
    ˀh	                    n    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	Zdd
Zy)    )annotations)TYPE_CHECKINGAny)get_first_non_none)pyarrow)pandasNT)lengthnan_to_nullc                  t        | dd      }|dk(  rt        | j                        }t        |t              r*t        j                  | t        j                         |      S |5t        j                  |xs t        |       t        j                               S t        j                  | |      S |rt        j                  | |      S d}t        || j                  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)from_pandaszduplicate column names found: )getattrr   values
isinstancestrpaarray
large_utf8nullslen
ValueErrorcolumnstolist)r   r	   r
   r   first_non_nonemsgs         |/var/www/html/wine-match-dev/backend/winematch-backend/venv/lib/python3.12/site-packages/polars/_utils/construction/other.pypandas_series_to_arrowr      s    . FGT*E+FMM:nc*88FBMMOMM#88F1c&k2==?CCxxK88	xxK88 /~~$$&)
 	
    c                N   ddl m} t        | d      r| j                  dkD  rt        j
                  j                  | j                        rWt        j
                  j                  | j                  j                        st        j
                  j                  | j                  j                        st        j
                  j                  | j                  j                        sft        j
                  j                  | j                  j                        s3t        j
                  j                  | j                  j                        rX|j                  | t	        j                  t	        j                          t	        j"                                     j%                         } | S )z...r   N
num_chunks   )pyarrow.computecomputehasattrr!   r   typesis_dictionarytypeis_int8
index_typeis_uint8is_int16	is_uint16is_int32cast
dictionaryuint32large_stringcombine_chunks)r   pcs     r   coerce_arrowr5   7   s     ul#(8(81(< 88!!%**-HHUZZ223xx  !6!67xx  !6!67xx!!%**"7"78xx  !6!67GGr}}RYY["//2CDn  Lr   )r   zpd.Series[Any] | pd.Index[Any]r	   z
int | Noner
   boolreturnpa.Array)r   r8   r7   r8   )
__future__r   typingr   r    polars._utils.construction.utilsr   polars.dependenciesr   r   r   pdr   r5    r   r   <module>r?      sP    " % ? -0 	(
*(
 (
 	(

 (
Vr   