o
    i	                     @  sd   d dl mZ d dlmZmZ d dlmZ d dlm	Z	 er"d dlm
Z ddddddZdddZdS )    )annotations)TYPE_CHECKINGAny)pyarrow)get_first_non_none)pandasNT)lengthnan_to_nullvaluespd.Series[Any] | pd.Index[Any]r   
int | Noner	   boolreturnpa.Arrayc                C  s   t | dd}|dkr5t| j}t|trtj| t |dS |du r.t|p)t	| t S tj| |dS |r>tj| |dS d}t
|| j )a  
    Convert a pandas Series to an Arrow Array.

    Parameters
    ----------
    values : :class:`pandas.Series` or :class:`pandas.Index`.
        Series to convert to arrow
    nan_to_null : bool, default = True
        Interpret `NaN` as missing values.
    length : int, optional
        in case all values are null, create a null array of this length.
        if unset, length is inferred from values.

    Returns
    -------
    :class:`pyarrow.Array`
    dtypeNobject)Zfrom_pandaszduplicate column names found: )getattrr   r
   
isinstancestrpaarrayZ
large_utf8Znullslen
ValueErrorcolumnstolist)r
   r   r	   r   Zfirst_non_nonemsg r   W/home/app/Keep/.python/lib/python3.10/site-packages/polars/_utils/construction/other.pypandas_series_to_arrow   s   


r   r   c                 C  s   ddl m} t| drO| jdkrOtj| jrOtj| jj	s?tj
| jj	s?tj| jj	s?tj| jj	s?tj| jj	rO|| tt t  } | S )z...r   N
num_chunks   )Zpyarrow.computeZcomputehasattrr   r   typesZis_dictionarytypeZis_int8Z
index_typeZis_uint8Zis_int16Z	is_uint16Zis_int32cast
dictionaryZuint32Zlarge_stringZcombine_chunks)r   Zpcr   r   r   coerce_arrow7   s&   r&   )r
   r   r   r   r	   r   r   r   )r   r   r   r   )
__future__r   typingr   r   Zpolars._dependenciesr   r   Z polars._utils.construction.utilsr   r   pdr   r&   r   r   r   r   <module>   s    +