
    ˀh                        d dl mZ d dlZd dlmZmZ d dlmZ er2d dl	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      Zy)    )annotationsN)TYPE_CHECKINGCallable)altair)
EncodeKwds)	Encodings)      )Unpack)Seriesc                  T    e Zd ZdZdZd	dZ	 	 	 	 d
dZ	 	 	 	 d
dZ	 	 	 	 d
dZddZ	y)
SeriesPlotzSeries.plot namespace.plotc                ^    |j                   xs d}|j                  |      | _        || _        y )Nvalue)nameto_frame_df_series_name)selfsr   s      r/var/www/html/wine-match-dev/backend/winematch-backend/venv/lib/python3.12/site-packages/polars/series/plotting.py__init__zSeriesPlot.__init__   s(    vv ::d#     c               &   | j                   dk(  rd}t        |      t        j                  | j                    dd      dd} t        j                  | j
                        j                  d      j                  di ||j                         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tooltip )	r   
ValueErroraltXChartr   mark_barencodeinteractiver   kwargsmsg	encodingss       r   histzSeriesPlot.hist!   s    @ 	)JCS/!$++,B/T: 
	
CIIdhhXdX#V++#)+ []		
r   c               D   | j                   dk(  rd}t        |      | j                   dd} t        j                  | j                        j                  | j                   | j                   dg      j                  d      j                  di ||j                         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
        densityz5cannot use `plot.kde` when Series name is `'density'`z	density:Qr   )as_Tr    r"   )	r   r#   r$   r&   r   transform_density	mark_arear(   r)   r*   s       r   kdezSeriesPlot.kdeO   s    @ 	)ICS/!%)%6%6[I	CIIdhht00t7H7H)6TUYtY$V+  + $*+ []	
r   c                  | j                   dk(  rd}t        |      d| j                   d} t        j                  | j                  j                               j                  d      j                  di ||j                         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    r"   )	r   r#   r$   r&   r   with_row_index	mark_liner(   r)   r*   s       r   linezSeriesPlot.line{   s    @ 'GCS/!%,43D3DE	CIIdhh--/0YtY$V++#)+ []		
r   c                   | j                   dk(  rd| d}t        |      |dk(  rd}t        t        j                  | j
                  j                               d| d       d| d}t        |      d| j                   d	d
t        j                        j                  j                         D ch c]  }|j                   c}v }|r	dfd}|S dfd}|S c c}w )Nr6   zCannot call `plot.z` when Series name is 'index'scatterpointmark_zAltair has no method 'mark_'r   r!   c                 V      d      j                   di | j                         S )NTr    r"   r(   r)   r+   r-   methods    r   funcz$SeriesPlot.__getattr__.<locals>.func   s,    2vd+22IYI&IUUWWr   c                 R             j                   di | j                         S )Nr"   r@   rA   s    r   rC   z$SeriesPlot.__getattr__.<locals>.func   s'    &vx==f=IIKKr   )r+   r   return	alt.Chart)r   r#   getattrr$   r&   r   r7   AttributeErrorinspect	signature
parametersvaluesr   )r   attrr,   r   accepts_tooltip_argumentrC   r-   rB   s         @@r   __getattr__zSeriesPlot.__getattr__   s    '&tf,IJCS/!9D488#:#:#<=tf~tT>/vQ7C %%%,43D3DE	#,$+$5$5f$=$H$H$O$O$Q1
 EJJ1
 $
  $X L 1
s   7C"N)r   r   rE   None)r+   zUnpack[EncodeKwds]rE   rF   )rM   strrE   zCallable[..., alt.Chart])
__name__
__module____qualname____doc__	_accessorr   r.   r4   r9   rO   r"   r   r   r   r      sb     I!
,
 %,
 
	,
\*
 %*
 
	*
X)
 %)
 
	)
Vr   r   )
__future__r   rI   typingr   r   polars.dependenciesr   r$   sysaltair.typingr   polars.dataframe.plottingr   version_infor   typing_extensionspolarsr   r   r"   r   r   <module>r`      s@    "  * -(3
7"!,h hr   