o
    i0                     @  s   d dl mZ d dlZd dlmZ d dlmZ erFd dlZd dl	m
Z
 d dlmZ d dlmZ ejdkr:d d	lmZ nd d	lmZ d d
lmZ G dd dZdS )    )annotationsN)TYPE_CHECKING)altair)Callable)
EncodeKwds)	Encodings)      )Unpack)Seriesc                   @  sF   e Zd ZdZdZdddZdddZdddZdddZdddZ	dS )
SeriesPlotzSeries.plot namespace.Zplotsr   returnNonec                 C  s    |j pd}||| _|| _d S )Nvalue)nameZto_frame_df_series_name)selfr   r    r   M/home/app/Keep/.python/lib/python3.10/site-packages/polars/series/plotting.py__init__   s   

zSeriesPlot.__init__kwargsUnpack[EncodeKwds]	alt.Chartc                K  sZ   | j dkrd}t|tj| j  ddddd}t| jjddjd	i || S )
a(  
        Draw histogram.

        Polars does not implement plotting logic itself but instead defers to
        `Altair <https://altair-viz.github.io/>`_.

        `s.plot.hist(**kwargs)` is shorthand for
        `alt.Chart(s.to_frame()).mark_bar(tooltip=True).encode(x=alt.X(f'{s.name}:Q', bin=True), y='count()', **kwargs).interactive()`,
        and is provided for convenience - for full customisatibility, use a plotting
        library directly.

        .. versionchanged:: 1.6.0
            In prior versions of Polars, HvPlot was the plotting backend. If you would
            like to restore the previous plotting functionality, all you need to do
            is add `import hvplot.polars` at the top of your script and replace
            `df.plot` with `df.hvplot`.

        Parameters
        ----------
        **kwargs
            Additional arguments and keyword arguments passed to Altair.

        Examples
        --------
        >>> s = pl.Series("price", [1, 3, 3, 3, 5, 2, 6, 5, 5, 5, 7])
        >>> s.plot.hist()  # doctest: +SKIP
        zcount()z6cannot use `plot.hist` when Series name is `'count()'`z:QT)binxytooltipNr   )	r   
ValueErroraltXChartr   Zmark_barencodeinteractiver   r   msg	encodingsr   r   r   hist"   s"   
 
zSeriesPlot.histc                K  s\   | j dkrd}t|| j dd}t| jj| j | j dgdjddjd	i || S )
aI  
        Draw kernel density estimate plot.

        Polars does not implement plotting logic itself but instead defers to
        `Altair <https://altair-viz.github.io/>`_.

        `s.plot.kde(**kwargs)` is shorthand for
        `alt.Chart(s.to_frame()).transform_density(s.name, as_=[s.name, 'density']).mark_area(tooltip=True).encode(x=s.name, y='density:Q', **kwargs).interactive()`,
        and is provided for convenience - for full customisatibility, use a plotting
        library directly.

        .. versionchanged:: 1.6.0
            In prior versions of Polars, HvPlot was the plotting backend. If you would
            like to restore the previous plotting functionality, all you need to do
            is add `import hvplot.polars` at the top of your script and replace
            `df.plot` with `df.hvplot`.

        Parameters
        ----------
        **kwargs
            Additional keyword arguments passed to Altair.

        Examples
        --------
        >>> s = pl.Series("price", [1, 3, 3, 3, 5, 2, 6, 5, 5, 5, 7])
        >>> s.plot.kde()  # doctest: +SKIP
        Zdensityz5cannot use `plot.kde` when Series name is `'density'`z	density:Qr   )Zas_Tr   Nr   )	r   r!   r"   r$   r   Ztransform_densityZ	mark_arear%   r&   r'   r   r   r   kdeP   s"   
 
zSeriesPlot.kdec                K  sN   | j dkrd}t|d| j d}t| j jddjdi || S )a  
        Draw line plot.

        Polars does not implement plotting logic itself but instead defers to
        `Altair <https://altair-viz.github.io/>`_.

        `s.plot.line(**kwargs)` is shorthand for
        `alt.Chart(s.to_frame().with_row_index()).mark_line(tooltip=True).encode(x='index', y=s.name, **kwargs).interactive()`,
        and is provided for convenience - for full customisatibility, use a plotting
        library directly.

        .. versionchanged:: 1.6.0
            In prior versions of Polars, HvPlot was the plotting backend. If you would
            like to restore the previous plotting functionality, all you need to do
            is add `import hvplot.polars` at the top of your script and replace
            `df.plot` with `df.hvplot`.

        Parameters
        ----------
        **kwargs
            Additional keyword arguments passed to Altair.

        Examples
        --------
        >>> s = pl.Series("price", [1, 3, 3, 3, 5, 2, 6, 5, 5, 5, 7])
        >>> s.plot.line()  # doctest: +SKIP
        indexz3cannot call `plot.line` when Series name is 'index'r   Tr   Nr   )	r   r!   r"   r$   r   with_row_indexZ	mark_liner%   r&   r'   r   r   r   line|   s   
 zSeriesPlot.lineattrstrCallable[..., alt.Chart]c                   s   | j dkrd| d}t||dkrd}tt| j d| d d u r2d| d}t|d| j d	 d
dd t	j
 D v }|rSd fdd}|S d fdd}|S )Nr,   zCannot call `plot.z` when Series name is 'index'ZscatterpointZmark_zAltair has no method 'mark_'r   r    c                 S  s   h | ]}|j qS r   )r   ).0r   r   r   r   	<setcomp>   s    z)SeriesPlot.__getattr__.<locals>.<setcomp>r   r   r   r   c                    s   ddj di  |  S )NTr   r   r%   r&   r   r)   methodr   r   func   s   z$SeriesPlot.__getattr__.<locals>.funcc                    s    j di  |  S )Nr   r6   r7   r8   r   r   r:      s   )r   r   r   r   )r   r!   getattrr"   r$   r   r-   AttributeErrorinspect	signature
parametersvalues)r   r/   r(   Zaccepts_tooltip_argumentr:   r   r8   r   __getattr__   s$   
zSeriesPlot.__getattr__N)r   r   r   r   )r   r   r   r   )r/   r0   r   r1   )
__name__
__module____qualname____doc__	_accessorr   r*   r+   r.   rA   r   r   r   r   r      s    


.
,+r   )
__future__r   r=   typingr   Zpolars._dependenciesr   r"   syscollections.abcr   Zaltair.typingr   Zpolars.dataframe.plottingr   version_infor
   Ztyping_extensionsZpolarsr   r   r   r   r   r   <module>   s    
