
    Cd                        d dl mZ d dlZd dlmZmZ d dlmZm	Z	m
Z
 	 d dlZn# e$ r dZY nw xY wd Zd Zd Zd Zd	 Zd
 Zd ZdS )    )annotationsN)PANDAS_GT_150PANDAS_GT_200)is_dataframe_likeis_index_likeis_series_likec                    t           dS t          r:t          j        d          t          j        t          j                              g}nt          j        d          g}| |v S )z$Is the input dtype a pyarrow string?NFpyarrow)par   pdStringDtype
ArrowDtypestring)dtypepa_string_typess     7lib/python3.11/site-packages/dask/dataframe/_pyarrow.pyis_pyarrow_string_dtyper      sW    	zu 6>)44bmBIKK6P6PQ>)445O##    c                    t           j        j                            |           o5t	          |            o%t           j        j                            | d           S )z0Determine if input is a non-pyarrow string dtypedecimal)r   apitypesis_string_dtyper   is_dtype_equal)r   s    r   is_object_string_dtyper      sP     	$$U++ 	>'...	>++E9===r   c                    t          | t          j                  rt          d | j        D                       S t          | t          j                  ot          | j                  S )Nc              3  4   K   | ]}t          |          V  d S N)is_object_string_index).0levels     r   	<genexpr>z)is_object_string_index.<locals>.<genexpr>&   s+      GGU)%00GGGGGGr   )
isinstancer   
MultiIndexanylevelsIndexr   r   xs    r   r   r   $   sX    !R]## HGGahGGGGGGa""F'=ag'F'FFr   c                    t          | t          j                  o't          | j                  pt          | j                  S r   )r#   r   Seriesr   r   r   indexr(   s    r   is_object_string_seriesr-   *   s8    a## qw''J+A!'+J+Jr   c                    t          | t          j                  o>t          d |                                 D                       pt          | j                  S )Nc              3  :   K   | ]\  }}t          |          V  d S r   )r-   )r    _ss      r   r"   z-is_object_string_dataframe.<locals>.<genexpr>2   s/      ==41a#A&&======r   )r#   r   	DataFramer%   itemsr   r,   r(   s    r   is_object_string_dataframer4   0   sO    a&& ==17799===== 	+!!'**r   c                (   t          |           s t          |           st          |           s| S d }t          |           r$d | j                                        D             }n(t          | j                  rt          j        d          }|r| 	                    |d          } t          |           st          |           rt          | j                  rt          | j        t          j                  rjd t          | j        j                  D             }| j                            |                                |                                d          | _        n1| j        	                    t          j        d                    | _        | S )Nc                \    i | ])\  }}t          |          |t          j        d           *S r
   )r   r   r   )r    colr   s      r   
<dictcomp>z%to_pyarrow_string.<locals>.<dictcomp>>   sF     
 
 
U%e,,
	**
 
 
r   r
   F)copyc                    i | ]A\  }}t          |j                  ||                    t          j        d                     BS r7   )r   r   astyper   r   )r    ir!   s      r   r9   z%to_pyarrow_string.<locals>.<dictcomp>N   sT       Au)%+665<<y 9 9::  r   )r!   verify_integrity)r   r   r   dtypesr3   r   r   r   r   r<   r   r,   r#   r$   	enumerater&   
set_levelsvalueskeys)dfr?   r&   s      r   to_pyarrow_stringrE   7   s   b!! ^B%7%7 =;L;L 	 F +
 
 ioo//
 
 

 
 	)	) +	** +YYvEY** 	" B!3!3 B9O
: : B bh.. 	B  )"(/ : :  F x**v{{}}u +  BHH xr~i'@'@AABHIr   c                 ^    t           t          d          t          st          d          dS )z+Make sure we have all the required versionsNz`Using dask's `dataframe.convert-string` configuration option requires `pyarrow` to be installed.zdUsing dask's `dataframe.convert-string` configuration option requires `pandas>=2.0` to be installed.)r   RuntimeErrorr    r   r   check_pyarrow_string_supportedrI   \   sI    	z9
 
 	
  
=
 
 	

 
r   )
__future__r   pandasr   dask.dataframe._compatr   r   dask.dataframe.utilsr   r   r   r
   r   ImportErrorr   r   r   r-   r4   rE   rI   rH   r   r   <module>rO      s   " " " " " "     ? ? ? ? ? ? ? ? Q Q Q Q Q Q Q Q Q Q   	BBB	$ 	$ 	$  G G G    " " "J
 
 
 
 
s   # --