o
    i                     @  s  U d dl mZ d dlZd dlmZ d dlmZ erd dlZd dl	m
Z
 d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ ejdkred dlmZ nd dlmZ eeB eB eB eB eB Zde d< e!e"ef Z#de d< G dd dZ$dS )    )annotationsN)TYPE_CHECKING)altair)Callable)	TypeAlias)ChannelColor)ChannelOrder)ChannelSize)ChannelTooltip)ChannelX)ChannelY)
EncodeKwds)	DataFrame)      )Unpackr   Encoding	Encodingsc                   @  sb   e Zd ZdZd!ddZ			d"d#ddZ				d$d%ddZ				d$d&ddZeZd'dd Z	dS )(DataFramePlotzDataFrame.plot namespace.dfr   returnNonec                 C  s   t || _d S )N)altZChart_chart)selfr    r   P/home/app/Keep/.python/lib/python3.10/site-packages/polars/dataframe/plotting.py__init__#   s   zDataFramePlot.__init__NxX | NoneyY | NonecolorColor | NonekwargsUnpack[EncodeKwds]	alt.Chartc                K  sV   i }|dur
||d< |dur||d< |dur||d< | j jddjdi || S )a  
        Draw bar plot.

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

        `df.plot.bar(**kwargs)` is shorthand for
        `alt.Chart(df).mark_bar().encode(**kwargs).interactive()`,
        and is provided for convenience - for full customisability, 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
        ----------
        x
            Column with x-coordinates of bars.
        y
            Column with y-coordinates of bars.
        color
            Column to color bars by.
        **kwargs
            Additional keyword arguments passed to Altair.

        Examples
        --------
        >>> df = pl.DataFrame(
        ...     {
        ...         "day": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] * 2,
        ...         "group": ["a"] * 7 + ["b"] * 7,
        ...         "value": [1, 3, 2, 4, 5, 6, 1, 1, 3, 2, 4, 5, 1, 2],
        ...     }
        ... )
        >>> df.plot.bar(
        ...     x="day", y="value", color="day", column="group"
        ... )  # doctest: +SKIP
        Nr   r    r"   Ttooltipr   )r   Zmark_barencodeinteractive)r   r   r    r"   r$   	encodingsr   r   r   bar&   s    1zDataFramePlot.barorderOrder | Nonec                K  f   i }|dur
||d< |dur||d< |dur||d< |dur"||d< | 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/>`_.

        `df.plot.line(**kwargs)` is shorthand for
        `alt.Chart(df).mark_line().encode(**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
        ----------
        x
            Column with x-coordinates of lines.
        y
            Column with y-coordinates of lines.
        color
            Column to color lines by.
        order
            Column to use for order of data points in lines.
        **kwargs
            Additional keyword arguments passed to Altair.

        Examples
        --------
        >>> from datetime import date
        >>> df = pl.DataFrame(
        ...     {
        ...         "date": [date(2020, 1, 2), date(2020, 1, 3), date(2020, 1, 4)] * 2,
        ...         "price": [1, 4, 6, 1, 5, 2],
        ...         "stock": ["a", "a", "a", "b", "b", "b"],
        ...     }
        ... )
        >>> df.plot.line(x="date", y="price", color="stock")  # doctest: +SKIP
        Nr   r    r"   r-   Tr'   r   )r   Z	mark_liner)   r*   )r   r   r    r"   r-   r$   r+   r   r   r   lined   s$   3zDataFramePlot.linesizeSize | Nonec                K  r/   )	a  
        Draw scatter plot.

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

        `df.plot.point(**kwargs)` is shorthand for
        `alt.Chart(df).mark_point().encode(**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
        ----------
        x
            Column with x-coordinates of points.
        y
            Column with y-coordinates of points.
        color
            Column to color points by.
        size
            Column which determines points' sizes.
        **kwargs
            Additional keyword arguments passed to Altair.

        Examples
        --------
        >>> df = pl.DataFrame(
        ...     {
        ...         "length": [1, 4, 6],
        ...         "width": [4, 5, 6],
        ...         "species": ["setosa", "setosa", "versicolor"],
        ...     }
        ... )
        >>> df.plot.point(x="length", y="width", color="species")  # doctest: +SKIP
        Nr   r    r"   r1   Tr'   r   )r   Z
mark_pointr)   r*   )r   r   r    r"   r1   r$   r+   r   r   r   point   s$   2zDataFramePlot.pointattrstrCallable[..., alt.Chart]c                   sv   t | jd| d   d u rd| d}t|ddd t j D v }|r2d fdd}|S d fdd}|S )NZmark_zAltair has no method 'mark_'r(   c                 S  s   h | ]}|j qS r   )name).0valuer   r   r   	<setcomp>   s    z,DataFramePlot.__getattr__.<locals>.<setcomp>r$   r   r   r&   c                    s    ddj di |  S )NTr'   r   r)   r*   r$   methodr   r   func   s   z'DataFramePlot.__getattr__.<locals>.funcc                    s     j di |  S )Nr   r<   r=   r>   r   r   r@      s   )r$   r   r   r&   )getattrr   AttributeErrorinspect	signature
parametersvalues)r   r4   msgZaccepts_tooltip_argumentr@   r   r>   r   __getattr__   s   zDataFramePlot.__getattr__)r   r   r   r   )NNN)
r   r   r    r!   r"   r#   r$   r%   r   r&   )NNNN)r   r   r    r!   r"   r#   r-   r.   r$   r%   r   r&   )r   r   r    r!   r"   r#   r1   r2   r$   r%   r   r&   )r4   r5   r   r6   )
__name__
__module____qualname____doc__r   r,   r0   r3   ZscatterrH   r   r   r   r   r       s&    
@DEr   )%
__future__r   rC   typingr   Zpolars._dependenciesr   r   syscollections.abcr   r   Zaltair.typingr   Colorr   ZOrderr	   Sizer
   ZTooltipr   Xr   Yr   Zpolarsr   version_infor   Ztyping_extensionsr   __annotations__dictr5   r   r   r   r   r   r   <module>   s,    
 