
    &e                       d 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
mZmZmZmZmZmZmZ ddlZddlmZmZ dd	lmZ ddlmc mZ dd
lmZ ddlmZm Z m!Z!m"Z"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+m,Z, ddl-m.Z/ ddl0m1Z1 e
r
ddl2Z3ddl4m5Z5  G d de          Z6 e7ddd          Z8 e7ddd          Z9dZ:dZ;dZ<dZ=e:e=z   Z>e;e=z   Z?e<e=z   Z@de=z   ZA G d d          ZBd~d&ZCdd.ZDdd4ZE	 	 	 	 	 	 dddCZFddDZGddFZHddGZIddIZJddMZKddNZLddOZMddQZNddTZOddWZPddYZQdd[ZRdd^ZSddbZTddeZUddhZVddjZWddkZX	 	 dddwZY G dx dye,          ZZ G dz d{e,          Z[ G d| d}e,          Z\dS )zA Python wrapper around Altair.
Altair is a Python visualization library based on Vega-Lite,
a nice JSON schema for expressing graphs and charts.
    )annotations)nullcontext)date)Enum)TYPE_CHECKINGAny
CollectionDictListSequenceTuplecastN)infer_dtypeis_integer_dtype)Literal)	type_util)Coloris_color_likeis_color_tuple_likeis_hex_color_liketo_css_color)AddRowsMetadata)Data) last_index_for_melted_dataframes)ErrorStreamlitAPIException)ArrowVegaLiteChart)gather_metrics)DeltaGeneratorc                  .    e Zd ZddiZddiZddiZddiZdS )	ChartType	mark_typeareabarlinecircleN)__name__
__module____qualname__AREABARLINESCATTER     ?lib/python3.11/site-packages/streamlit/elements/arrow_altair.pyr!   r!   6   s6         D
C DH%GGGr/   r!      bottom)titlePaddingoffsetorientg      ?indexvaluecolorz--p5bJXXpQgvPz6yvQMFiyDOES_NOT_EXISTc            
      P   e Zd Z ed          	 d(dddddddd)d            Z ed          	 d(dddddddd)d            Z ed          	 d(dddddddd)d            Z ed          	 d(ddddddddd*d            Z ed           	 	 d+d,d&            Ze	d-d'            Z
dS ).ArrowAltairMixin
line_chartNr   T)xyr8   widthheightuse_container_widthdatar   r=   
str | Noner>   str | Sequence[str] | Noner8    str | Color | List[Color] | Noner?   intr@   rA   boolreturnr   c          
         t                      }t          t          j        ||||d||          \  }	}
t	          ||	|d           | j                            d||
          S )a  Display a line chart.

        This is syntax-sugar around ``st.altair_chart``. The main difference
        is this command uses the data's own column and indices to figure out
        the chart's spec. As a result this is easier to use for many "just plot
        this" scenarios, while being less customizable.

        If ``st.line_chart`` does not guess the data specification
        correctly, try specifying your desired chart using ``st.altair_chart``.

        Parameters
        ----------
        data : pandas.DataFrame, pandas.Styler, pyarrow.Table, numpy.ndarray, pyspark.sql.DataFrame, snowflake.snowpark.dataframe.DataFrame, snowflake.snowpark.table.Table, Iterable, dict or None
            Data to be plotted.

        x : str or None
            Column name to use for the x-axis. If None, uses the data index for the x-axis.

        y : str, Sequence of str, or None
            Column name(s) to use for the y-axis. If a Sequence of strings,
            draws several series on the same chart by melting your wide-format
            table into a long-format table behind the scenes. If None, draws
            the data of all remaining columns as data series.

        color : str, tuple, Sequence of str, Sequence of tuple, or None
            The color to use for different lines in this chart.

            For a line chart with just one line, this can be:

            * None, to use the default color.
            * A hex string like "#ffaa00" or "#ffaa0088".
            * An RGB or RGBA tuple with the red, green, blue, and alpha
              components specified as ints from 0 to 255 or floats from 0.0 to
              1.0.

            For a line chart with multiple lines, where the dataframe is in
            long format (that is, y is None or just one column), this can be:

            * None, to use the default colors.
            * The name of a column in the dataset. Data points will be grouped
              into lines of the same color based on the value of this column.
              In addition, if the values in this column match one of the color
              formats above (hex string or color tuple), then that color will
              be used.

              For example: if the dataset has 1000 rows, but this column only
              contains the values "adult", "child", and "baby", then those 1000
              datapoints will be grouped into three lines whose colors will be
              automatically selected from the default palette.

              But, if for the same 1000-row dataset, this column contained
              the values "#ffaa00", "#f0f", "#0000ff", then then those 1000
              datapoints would still be grouped into three lines, but their
              colors would be "#ffaa00", "#f0f", "#0000ff" this time around.

            For a line chart with multiple lines, where the dataframe is in
            wide format (that is, y is a Sequence of columns), this can be:

            * None, to use the default colors.
            * A list of string colors or color tuples to be used for each of
              the lines in the chart. This list should have the same length
              as the number of y values (e.g. ``color=["#fd0", "#f0f", "#04f"]``
              for three lines).

        width : int
            The chart width in pixels. If 0, selects the width automatically.

        height : int
            The chart height in pixels. If 0, selects the height automatically.

        use_container_width : bool
            If True, set the chart width to the column width. This takes
            precedence over the width argument.

        Examples
        --------
        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>>
        >>> chart_data = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"])
        >>>
        >>> st.line_chart(chart_data)

        .. output::
           https://doc-line-chart.streamlit.app/
           height: 440px

        You can also choose different columns to use for x and y, as well as set
        the color dynamically based on a 3rd column (assuming your dataframe is in
        long format):

        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>>
        >>> chart_data = pd.DataFrame(
        ...    {
        ...        "col1": np.random.randn(20),
        ...        "col2": np.random.randn(20),
        ...        "col3": np.random.choice(["A", "B", "C"], 20),
        ...    }
        ... )
        >>>
        >>> st.line_chart(chart_data, x="col1", y="col2", color="col3")

        .. output::
           https://doc-line-chart1.streamlit.app/
           height: 440px

        Finally, if your dataframe is in wide format, you can group multiple
        columns under the y argument to show multiple lines with different
        colors:

        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>>
        >>> chart_data = pd.DataFrame(np.random.randn(20, 3), columns=["col1", "col2", "col3"])
        >>>
        >>> st.line_chart(
        ...    chart_data, x="col1", y=["col2", "col3"], color=["#FF0000", "#0000FF"]  # Optional
        ... )

        .. output::
           https://doc-line-chart2.streamlit.app/
           height: 440px

        N
chart_typerB   x_from_usery_from_usercolor_from_usersize_from_userr?   r@   	streamlitthemearrow_line_chartadd_rows_metadata)ArrowVegaLiteChartProto_generate_chartr!   r,   marshalldg_enqueueselfrB   r=   r>   r8   r?   r@   rA   protochartrU   s              r0   r<   zArrowAltairMixin.line_charta   s    Z ())#2 ~!	$
 	$
 	$
   	2+FFFFw9J   
 
 	
r/   
area_chartc          
         t                      }t          t          j        ||||d||          \  }	}
t	          ||	|d           | j                            d||
          S )a  Display an area chart.

        This is syntax-sugar around ``st.altair_chart``. The main difference
        is this command uses the data's own column and indices to figure out
        the chart's spec. As a result this is easier to use for many "just plot
        this" scenarios, while being less customizable.

        If ``st.area_chart`` does not guess the data specification
        correctly, try specifying your desired chart using ``st.altair_chart``.

        Parameters
        ----------
        data : pandas.DataFrame, pandas.Styler, pyarrow.Table, numpy.ndarray, pyspark.sql.DataFrame, snowflake.snowpark.dataframe.DataFrame, snowflake.snowpark.table.Table, Iterable, or dict
            Data to be plotted.

        x : str or None
            Column name to use for the x-axis. If None, uses the data index for the x-axis.

        y : str, Sequence of str, or None
            Column name(s) to use for the y-axis. If a Sequence of strings,
            draws several series on the same chart by melting your wide-format
            table into a long-format table behind the scenes. If None, draws
            the data of all remaining columns as data series.

        color : str, tuple, Sequence of str, Sequence of tuple, or None
            The color to use for different series in this chart.

            For an area chart with just 1 series, this can be:

            * None, to use the default color.
            * A hex string like "#ffaa00" or "#ffaa0088".
            * An RGB or RGBA tuple with the red, green, blue, and alpha
              components specified as ints from 0 to 255 or floats from 0.0 to
              1.0.

            For an area chart with multiple series, where the dataframe is in
            long format (that is, y is None or just one column), this can be:

            * None, to use the default colors.
            * The name of a column in the dataset. Data points will be grouped
              into series of the same color based on the value of this column.
              In addition, if the values in this column match one of the color
              formats above (hex string or color tuple), then that color will
              be used.

              For example: if the dataset has 1000 rows, but this column only
              contains the values "adult", "child", and "baby", then those 1000
              datapoints will be grouped into three series whose colors will be
              automatically selected from the default palette.

              But, if for the same 1000-row dataset, this column contained
              the values "#ffaa00", "#f0f", "#0000ff", then then those 1000
              datapoints would still be grouped into 3 series, but their
              colors would be "#ffaa00", "#f0f", "#0000ff" this time around.

            For an area chart with multiple series, where the dataframe is in
            wide format (that is, y is a Sequence of columns), this can be:

            * None, to use the default colors.
            * A list of string colors or color tuples to be used for each of
              the series in the chart. This list should have the same length
              as the number of y values (e.g. ``color=["#fd0", "#f0f", "#04f"]``
              for three lines).

        width : int
            The chart width in pixels. If 0, selects the width automatically.

        height : int
            The chart height in pixels. If 0, selects the height automatically.

        use_container_width : bool
            If True, set the chart width to the column width. This takes
            precedence over the width argument.

        Examples
        --------
        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>>
        >>> chart_data = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"])
        >>>
        >>> st.area_chart(chart_data)

        .. output::
           https://doc-area-chart.streamlit.app/
           height: 440px

        You can also choose different columns to use for x and y, as well as set
        the color dynamically based on a 3rd column (assuming your dataframe is in
        long format):

        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>>
        >>> chart_data = pd.DataFrame(
        ...    {
        ...        "col1": np.random.randn(20),
        ...        "col2": np.random.randn(20),
        ...        "col3": np.random.choice(["A", "B", "C"], 20),
        ...    }
        ... )
        >>>
        >>> st.area_chart(chart_data, x="col1", y="col2", color="col3")

        .. output::
           https://doc-area-chart1.streamlit.app/
           height: 440px

        Finally, if your dataframe is in wide format, you can group multiple
        columns under the y argument to show multiple series with different
        colors:

        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>>
        >>> chart_data = pd.DataFrame(np.random.randn(20, 3), columns=["col1", "col2", "col3"])
        >>>
        >>> st.area_chart(
        ...    chart_data, x="col1", y=["col2", "col3"], color=["#FF0000", "#0000FF"]  # Optional
        ... )

        .. output::
           https://doc-area-chart2.streamlit.app/
           height: 440px

        NrJ   rP   rQ   arrow_area_chartrT   )rV   rW   r!   r*   rX   rY   rZ   r[   s              r0   r_   zArrowAltairMixin.area_chart   s    \ ())#2 ~!	$
 	$
 	$
   	2+FFFFw9J   
 
 	
r/   	bar_chartc          
         t                      }t          t          j        ||||d||          \  }	}
t	          ||	|d           | j                            d||
          S )a!  Display a bar chart.

        This is syntax-sugar around ``st.altair_chart``. The main difference
        is this command uses the data's own column and indices to figure out
        the chart's spec. As a result this is easier to use for many "just plot
        this" scenarios, while being less customizable.

        If ``st.bar_chart`` does not guess the data specification
        correctly, try specifying your desired chart using ``st.altair_chart``.

        Parameters
        ----------
        data : pandas.DataFrame, pandas.Styler, pyarrow.Table, numpy.ndarray, pyspark.sql.DataFrame, snowflake.snowpark.dataframe.DataFrame, snowflake.snowpark.table.Table, Iterable, or dict
            Data to be plotted.

        x : str or None
            Column name to use for the x-axis. If None, uses the data index for the x-axis.

        y : str, Sequence of str, or None
            Column name(s) to use for the y-axis. If a Sequence of strings,
            draws several series on the same chart by melting your wide-format
            table into a long-format table behind the scenes. If None, draws
            the data of all remaining columns as data series.

        color : str, tuple, Sequence of str, Sequence of tuple, or None
            The color to use for different series in this chart.

            For a bar chart with just one series, this can be:

            * None, to use the default color.
            * A hex string like "#ffaa00" or "#ffaa0088".
            * An RGB or RGBA tuple with the red, green, blue, and alpha
              components specified as ints from 0 to 255 or floats from 0.0 to
              1.0.

            For a bar chart with multiple series, where the dataframe is in
            long format (that is, y is None or just one column), this can be:

            * None, to use the default colors.
            * The name of a column in the dataset. Data points will be grouped
              into series of the same color based on the value of this column.
              In addition, if the values in this column match one of the color
              formats above (hex string or color tuple), then that color will
              be used.

              For example: if the dataset has 1000 rows, but this column only
              contains the values "adult", "child", and "baby", then those 1000
              datapoints will be grouped into three series whose colors will be
              automatically selected from the default palette.

              But, if for the same 1000-row dataset, this column contained
              the values "#ffaa00", "#f0f", "#0000ff", then then those 1000
              datapoints would still be grouped into 3 series, but their
              colors would be "#ffaa00", "#f0f", "#0000ff" this time around.

            For a bar chart with multiple series, where the dataframe is in
            wide format (that is, y is a Sequence of columns), this can be:

            * None, to use the default colors.
            * A list of string colors or color tuples to be used for each of
              the series in the chart. This list should have the same length
              as the number of y values (e.g. ``color=["#fd0", "#f0f", "#04f"]``
              for three lines).

        width : int
            The chart width in pixels. If 0, selects the width automatically.

        height : int
            The chart height in pixels. If 0, selects the height automatically.

        use_container_width : bool
            If True, set the chart width to the column width. This takes
            precedence over the width argument.

        Examples
        --------
        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>>
        >>> chart_data = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"])
        >>>
        >>> st.bar_chart(chart_data)

        .. output::
           https://doc-bar-chart.streamlit.app/
           height: 440px

        You can also choose different columns to use for x and y, as well as set
        the color dynamically based on a 3rd column (assuming your dataframe is in
        long format):

        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>>
        >>> chart_data = pd.DataFrame(
        ...    {
        ...        "col1": list(range(20)) * 3,
        ...        "col2": np.random.randn(60),
        ...        "col3": ["A"] * 20 + ["B"] * 20 + ["C"] * 20,
        ...    }
        ... )
        >>>
        >>> st.bar_chart(chart_data, x="col1", y="col2", color="col3")

        .. output::
           https://doc-bar-chart1.streamlit.app/
           height: 440px

        Finally, if your dataframe is in wide format, you can group multiple
        columns under the y argument to show multiple series with different
        colors:

        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>>
        >>> chart_data = pd.DataFrame(
        ...    {"col1": list(range(20)), "col2": np.random.randn(20), "col3": np.random.randn(20)}
        ... )
        >>>
        >>> st.bar_chart(
        ...    chart_data, x="col1", y=["col2", "col3"], color=["#FF0000", "#0000FF"]  # Optional
        ... )

        .. output::
           https://doc-bar-chart2.streamlit.app/
           height: 440px

        NrJ   rP   rQ   arrow_bar_chartrT   )rV   rW   r!   r+   rX   rY   rZ   r[   s              r0   rb   zArrowAltairMixin.bar_chart  s    ` ())#2 }!	$
 	$
 	$
   	2+FFFFwu8I   
 
 	
r/   scatter_chart)r=   r>   r8   sizer?   r@   rA   rf   str | float | int | None'DeltaGenerator'c          
         t                      }	t          t          j        |||||||          \  }
}t	          |	|
|d           | j                            d|	|          S )a	  Display a scatterplot chart.

        This is syntax-sugar around ``st.altair_chart``. The main difference
        is this command uses the data's own column and indices to figure out
        the chart's spec. As a result this is easier to use for many "just plot
        this" scenarios, while being less customizable.

        If ``st.scatter_chart`` does not guess the data specification correctly,
        try specifying your desired chart using ``st.altair_chart``.

        Parameters
        ----------
        data : pandas.DataFrame, pandas.Styler, pyarrow.Table, numpy.ndarray, pyspark.sql.DataFrame, snowflake.snowpark.dataframe.DataFrame, snowflake.snowpark.table.Table, Iterable, dict or None
            Data to be plotted.

        x : str or None
            Column name to use for the x-axis. If None, uses the data index for the x-axis.

        y : str, Sequence of str, or None
            Column name(s) to use for the y-axis. If a Sequence of strings,
            draws several series on the same chart by melting your wide-format
            table into a long-format table behind the scenes. If None, draws
            the data of all remaining columns as data series.

        color : str, tuple, Sequence of str, Sequence of tuple, or None
            The color of the circles representing each datapoint.

            This can be:

            * None, to use the default color.
            * A hex string like "#ffaa00" or "#ffaa0088".
            * An RGB or RGBA tuple with the red, green, blue, and alpha
              components specified as ints from 0 to 255 or floats from 0.0 to
              1.0.
            * The name of a column in the dataset where the color of that
              datapoint will come from.

              If the values in this column are in one of the color formats
              above (hex string or color tuple), then that color will be used.

              Otherwise, the color will be automatically picked from the
              default palette.

              For example: if the dataset has 1000 rows, but this column only
              contains the values "adult", "child", and "baby", then those 1000
              datapoints be shown using three colors from the default palette.

              But if this column only contains floats or ints, then those
              1000 datapoints will be shown using a colors from a continuous
              color gradient.

              Finally, if this column only contains the values "#ffaa00",
              "#f0f", "#0000ff", then then each of those 1000 datapoints will
              be assigned "#ffaa00", "#f0f", or "#0000ff" as appropriate.

            If the dataframe is in wide format (that is, y is a Sequence of
            columns), this can also be:

            * A list of string colors or color tuples to be used for each of
              the series in the chart. This list should have the same length
              as the number of y values (e.g. ``color=["#fd0", "#f0f", "#04f"]``
              for three series).

        size : str, float, int, or None
            The size of the circles representing each point.

            This can be:

            * A number like 100, to specify a single size to use for all
              datapoints.
            * The name of the column to use for the size. This allows each
              datapoint to be represented by a circle of a different size.

        width : int
            The chart width in pixels. If 0, selects the width automatically.

        height : int
            The chart height in pixels. If 0, selects the height automatically.

        use_container_width : bool
            If True, set the chart width to the column width. This takes
            precedence over the width argument.

        Examples
        --------
        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>>
        >>> chart_data = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"])
        >>>
        >>> st.scatter_chart(chart_data)

        .. output::
           https://doc-scatter-chart.streamlit.app/
           height: 440px

        You can also choose different columns to use for x and y, as well as set
        the color dynamically based on a 3rd column (assuming your dataframe is in
        long format):

        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>>
        >>> chart_data = pd.DataFrame(np.random.randn(20, 3), columns=["col1", "col2", "col3"])
        >>> chart_data['col4'] = np.random.choice(['A','B','C'], 20)
        >>>
        >>> st.scatter_chart(
        ...     chart_data,
        ...     x='col1',
        ...     y='col2',
        ...     color='col4',
        ...     size='col3',
        ... )

        .. output::
           https://doc-scatter-chart1.streamlit.app/
           height: 440px

        Finally, if your dataframe is in wide format, you can group multiple
        columns under the y argument to show multiple series with different
        colors:

        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>>
        >>> chart_data = pd.DataFrame(np.random.randn(20, 4), columns=["col1", "col2", "col3", "col4"])
        >>>
        >>> st.scatter_chart(
        ...     chart_data,
        ...     x='col1',
        ...     y=['col2', 'col3'],
        ...     size='col4',
        ...     color=['#FF0000', '#0000FF'],  # Optional
        ... )

        .. output::
           https://doc-scatter-chart2.streamlit.app/
           height: 440px

        rJ   rP   rQ   arrow_scatter_chartrT   )rV   rW   r!   r-   rX   rY   rZ   )r\   rB   r=   r>   r8   rf   r?   r@   rA   r]   r^   rU   s               r0   re   zArrowAltairMixin.scatter_chart?  s    x ())#2 (!	$
 	$
 	$
   	2+FFFFw!5<M   
 
 	
r/   altair_chartFrP   	alt.ChartrR   Literal['streamlit'] | Nonec                    |dk    r|dk    rt          d| d          t                      }t          ||||           | j                            d|          S )a  Display a chart using the Altair library.

        Parameters
        ----------
        altair_chart : altair.Chart
            The Altair chart object to display.

        use_container_width : bool
            If True, set the chart width to the column width. This takes
            precedence over Altair's native ``width`` value.

        theme : "streamlit" or None
            The theme of the chart. Currently, we only support "streamlit" for the Streamlit
            defined design or None to fallback to the default behavior of the library.

        Example
        -------

        >>> import streamlit as st
        >>> import pandas as pd
        >>> import numpy as np
        >>> import altair as alt
        >>>
        >>> chart_data = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"])
        >>>
        >>> c = (
        ...    alt.Chart(chart_data)
        ...    .mark_circle()
        ...    .encode(x="a", y="b", size="c", color="c", tooltip=["a", "b", "c"])
        ... )
        >>>
        >>> st.altair_chart(c, use_container_width=True)

        .. output::
           https://doc-vega-lite-chart.streamlit.app/
           height: 300px

        Examples of Altair charts can be found at
        https://altair-viz.github.io/gallery/.

        rP   NzYou set theme="us   " while Streamlit charts only support theme=”streamlit” or theme=None to fallback to the default library theme.rA   rR   arrow_vega_lite_chart)r   rV   rX   rY   rZ   )r\   rk   rA   rR   r]   s        r0   rk   zArrowAltairMixin.altair_chart  s    ` KETMM' ]%  ]  ]  ]   ()) 3		
 	
 	
 	
 w 7???r/   c                "    t          d|           S )zGet our DeltaGenerator.r   )r   )r\   s    r0   rY   zArrowAltairMixin.dg*  s     $d+++r/   N)rB   r   r=   rC   r>   rD   r8   rE   r?   rF   r@   rF   rA   rG   rH   r   )rB   r   r=   rC   r>   rD   r8   rE   rf   rg   r?   rF   r@   rF   rA   rG   rH   rh   FrP   )rk   rl   rA   rG   rR   rm   rH   r   )rH   r   )r'   r(   r)   r   r<   r_   rb   re   rk   propertyrY   r.   r/   r0   r;   r;   `   s       ^L!! [
 (,26$([
 [
 [
 [
 [
 "![
z ^L!! \
 (,26$(\
 \
 \
 \
 \
 "!\
| ^K   ^
 (,26$(^
 ^
 ^
 ^
 ^
 ! ^
@ ^O$$ j
 (,26)-$(j
 j
 j
 j
 j
 %$j
X ^N## %*-8	;@ ;@ ;@ ;@ $#;@z , , , X, , ,r/   r;   dfpd.DataFramenamerC   rH   rG   c                t    |dS | |         }|j         dk    rdS t          |j        d         t                    S )aY  True if the column with the given name stores datetime.date values.

    This function just checks the first value in the given column, so
    it's meaningful only for columns whose values all share the same type.

    Parameters
    ----------
    df : pd.DataFrame
    name : str
        The column name

    Returns
    -------
    bool

    NFr   )rf   
isinstanceilocr   )ru   rw   columns      r0   _is_date_columnr|   0  s?    " |uXF{aufk!nd+++r/   columns_to_leave_alone	List[str]columns_to_meltList[str] | Nonenew_y_column_namestrnew_color_column_namec                    t          j        | ||||          }||         }|j        dk    rEdt          |          v r4t	          |                                          dk    rt          d          t          j        |g |||          }|S )z<Converts a wide-format dataframe to a long-format dataframe.)id_vars
value_varsvar_name
value_nameobjectmixedd   zThe columns used for rendering the chart contain too many values with mixed types. Please select the columns manually via the y parameter.)selected_columns)	pdmeltdtyper   lenuniquer   r   #fix_arrow_incompatible_column_types)ru   r}   r   r   r   	melted_dfy_seriesfixed_dfs           r0   
_melt_datar   K  s     
&"&$  I *+H(""{8,,,,!!""S((# Y
 
 	
 <
#
!
 
  H Or/   x_columny_column_listcolor_columnsize_columnCTuple[pd.DataFrame, str | None, str | None, str | None, str | None]c                    t          | ||          }t          | |||g|R  }t          ||           t          |||||          \  }}}}t	          |||||          \  }}}|||||fS )zPrepares the data for charting. This is also used in add_rows.

    Returns the prepared dataframe and the new names of the x column (taking the index reset into
    consideration) and y, color, and size columns.
    )_maybe_reset_index_in_place_drop_unused_columns$_maybe_convert_color_column_in_place"_convert_col_names_to_str_in_place_maybe_melt)ru   r   r   r   r   selected_datamelted_datay_columns           r0   	prep_datar   t  s     +2xGGH )
HlK2?  M
 )EEE 	+xk	 	 +6xk+ +'K<
 (L+EEr/   rK   rB   Data | NonerL   rM   rD   rN   rE   rO   str | float | Noner?   rF   r@   !Tuple[alt.Chart, AddRowsMetadata]c           	     v   ddl }t          j        |d          }	~t          |	|          }
t	          |	||
          }t          |	|          \  }}t          |	|          \  }}t          t          |	          t          |
|||                    }t          |	|
|||          \  }	}
}}} |j
        |	| j        d         ||                              t          |	|
||           t          |	||          	          }t          | |          }||                    |
          }t!          |	||||          }||                    |          }t#          | ||          }||                    |          }|
)|'|                    t%          |
||||                    }|                                |fS )zZFunction to use the chart's type, data columns and indices to figure out the chart's spec.r   NT)ensure_copy)r   r   r   r   )
last_indexcolumnsr"   )rB   markr?   r@   )r=   r>   )opacity)r8   )rf   )tooltip)altairr   convert_anything_to_df_parse_x_column_parse_y_columns_parse_generic_columnr   r   dictr   Chartr7   encode_get_x_encoding_get_y_encoding_get_opacity_encoding_get_color_encoding_get_size_encoding_get_tooltip_encodinginteractive)rK   rB   rL   rM   rN   rO   r?   r@   altru   r   r   r   color_valuer   
size_valuerU   r   r^   opacity_enc	color_encsize_encs                         r0   rW   rW     s+    		)$D	A	A	AB 	 r;//H$Rh??M 5b/ J JL+3BGGK (3B77'%#	
 
 
	
 
 
 9B
Hm\;9 95B(L+ CIk*	  
 f
"hZ
@
@
"h
4
4    
 (
LAAK[11 $
K}o I 9-- "*k:FFH(++  4)   
 
  111r/   c                    |Ut          |          dk    rB| j        j        t          }n| j        j        }|| j        _        |                     d           |S )Nr   T)inplace)r   r6   rw   SEPARATED_INDEX_COLUMN_NAMEreset_index)ru   r   r   s      r0   r   r     sZ     C..228= 2HH x}H 
t$$$Or/   column_namesc                    t                      }g }|D ]4}|||v r
|                    |           |                    |           5| |         S )zEReturns a subset of df, selecting only column_names that aren't None.)setaddappend)ru   r   seenkeepr=   s        r0   r   r     s^     55DD  999Ad8Or/   c                    |t          | |                   dk    rdS | |         d         }t          |          rdS t          |          r%| |                             t                    | |<   dS dS )z=If needed, convert color column to a format Vega understands.Nr   )r   r   r   mapr   )ru   r   first_color_datums      r0   r   r   #  s    s2l#34499<(+*++ 		.	/	/ l+//==< 	r/   4Tuple[str | None, List[str], str | None, str | None]c                    t          | j                  }d |D             }t          j        |          | _        |dnt	          |          d |D             |dnt	          |          |dnt	          |          fS )zLConverts column names to strings, since Vega-Lite does not accept ints, etc.c                ,    g | ]}t          |          S r.   r   .0cs     r0   
<listcomp>z6_convert_col_names_to_str_in_place.<locals>.<listcomp>?  s    5551A555r/   Nc                ,    g | ]}t          |          S r.   r   r   s     r0   r   z6_convert_col_names_to_str_in_place.<locals>.<listcomp>D  s    '''AQ'''r/   )listr   r   Indexr   )ru   r   r   r   r   r   str_column_namess          r0   r   r   6  s     
##L55555*++BJ  c(mm'''''$#l*;*;#[)9)9	 r/   column_or_valuer   Tuple[str | None, Any]c                X    t          |t                    r|| j        v r|}d }nd }|}||fS rr   )ry   r   r   )ru   r   column_namer7   s       r0   r   r   J  sC     /3''  Orz,I,I%r/   c                    |d S t          |t                    r|| j        vrt          | |          |S t	          d| dt          |           d          )Nz^x parameter should be a column name (str) or None to use the  dataframe's index. Value given:  (type ))ry   r   r   StreamlitColumnNotFoundErrorr   type)ru   rL   s     r0   r   r   W  s    t	K	%	% 
bj((.r;??? $*0;* *+&&* * *
 
 	
r/   c                   g }|t          | j                  }njt          |t                    r|g}nQt	          j        |          rt          d |D                       }n#t          d| dt          |           d          |D ]}|| j        vrt          | |          ||v r|r||vr|	                    |           |S )Nc              3  4   K   | ]}t          |          V  d S rr   r   )r   cols     r0   	<genexpr>z#_parse_y_columns.<locals>.<genexpr>w  s(      ==#SXX======r/   zHy parameter should be a column name (str) or list thereof. Value given: r   r   )
r   r   ry   r   r   is_sequencer   r   r   remove)ru   rM   r   r   r   s        r0   r   r   i  s   
  "MRZ((	K	%	% 

$		{	+	+ 
======= $E'E E04[0A0AE E E
 
 	

  8 8bj  .r3777 ! =  + 9T9TX&&&r/   alt.OpacityValue | Nonec                R    dd l }|r | t          j        k    r |j        d          S d S )Nr   gffffff?)r   r!   r*   OpacityValue)rK   r   r   s      r0   r   r     s<      %
in44s$$$4r/   r   	alt.Scalec                j    dd l }t          | |          r |j        d          S  |j                    S )Nr   utc)r   )r   r|   Scale)ru   r   r   s      r0   
_get_scaler     sE     r;'' %sye$$$$39;;r/   gridalt.Axisc                ~    dd l }|'t          | |                   r |j        d|          S  |j        |          S )Nr      )tickMinStepr   r   )r   r   Axis)ru   r   r   r   s       r0   _get_axis_configr     sT    #3B{O#D#D sxAD111138r/   +Tuple[pd.DataFrame, str | None, str | None]c                    t          |          dk    rd}nZt          |          dk    r	|d         }n>|<t          }t          }|g}|r|                    |           t	          | ||||          } | ||fS )zGIf multiple columns are set for y, melt the dataframe into long format.r   Nr   )ru   r}   r   r   r   )r   MELTED_Y_COLUMN_NAMEMELTED_COLOR_COLUMN_NAMEr   r   )ru   r   r   r   r   r   r}   s          r0   r   r     s     =Q	]		q	 	  #		'/"* 	7"))+666#9)&".
 
 
 x%%r/   alt.Xc                    dd l }|
t          }d}n|t          k    r|}d}n	|}|d}n|} |j        ||t	          | ||          t          | |          t          | |d                    S )Nr    Fr   )titler   scaleaxis)r   NON_EXISTENT_COLUMN_NAMEr   X_get_x_encoding_typer   r   )ru   r   rL   rK   r   x_fieldx_titles          r0   r   r     s      +	0	0	0  
 GGG35!"j(;;X&&b(777   r/   r   alt.Yc                    dd l }|
t          }d}n|t          k    r|}d}n	|}|d}n|} |j        ||t	          | |          t          | |          t          | |d                    S )Nr   r  Tr   )fieldr  r   r  r  )r   r  r   Y_get_y_encoding_typer   r   )ru   r   rM   r   y_fieldy_titles         r0   r   r     s    
  +	)	)	)  
 GGG35!"h//X&&b(666   r/   r   Color | None!alt.Color | alt.ColorValue | Nonec           	        dd l }|d g t                      fv}|rnt          t          t          |                    rTt          |          dk    rt          |g|           |j        t          t          t          |                              S t          |t          t          f          rt          t          t                   |          }t          |          t          |          k    rt          ||          t          |          dk    r6 |j        t          t          t          |d                                       S  |j        | |j        d |D                       t          dd          S t          | |          ||t           k    rd}nt#          j        | |                   } |j        |t          |          }	|t           k    rd|	d	<   not          | |                   rYt          | |         d                   r>d
 | |                                         D             }
 |j        |
          |	d<   d |	d<   n	 |	S d S )Nr   r   c                ,    g | ]}t          |          S r.   r   r   s     r0   r   z'_get_color_encoding.<locals>.<listcomp>@  s    *Q*Q*Qq<??*Q*Q*Qr/   )rangenominal )r  r  legendr   r  )r  r  r   r  c                ,    g | ]}t          |          S r.   r  r   s     r0   r   z'_get_color_encoding.<locals>.<listcomp>]  s    NNNq<??NNNr/   r  r  )r   tupler   r   r   r   StreamlitColorLengthError
ColorValuer   ry   r   r	   r   r   COLOR_LEGEND_SETTINGSStreamlitInvalidColorErrorr  r   infer_vegalite_typer   )ru   r   r   r   rN   r   has_color_valuecolor_valuescolumn_typer   color_ranges              r0   r   r     sw    !$EGG)<<O  >c;//00 	=!!Q&&/}MMM!3>,tC/E/E"F"FGGG dE]33 	
5 1;??L<  C$6$666/mLLL;1$$%s~l4[^3L3L&M&MNNN sy&##)*Q*QL*Q*Q*QRRR0"    )_===		! 333#KK#7<8HIIKCI'<;
 
 
	
 333 "%Ig L!"" 	}R5Ea5H'I'I 	NNB|4D4K4K4M4MNNNK!*!=!=!=Ig #'Ih 4r/   r   alt.Size | alt.SizeValue | Nonec                R   dd l }| t          j        k    rv| |j        |t                    S t          |t          t          f          r |j        |          S | |j        d          S t          dt          |                     ||t          d| j         d          d S )Nr   )r  r   z&This does not look like a valid size: zChart type z: does not support size argument. This should never happen!)r   r!   r-   SizeSIZE_LEGEND_SETTINGSry   floatrF   	SizeValuer   reprr   rw   )rK   r   r   r   s       r0   r   r   o  s    
 Y&&&"38+   
 
UCL11 	 3=,,, 3=%%%'Kj9I9IKK   
	 J$:(*/ ( ( (
 
 	

 4r/   r   list[alt.Tooltip]c                   dd l }g }| t          k    r+|                     |j        | t                               n#|                     |j        |                      |t
          k    r,|                     |j        |t          d                     n#|                     |j        |                     |rkt          |dd          Z|t          k    r,|                     |j        |t          d                     n#|                     |j        |                     |r#|                     |j        |                     |S )Nr   )r  quantitative)r  r   r  Tr  )
r   r   r   TooltipSEPARATED_INDEX_COLUMN_TITLEr   MELTED_Y_COLUMN_TITLEgetattrr  MELTED_COLOR_COLUMN_TITLE)r   r   r   r   r   r   r   s          r0   r   r     s|    G ...{s{83OPPPQQQQ{s{8,,--- '''CK+#  	
 	
 	
 	
 	{s{8,,---
  6	8T::F333NN 3"      NN;3;|44555 1{s{;//000Nr/   type_util.VegaLiteTypec                    |dS |t           j        k    rt          | |          sdS t          j        | |                   S )Nr1  ordinal)r!   r+   r|   r   r#  )ru   rK   r   s      r0   r
  r
    sG     ~ Y]""?2x+H+H"y(H666r/   c                >    |rt          j        | |                   S dS )Nr1  )r   r#  )ru   r   s     r0   r  r    s&      ;,R\:::>r/   FrP   vega_lite_chartrV   rk   rl   rA   rR   None | Literal['streamlit']kwargsNonec                   ddl }i dfd}|j                            d|           |j        j        dk    r|j                            d          nt                      5  |j                            d          5  |                                }|d	<   t          j	        | |f||d
| ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )z!Marshall chart's data into proto.r   NrH   Dict[str, str]c                N    t          t          |                     }| |<   d|iS )z^Altair data transformer that returns a fake named dataset with the
        object id.
        rw   )r   id)rB   rw   datasetss     r0   id_transformzmarshall.<locals>.id_transform  s)     2d88}}~r/   rB  defaultnonerC  ro   )rH   r@  )
r   data_transformersregisterthemesactiveenabler   to_dictarrow_vega_literX   )	r;  rk   rA   rR   r=  r   rD  
chart_dictrC  s	           @r0   rX   rX     s     H      ""4666
 '*j&79&D&D		6	"	"	"+--  "))$// 	 	%--//J &.Jz"$ %8	 
   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	                 s6   !C<0B8,C8B<	<C?B<	 CCCc                       e Zd Z fdZ xZS )r   c                    d                     d t          |j                  D                       }d| d| d} t                      j        |g|R   d S )N, c              3  4   K   | ]}t          |          V  d S rr   r   r   s     r0   r   z8StreamlitColumnNotFoundError.__init__.<locals>.<genexpr>  s(      %G%Gc!ff%G%G%G%G%G%Gr/   z$Data does not have a column named `"z"`. Available columns are ``joinr   r   super__init__)r\   ru   col_nameargsavailable_columnsmessage	__class__s         r0   rW  z%StreamlitColumnNotFoundError.__init__  s}     II%G%Gd2:6F6F%G%G%GGG;8 ; ;&7; ; ; 	 	(4((((((r/   r'   r(   r)   rW  __classcell__r\  s   @r0   r   r   
  8        ) ) ) ) ) ) ) ) )r/   r   c                       e Zd Z fdZ xZS )r"  c                    d                     d t          |j                  D                        d| d} t                      j        |g|R   d S )NrQ  c              3  4   K   | ]}t          |          V  d S rr   r   r   s     r0   r   z6StreamlitInvalidColorError.__init__.<locals>.<genexpr>  s(      33Q#a&&333333r/   z2
This does not look like a valid color argument: `a5  `.

The color argument can be:

* A hex string like "#ffaa00" or "#ffaa0088".
* An RGB or RGBA tuple with the red, green, blue, and alpha
  components specified as ints from 0 to 255 or floats from 0.0 to
  1.0.
* The name of a column.
* Or a list of colors, matching the number of y columns to draw.
        rT  )r\   ru   rN   rY  r[  r\  s        r0   rW  z#StreamlitInvalidColorError.__init__  sn    		33$rz"2"23333332A   	(4((((((r/   r]  r_  s   @r0   r"  r"    s8        ) ) ) ) ) ) ) ) )r/   r"  c                       e Zd Z fdZ xZS )r  c                N    d| d| d} t                      j        |g|R   d S )NzThe list of colors `zB` must have the same length as the list of columns to be colored `z`.)rV  rW  )r\   r%  r   rY  r[  r\  s        r0   rW  z"StreamlitColorLengthError.__init__'  sR    "< " "" " " 	
 	(4((((((r/   r]  r_  s   @r0   r  r  &  r`  r/   r  )ru   rv   rw   rC   rH   rG   )ru   rv   r}   r~   r   r   r   r   r   r   rH   rv   )ru   rv   r   rC   r   r~   r   rC   r   rC   rH   r   )NNNNr   r   )rK   r!   rB   r   rL   rC   rM   rD   rN   rE   rO   r   r?   rF   r@   rF   rH   r   )ru   rv   r   rC   r   r~   rH   rC   )ru   rv   r   rC   rH   rv   )ru   rv   r   rC   )ru   rv   r   rC   r   r~   r   rC   r   rC   rH   r   )ru   rv   r   r   rH   r   )ru   rv   rL   rC   rH   rC   )ru   rv   rM   rD   r   rC   rH   r~   )rK   r!   r   rC   rH   r   )ru   rv   r   rC   rH   r   )ru   rv   r   rC   r   rG   rH   r   )ru   rv   r   rC   r   r~   r   rC   r   rC   rH   r   )
ru   rv   r   rC   rL   rC   rK   r!   rH   r  )ru   rv   r   rC   rM   rD   rH   r  )ru   rv   r   r  r   rC   r   r~   rN   rE   rH   r  )rK   r!   r   rC   r   r   rH   r(  )r   r   r   r   r   rC   r   rC   r   r  rH   r/  )ru   rv   rK   r!   r   rC   rH   r7  )ru   rv   r   rC   rH   r7  rs   )r;  rV   rk   rl   rA   rG   rR   r<  r=  r   rH   r>  )]__doc__
__future__r   
contextlibr   datetimer   enumr   typingr   r   r	   r
   r   r   r   r   pandasr   pandas.api.typesr   r   typing_extensionsr   "streamlit.elements.arrow_vega_liteelementsrM  rP   r   streamlit.color_utilr   r   r   r   r   streamlit.elements.altair_utilsr   streamlit.elements.arrowr   streamlit.elements.utilsr   streamlit.errorsr   r   &streamlit.proto.ArrowVegaLiteChart_pb2r   rV   streamlit.runtime.metrics_utilr   r   r   streamlit.delta_generatorr   r!   r   r!  r+  r3  r4  r6  PROTECTION_SUFFIXr   r   r  r  r;   r|   r   r   rW   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
  r  rX   r   r"  r  r.   r/   r0   <module>rz     sT    # " " " " " " " " " " "             T T T T T T T T T T T T T T T T T T T T     : : : : : : : : % % % % % % < < < < < < < < <                    < ; ; ; ; ; ) ) ) ) ) ) E E E E E E 9 9 9 9 9 9 9 9      : 9 9 9 9 9 9888888& & & & & & & && !AhGGG tQxHHH   '  #  - :=NN ,/@@ 47HH  ,.?? M, M, M, M, M, M, M, M,`, , , ,6& & & &R)F )F )F )F^ #.28<)-Z2 Z2 Z2 Z2 Z2z   "   *   &   (
 
 
 

 
 
 
$   B         & & & &D% % % %P$ $ $ $NM M M M`   @2 2 2 2j7 7 7 7    !&)4	, , , , ,^) ) ) ) )#8 ) ) )) ) ) ) )!6 ) ) )$) ) ) ) ) 5 ) ) ) ) )r/   