Ë
    *�£jœ9  ã                  óÔ   — d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m
Z
 ddlmZ e
rddlZddlmZ ddlmZ erdd	lmZ dd
lmZmZ  G d„ de¬«      Z G d„ de«      Z G d„ de«      Zy)z Accessors for arrow-backed data.é    )Úannotations)ÚABCMetaÚabstractmethod)ÚTYPE_CHECKINGÚcast)ÚHAS_PYARROW)Úis_list_likeN)Ú
ArrowDtype)ÚIterator)Ú	DataFrameÚSeriesc                  óH   — e Zd Zedd„«       Zedd„«       Zdd„Zed„ «       Zy)	ÚArrowAccessorc                óB   — || _         || _        | j                  |«       y ©N)Ú_dataÚ_validation_msgÚ	_validate)ÚselfÚdataÚvalidation_msgs      úDC:\FundamentalWorkbench\vendor\pandas\core\arrays\arrow\accessors.pyÚ__init__zArrowAccessor.__init__"   s   € àˆŒ
Ø-ˆÔØ�‰�tÕó    c                 ó   — y r   © ©r   Úpyarrow_dtypes     r   Ú_is_valid_pyarrow_dtypez%ArrowAccessor._is_valid_pyarrow_dtype(   s   € àr   c                ó  — |j                   }t        rt        |t        «      s%t	        | j
                  j                  |¬«      «      ‚| j                  |j                  «      s%t	        | j
                  j                  |¬«      «      ‚y )N)Údtype)	r!   r   Ú
isinstancer
   ÚAttributeErrorr   Úformatr   r   )r   r   r!   s      r   r   zArrowAccessor._validate,   so   € Ø—
‘
ˆÝ¤*¨U´JÔ"?ä  ×!5Ñ!5×!<Ñ!<À5Ð!<Ó!IÓJÐJà×+Ñ+¨E×,?Ñ,?Ô@ä  ×!5Ñ!5×!<Ñ!<À5Ð!<Ó!IÓJÐJð Ar   c                óB   — | j                   j                  j                  S r   )r   ÚarrayÚ	_pa_array©r   s    r   r'   zArrowAccessor._pa_array6   s   € à�z‰z×Ñ×)Ñ)Ð)r   N)r   ÚstrÚreturnÚNone©r*   Úbool©r*   r+   )	Ú__name__Ú
__module__Ú__qualname__r   r   r   r   Úpropertyr'   r   r   r   r   r   !   sB   „ Øòó ðð
 òó ðóKð ñ*ó ñ*r   r   )Ú	metaclassc                  óN   ‡ — e Zd ZdZdd	ˆ fd„Zd
d„Zdd„Zdd„Zdd„Zdd„Z	ˆ xZ
S )ÚListAccessorz¤
    Accessor object for list data properties of the Series values.

    Parameters
    ----------
    data : Series
        Series containing Arrow list data.
    c                ó(   •— t         ‰| �  |d¬«       y )NzJCan only use the '.list' accessor with 'list[pyarrow]' dtype, not {dtype}.©r   ©Úsuperr   ©r   r   Ú	__class__s     €r   r   zListAccessor.__init__E   s   ø€ Ü‰ÑØð2ð 	õ 	
r   c                óÄ   — t         j                  j                  |«      xs@ t         j                  j                  |«      xs t         j                  j	                  |«      S r   )ÚpaÚtypesÚis_listÚis_fixed_size_listÚis_large_listr   s     r   r   z$ListAccessor._is_valid_pyarrow_dtypeL   sG   € ä�H‰H×Ñ˜]Ó+ò 5Ü�x‰x×*Ñ*¨=Ó9ò5ä�x‰x×%Ñ% mÓ4ð	
r   c                óÚ   — ddl m} t        j                  | j                  «      } ||t        |j                  «      | j                  j                  | j                  j                  ¬«      S )aò  
        Return the length of each list in the Series.

        Returns
        -------
        pandas.Series
            The length of each list.

        See Also
        --------
        str.len : Python built-in function returning the length of an object.
        Series.size : Returns the length of the Series.
        StringMethods.len : Compute the length of each element in the Series/Index.

        Examples
        --------
        >>> import pyarrow as pa
        >>> s = pd.Series(
        ...     [
        ...         [1, 2, 3],
        ...         [3],
        ...     ],
        ...     dtype=pd.ArrowDtype(pa.list_(pa.int64())),
        ... )
        >>> s.list.len()
        0    3
        1    1
        dtype: int32[pyarrow]
        r   ©r   ©r!   ÚindexÚname)
Úpandasr   ÚpcÚlist_value_lengthr'   r
   Útyper   rE   rF   )r   r   Úvalue_lengthss      r   ÚlenzListAccessor.lenS   sQ   € õ< 	"ä×,Ñ,¨T¯^©^Ó<ˆÙØÜ˜]×/Ñ/Ó0Ø—*‘*×"Ñ"Ø—‘—‘ô	
ð 	
r   c                óˆ  — ddl m} t        |t        «      rgt	        j
                  | j                  |«      } ||t        |j                  «      | j                  j                  | j                  j                  ¬«      S t        |t        «      r•|j                  |j                  |j                  }}}|€d}|€d}t	        j                   | j                  |||«      } ||t        |j                  «      | j                  j                  | j                  j                  ¬«      S t#        dt        |«      j$                  › �«      ‚)aÄ  
        Index or slice lists in the Series.

        Parameters
        ----------
        key : int | slice
            Index or slice of indices to access from each list.

        Returns
        -------
        pandas.Series
            The list at requested index.

        See Also
        --------
        ListAccessor.flatten : Flatten list values.

        Examples
        --------
        >>> import pyarrow as pa
        >>> s = pd.Series(
        ...     [
        ...         [1, 2, 3],
        ...         [3],
        ...     ],
        ...     dtype=pd.ArrowDtype(pa.list_(pa.int64())),
        ... )
        >>> s.list[0]
        0    1
        1    3
        dtype: int64[pyarrow]
        r   rC   rD   é   z!key must be an int or slice, got )rG   r   r"   ÚintrH   Úlist_elementr'   r
   rJ   r   rE   rF   ÚsliceÚstartÚstopÚstepÚ
list_sliceÚ
ValueErrorr/   )r   Úkeyr   ÚelementrR   rS   rT   Úsliceds           r   Ú__getitem__zListAccessor.__getitem__{   s  € õB 	"ä�cœ3Ôô
 —o‘o d§n¡n°cÓ:ˆGÙØÜ  §¡Ó.Ø—j‘j×&Ñ&Ø—Z‘Z—_‘_ô	ð ô ˜œUÔ#ð !$§	¡	¨3¯8©8°S·X±X˜�4ˆEØˆ}ð �Øˆ|Ø�Ü—]‘] 4§>¡>°5¸$ÀÓEˆFÙØÜ  §¡Ó-Ø—j‘j×&Ñ&Ø—Z‘Z—_‘_ô	ð ô Ð@ÄÀcÃ×ASÑASÐ@TÐUÓVÐVr   c                óF   — t        dt        | «      j                  › d�«      ‚)NÚ'z' object is not iterable)Ú	TypeErrorrJ   r/   r(   s    r   Ú__iter__zListAccessor.__iter__¿   s"   € Ü˜!œD ›J×/Ñ/Ð0Ð0HÐIÓJÐJr   c                ó¼  — ddl m} t        j                  j	                  | j
                  «      }t        j                  j                  | j
                  «      }| j                  j                  j                  |j                  t        j                  d|j                  «      «      «      } ||t        |j                  «      || j                  j                  ¬«      S )a�  
        Flatten list values.

        Returns
        -------
        pandas.Series
            The data from all lists in the series flattened.

        See Also
        --------
        ListAccessor.__getitem__ : Index or slice values in the Series.

        Examples
        --------
        >>> import pyarrow as pa
        >>> s = pd.Series(
        ...     [
        ...         [1, 2, 3],
        ...         [3],
        ...     ],
        ...     dtype=pd.ArrowDtype(pa.list_(pa.int64())),
        ... )
        >>> s.list.flatten()
        0    1
        0    2
        0    3
        1    3
        dtype: int64[pyarrow]
        r   rC   rD   )rG   r   r=   ÚcomputerI   r'   Úlist_flattenr   rE   ÚrepeatÚ	fill_nullÚscalarrJ   r
   rF   )r   r   ÚcountsÚ	flattenedrE   s        r   ÚflattenzListAccessor.flattenÂ   s•   € õ< 	"ä—‘×-Ñ-¨d¯n©nÓ=ˆÜ—J‘J×+Ñ+¨D¯N©NÓ;ˆ	Ø—
‘
× Ñ ×'Ñ'¨×(8Ñ(8¼¿¹À1ÀfÇkÁkÓ9RÓ(SÓTˆÙØÜ˜YŸ^™^Ó,ØØ—‘—‘ô	
ð 	
r   r   r.   r,   ©r*   r   )rW   zint | slicer*   r   )r*   r   )r/   r0   r1   Ú__doc__r   r   rL   rZ   r^   rg   Ú__classcell__©r;   s   @r   r5   r5   ;   s+   ø„ ñö
ó
ó&
óPBWóHK÷(
r   r5   c                  óX   ‡ — e Zd ZdZddˆ fd„Zd	d„Zed
d„«       Z	 	 	 	 dd„Zdd„Z	ˆ xZ
S )ÚStructAccessorz¬
    Accessor object for structured data properties of the Series values.

    Parameters
    ----------
    data : Series
        Series containing Arrow struct data.
    c                ó(   •— t         ‰| �  |d¬«       y )NzNCan only use the '.struct' accessor with 'struct[pyarrow]' dtype, not {dtype}.r7   r8   r:   s     €r   r   zStructAccessor.__init__÷   s   ø€ Ü‰ÑØð&ð 	õ 	
r   c                ó@   — t         j                  j                  |«      S r   )r=   r>   Ú	is_structr   s     r   r   z&StructAccessor._is_valid_pyarrow_dtype   s   € Ü�x‰x×!Ñ! -Ó0Ð0r   c                óü   — ddl m}m} | j                  j                  j
                  }|D �cg c]  }t        |j                  «      ‘Œ }}|D �cg c]  }|j                  ‘Œ }} || ||«      ¬«      S c c}w c c}w )aZ  
        Return the dtype object of each child field of the struct.

        Returns
        -------
        pandas.Series
            The data type of each child field.

        See Also
        --------
        Series.dtype: Return the dtype object of the underlying data.

        Examples
        --------
        >>> import pyarrow as pa
        >>> s = pd.Series(
        ...     [
        ...         {"version": 1, "project": "pandas"},
        ...         {"version": 2, "project": "pandas"},
        ...         {"version": 1, "project": "numpy"},
        ...     ],
        ...     dtype=pd.ArrowDtype(
        ...         pa.struct([("version", pa.int64()), ("project", pa.string())])
        ...     ),
        ... )
        >>> s.struct.dtypes
        version     int64[pyarrow]
        project    string[pyarrow]
        dtype: object
        r   )ÚIndexr   )rE   )	rG   rr   r   r   r!   r   r
   rJ   rF   )r   rr   r   Úpa_typeÚstructr>   Únamess          r   ÚdtypeszStructAccessor.dtypes  sn   € ÷@	
ð
 —*‘*×"Ñ"×0Ñ0ˆÙ7>Ó?±w¨V”˜FŸK™KÕ(°wˆÐ?Ù+2Ó3©7 �—“¨7ˆÐ3Ù�e¡5¨£<Ô0Ð0ùò @ùÚ3s   ­A4ÁA9c                ó  ‡— ddl m} 	 	 	 	 dˆfd„Š| j                  j                  j                  } ‰||«      }t        j                  ||«      } ||t        |j                  «      | j                  j                  |¬«      S )aï  
        Extract a child field of a struct as a Series.

        Parameters
        ----------
        name_or_index : str | bytes | int | expression | list
            Name or index of the child field to extract.

            For list-like inputs, this will index into a nested
            struct.

        Returns
        -------
        pandas.Series
            The data corresponding to the selected child field.

        See Also
        --------
        Series.struct.explode : Return all child fields as a DataFrame.

        Notes
        -----
        The name of the resulting Series will be set using the following
        rules:

        - For string, bytes, or integer `name_or_index` (or a list of these, for
          a nested selection), the Series name is set to the selected
          field's name.
        - For a :class:`pyarrow.compute.Expression`, this is set to
          the string form of the expression.
        - For list-like `name_or_index`, the name will be set to the
          name of the final field selected.

        Examples
        --------
        >>> import pyarrow as pa
        >>> s = pd.Series(
        ...     [
        ...         {"version": 1, "project": "pandas"},
        ...         {"version": 2, "project": "pandas"},
        ...         {"version": 1, "project": "numpy"},
        ...     ],
        ...     dtype=pd.ArrowDtype(
        ...         pa.struct([("version", pa.int64()), ("project", pa.string())])
        ...     ),
        ... )

        Extract by field name.

        >>> s.struct.field("project")
        0    pandas
        1    pandas
        2     numpy
        Name: project, dtype: string[pyarrow]

        Extract by field index.

        >>> s.struct.field(0)
        0    1
        1    2
        2    1
        Name: version, dtype: int64[pyarrow]

        Or an expression

        >>> import pyarrow.compute as pc
        >>> s.struct.field(pc.field("project"))
        0    pandas
        1    pandas
        2     numpy
        Name: project, dtype: string[pyarrow]

        For nested struct types, you can pass a list of values to index
        multiple levels:

        >>> version_type = pa.struct(
        ...     [
        ...         ("major", pa.int64()),
        ...         ("minor", pa.int64()),
        ...     ]
        ... )
        >>> s = pd.Series(
        ...     [
        ...         {"version": {"major": 1, "minor": 5}, "project": "pandas"},
        ...         {"version": {"major": 2, "minor": 1}, "project": "pandas"},
        ...         {"version": {"major": 1, "minor": 26}, "project": "numpy"},
        ...     ],
        ...     dtype=pd.ArrowDtype(
        ...         pa.struct([("version", version_type), ("project", pa.string())])
        ...     ),
        ... )
        >>> s.struct.field(["version", "minor"])
        0     5
        1     1
        2    26
        Name: minor, dtype: int64[pyarrow]
        >>> s.struct.field([0, 0])
        0    1
        1    2
        2    1
        Name: major, dtype: int64[pyarrow]
        r   rC   c                ó,  •— t        | t        «      r'|j                  j                  | «      j                  }|S t        | t
        t        f«      r| }|S t        | t        j                  «      rt        | «      }|S t        | «      r†t        t        | «      «      } |}| rlt        t        | «      } | j                  «       } ‰||«      }|j                  j                  |j                  j                  |«      «      }|j                  }| rŒlS t        d«      ‚)NzVname_or_index must be an int, str, bytes, pyarrow.compute.Expression, or list of those)r"   rO   rJ   ÚfieldrF   r)   ÚbytesrH   Ú
Expressionr	   ÚlistÚreversedr   ÚpopÚget_field_indexrV   )Úlevel_name_or_indexr   rF   ÚselectedÚname_or_indexÚget_names        €r   rƒ   z&StructAccessor.field.<locals>.get_nameŸ  s  ø€ ô Ð-¬sÔ3Ø—y‘y—‘Ð':Ó;×@Ñ@�ð0 ˆKô/ Ð/´#´u°Ô>Ø*�ð, ˆKô+ Ð/´·±Ô?ÜÐ.Ó/�ð( ˆKô' Ð1Ô2ô '+¬8Ð4GÓ+HÓ&IÐ#Ø�Ù)ô +/¬tÐ5HÓ*IÐ'Ø$7×$;Ñ$;Ó$=�MÙ# M°8Ó<�DØ'Ÿ}™}×2Ñ2°8·=±=×3PÑ3PÐQUÓ3VÓW�HØ#Ÿ=™=�Dò *ð ˆKô	 !ðCóð r   rD   )r€   úGlist[str] | list[bytes] | list[int] | pc.Expression | bytes | str | intr   zpa.ChunkedArray)
rG   r   r   r&   r'   rH   Ústruct_fieldr
   rJ   rE   )r   r‚   r   Úpa_arrrF   Ú	field_arrrƒ   s         @r   ry   zStructAccessor.field-  s‚   ø€ õ` 	"ð#	ð"ð#	ð "õ#	ðJ —‘×!Ñ!×+Ñ+ˆÙ˜ vÓ.ˆÜ—O‘O F¨MÓ:ˆ	áØÜ˜YŸ^™^Ó,Ø—*‘*×"Ñ"Øô	
ð 	
r   c                ó¸   — ddl m} | j                  j                  } |t	        |j
                  «      D �cg c]  }| j                  |«      ‘Œ c}d¬«      S c c}w )au  
        Extract all child fields of a struct as a DataFrame.

        Returns
        -------
        pandas.DataFrame
            The data corresponding to all child fields.

        See Also
        --------
        Series.struct.field : Return a single child field as a Series.

        Examples
        --------
        >>> import pyarrow as pa
        >>> s = pd.Series(
        ...     [
        ...         {"version": 1, "project": "pandas"},
        ...         {"version": 2, "project": "pandas"},
        ...         {"version": 1, "project": "numpy"},
        ...     ],
        ...     dtype=pd.ArrowDtype(
        ...         pa.struct([("version", pa.int64()), ("project", pa.string())])
        ...     ),
        ... )

        >>> s.struct.explode()
           version project
        0        1  pandas
        1        2  pandas
        2        1   numpy
        r   )ÚconcatÚcolumns)Úaxis)rG   r‰   r'   rJ   ÚrangeÚ
num_fieldsry   )r   r‰   rs   Úis       r   ÚexplodezStructAccessor.explodeÏ  sP   € õB 	"à—.‘.×%Ñ%ˆÙÜ$)¨'×*<Ñ*<Ô$=Ó>Ñ$=˜qˆT�Z‰Z˜�]Ð$=Ñ>ÀYô
ð 	
ùÚ>s   ¶Ar   r.   r,   rh   )r‚   r„   r*   r   )r*   r   )r/   r0   r1   ri   r   r   r2   rv   ry   r�   rj   rk   s   @r   rm   rm   í   sI   ø„ ñö
ó1ð ò'1ó ð'1ðR`
ðð`
ð 
ó`
÷D&
r   rm   )ri   Ú
__future__r   Úabcr   r   Útypingr   r   Úpandas.compatr   Úpandas.core.dtypes.commonr	   Úpyarrowr=   Úpyarrow.computer`   rH   Úpandas.core.dtypes.dtypesr
   Úcollections.abcr   rG   r   r   r   r5   rm   r   r   r   Ú<module>r™      s]   ðÙ &å "÷÷õ
 &å 2áÛÝ å4áÝ(÷ô*˜gõ *ô4o
�=ô o
ôdH
�]õ H
r   