
    &PhL                    ,   d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	 d dl
Z
d dl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 d d	l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$m%Z% d dl&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z, d dl-mZm.Z.m/Z/ d dl0m1Z1 d dl2m3Z3 d dl4m5Z5 d dl6m7Z7m8Z8 d dl9m:Z:m;Z; d dl<m=Z= d dl>m?Z? d dl@mAZA d dlBmCZC d dlDmEZE er"d dlFZFd dlGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQ d dlRmSZS e% G d de$             ZT G d de5      ZU G d  d!eUe=      ZV G d" d#eV      ZWy)$    )annotations)partialN)TYPE_CHECKINGAnyLiteralcast)
get_optionusing_string_dtype)libmissing)NDArrayBacked)ensure_string_array)HAS_PYARROWpa_version_under10p1)function)doc)find_stack_level)ExtensionDtypeStorageExtensionDtyperegister_extension_dtype)is_array_likeis_bool_dtypeis_integer_dtypeis_object_dtypeis_string_dtypepandas_dtype)r   nanopsops)isin)masked_reductions)ExtensionArray)FloatingArrayFloatingDtype)IntegerArrayIntegerDtype)NumpyExtensionArray)extract_array)check_array_indexer)isna)printing)
	ArrayLikeAxisIntDtypeDtypeObjNumpySorterNumpyValueArrayLikeScalarSelfnpttype_t)Seriesc                       e Zd ZdZedd       Zedd       ZdZdej                  f	 	 	 	 	 ddZ
ddZddZd fd	Zd
 Zedd       Zedd       Z	 	 ddZddZ	 	 	 	 ddZ xZS )StringDtypea  
    Extension dtype for string data.

    .. warning::

       StringDtype is considered experimental. The implementation and
       parts of the API may change without warning.

    Parameters
    ----------
    storage : {"python", "pyarrow"}, optional
        If not given, the value of ``pd.options.mode.string_storage``.
    na_value : {np.nan, pd.NA}, default pd.NA
        Whether the dtype follows NaN or NA missing value semantics.

    Attributes
    ----------
    None

    Methods
    -------
    None

    Examples
    --------
    >>> pd.StringDtype()
    string[python]

    >>> pd.StringDtype(storage="pyarrow")
    string[pyarrow]
    c                >    | j                   t        j                  u ryy)Nstringstr)	_na_value
libmissingNAselfs    eC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\pandas/core/arrays/string_.pynamezStringDtype.name|   s    >>Z]]*    c                    | j                   S N)r;   r>   s    r@   na_valuezStringDtype.na_value   s    ~~rB   )storager;   Nc                4   |@|t         j                  urt        d      }|dk(  rt        rd}nd}nt        d      }|dk(  rd}|dk(  r6t	        j
                  dt        t                      d}t        j                  }|dvrt        d	| d
      |dk(  rt        rt        d      t        |t              r&t        j                  |      rt        j                  }n |t         j                  urt        d|       t!        t"        |      | _        || _        y )Nzmode.string_storageautopyarrowpythonpyarrow_numpya]  The 'pyarrow_numpy' storage option name is deprecated and will be removed in pandas 3.0. Use 'pd.StringDtype(storage="pyarrow", na_value-np.nan)' to construct the same dtype.
Or enable the 'pd.options.future.infer_string = True' option globally and use the "str" alias as a shorthand notation to specify a dtype (instead of "string[pyarrow_numpy]").)
stacklevel>   rJ   rI   z+Storage must be 'python' or 'pyarrow'. Got z	 instead.z;pyarrow>=10.0.1 is required for PyArrow backed StringArray.z('na_value' must be np.nan or pd.NA, got )r<   r=   r	   r   warningswarnFutureWarningr   npnan
ValueErrorr   ImportError
isinstancefloatisnanr   r:   rF   r;   )r?   rF   rE   s      r@   __init__zStringDtype.__init__   s    ?z}},$%:;f$""+"*$%:;f$&Go%MM8 +-	  GvvH //=gYiP  i$8M  h&288H+= vvHZ]]*GzRSSC)!rB   c                    | j                   t        j                  u r| j                   d| j                   dS | j                  S )N[])r;   r<   r=   rA   rF   r>   s    r@   __repr__zStringDtype.__repr__   s9    >>Z]]*ii[$,,q11 99rB   c                ,   t        |t              r'|dk(  s|| j                  k(  ry	 | j                  |      }t        |t        |             r3| j                  |j                  k(  xr | j                  |j                  u S y# t        t
        f$ r Y yw xY w)Nr9   TF)	rT   r:   rA   construct_from_string	TypeErrorrS   typerF   rE   )r?   others     r@   __eq__zStringDtype.__eq__   s     eS! ETYY$62259
 eT$Z(<<5==0TT]]enn5TT {+  s   B BBc                     t         |          S rD   )super__hash__)r?   	__class__s    r@   rd   zStringDtype.__hash__   s    w!!rB   c                >    t         | j                  | j                  ffS rD   )r7   rF   rE   r>   s    r@   
__reduce__zStringDtype.__reduce__   s    T\\4==999rB   c                    t         S rD   )r:   r>   s    r@   r_   zStringDtype.type   s    
rB   c                @   t        |t              st        dt        |             |dk(  r |        S |dk(  r!t	               r | t
        j                        S |dk(  r	 | d      S |dk(  r	 | d	      S |d
k(  r	 | d      S t        d| j                   d| d      )a|  
        Construct a StringDtype from a string.

        Parameters
        ----------
        string : str
            The type of the name. The storage type will be taking from `string`.
            Valid options and their storage types are

            ========================== ==============================================
            string                     result storage
            ========================== ==============================================
            ``'string'``               pd.options.mode.string_storage, default python
            ``'string[python]'``       python
            ``'string[pyarrow]'``      pyarrow
            ========================== ==============================================

        Returns
        -------
        StringDtype

        Raise
        -----
        TypeError
            If the string is not a valid option.
        z.'construct_from_string' expects a string, got r9   r:   rE   zstring[python]rJ   rF   zstring[pyarrow]rI   zstring[pyarrow_numpy]rK   zCannot construct a 'z' from '')rT   r:   r^   r_   r
   rP   rQ   __name__)clsr9   s     r@   r]   z!StringDtype.construct_from_string   s    8 &#&@fO  X5Lu_!3!5''''x((((y))..//23<<.PQRSSrB   c                    ddl m}m} | j                  dk(  r"| j                  t
        j                  u rt        S | j                  dk(  r| j                  t
        j                  u r|S | j                  dk(  rt        S |S )zq
        Return the array type associated with this dtype.

        Returns
        -------
        type
        r   )ArrowStringArrayArrowStringArrayNumpySemanticsrJ   rI   )	pandas.core.arrays.string_arrowrp   rq   rF   r;   r<   r=   StringArrayStringArrayNumpySemantics)r?   rp   rq   s      r@   construct_array_typez StringDtype.construct_array_type  sc    	

 <<8#*--(G\\Y&4>>Z]]+J##\\X%,,11rB   c                   t               }t               }|D ]s  }t        |t              r7|j                  |j                         |j                  |j
                         Jt        |t        j                        r|j                  dv rs y  t        |      dk(  rd}nt        t        |            }t        |      dk(  rt        j                  }nt        t        |            }t        ||      S )N)UT   rI   rF   rE   )setrT   r7   addrF   rE   rP   dtypekindlennextiterr<   r=   )r?   dtypesstorages	na_valuesr}   rF   rE   s          r@   _get_common_dtypezStringDtype._get_common_dtype,  s    5E	E%-U]]+enn-E288,z1I  x=AG4>*G y>Q!}}HDO,H7X>>rB   c                L   | j                   dk(  r8| j                  t        j                  u rddlm}  ||      S ddlm}  ||      S ddl}t        ||j                        r|g}n|j                  }g }|D ]<  }|j                  d      }t        || j                        }|j                  |       > t        |      dk(  rt!        j"                  g t$        	      }nt!        j&                  |      }t(        j+                  t(              }t-        j.                  |||        |S )
zH
        Construct StringArray from pyarrow Array/ChunkedArray.
        rI   r   )rp   )rq   NF)zero_copy_onlyrj   r}   )rF   r;   r<   r=   rr   rp   rq   rI   rT   Arraychunksto_numpyr   rE   appendr   rP   arrayobjectconcatenaters   __new__r   rW   )	r?   r   rp   rq   rI   r   resultsarrnew_string_arrays	            r@   __from_arrow__zStringDtype.__from_arrow__H  s     <<9$~~.L'.. 6e<< %/ G ll%l8)#Fs#  v;!((2V,C..)C '..{;/d;rB   )returnr:   )r   libmissing.NAType | float)rF   z
str | NonerE   r   r   None)r`   r   r   bool)r   int)r   z	type[str])r   r2   )r   ztype_t[BaseStringArray])r   zlist[DtypeObj]r   zDtypeObj | None)r   z$pyarrow.Array | pyarrow.ChunkedArrayr   BaseStringArray)rm   
__module____qualname____doc__propertyrA   rE   	_metadatar<   r=   rW   r[   ra   rd   rg   r_   classmethodr]   ru   r   r   __classcell__re   s   @r@   r7   r7   Z   s    @     )I #.8mm3"3" ,3" 
	3"j"":   +T +T`2	 20?8+ 9+ 	+ rB   r7   c                       e Zd ZU dZded<    eej                        d        Zedd       Z	dddZ
ej                  ddf	 	 	 dd	Z	 	 	 	 dd
Zej                  ddf	 	 	 ddZdd fdZ xZS )r   z8
    Mixin class for StringArray, ArrowStringArray.
    r7   r}   c                    | j                   dkD  r| D cg c]  }|j                          c}S t        | j                               S c c}w )N   )ndimtolistlistr   )r?   xs     r@   r   zBaseStringArray.tolist}  s>    99q=(,-1AHHJ--DMMO$$ .s   Ac                f    t        j                  |d      dvrt        | j                  ||      S )NTskipna)r9   emptyr   )r   infer_dtyperR   _from_sequence)rn   scalarsr}   s      r@   _from_scalarszBaseStringArray._from_scalars  s2    ??7408KK!!'!77rB   c                @    t        t        j                  d|       }|S )N)	
)escape_charsquote_strings)r   r*   pprint_thing)r?   boxed	formatters      r@   
_formatterzBaseStringArray._formatter  s%    !!+#)
	
 rB   NTc                   | j                   j                  t        j                  u r| j	                  ||||      S ddlm} || j                   }|t        j                  u r| j                   j                  }t        |       }t        j                  |       }t        |      st        |      rt        |      rt        }n|}t        |      }	|	rd}n#|t        j                   d      k(  rt        |      }t        j                  |||j!                  d      d|t        j                   t#        t$        |                  }
|	sd|d d   ||
|      S | j'                  |||||      S )	N)rE   r}   convertr   BooleanArrayr   r   uint8Fr   rE   r}   )r}   rE   rP   rQ   _str_map_nan_semanticspandas.arraysr   r   
no_defaultr)   asarrayr   r   r$   r   map_infer_maskviewr   r_   _str_map_str_or_object)r?   frE   r}   r   r   maskr   constructorna_value_is_naresults              r@   _str_mapzBaseStringArray._str_map  s?    ::"&&(..HE7 /   	/=JJEs~~%zz**HDzjjE"mE&:&**!(^N"((6**>''		'"! hhtD%01
F "Qvt,, ..uhQMMrB   c                n   t        |      rt        |      szt        j                  |||j	                  d      d|      }| j
                  j                  dk(  r'dd l}|j                  |||j                         d      } t        |       |      S t        j                  |||j	                  d            S )Nr   F)r   rE   rI   r   T)r   r_   from_pandas)r   r   r   r   r   r}   rF   rI   r   large_stringr_   )r?   r}   rE   r   r   r   r   pas           r@   r   z&BaseStringArray._str_map_str_or_object  s     5!/%*@''Q		'*EHF zz!!Y.$BOO,=4 "  4:f%% %%c1dii.@AArB   c                v   || j                   }|t        j                  u r$t        |      rd}n| j                   j                  }t        |       }t        j                  |       }t        |      st        |      rt        |      }|rt        |      rd}nd}t        j                  |||j                  d      d|t        j                   t        t        |                  }|r?t        |      r4|j                         r$|j                  d      }t        j                  ||<   |S | j!                  |||||      S )NFr   r   r   float64)r}   r   r   r   rE   r)   rP   r   r   r   r   r   r_   anyastyperQ   r   )	r?   r   rE   r}   r   r   r   r   r   s	            r@   r   z&BaseStringArray._str_map_nan_semantics  s    =JJEs~~%U# ::..DzjjE"mE&:!(^N#E* H  %H''		'"!hhtD%01F "25"9dhhj  y1!vvtM ..uhQMMrB   c                >    |t        d      t        | 	  |      S )Nz)Cannot change data-type for string array.r   )r^   rc   r   )r?   r}   re   s     r@   r   zBaseStringArray.view  s&    GHHw|%|((rB   )r}   r.   r   r2   F)r   r   )r}   Dtype | Noner   r   )r   z
np.ndarrayr   npt.NDArray[np.bool_]rD   )r}   r   r   r+   )rm   r   r   r   __annotations__r   r!   r   r   r   r   r   r   r   r   r   r   r   r   s   @r@   r   r   v  s     		%  %
 8 8 "5N 	5N
 5NnB 	B $BB ".N 	.N
 .N`) )rB   r   c                      e Zd ZU dZdZdZej                  Zde	d<   d&d' fdZ
d Zd	 Zed
ddd(d       Zed
dd	 	 	 d(d       Zed)d       Zd*dZd+dZd Zd, fdZd-dZd.dZd/dZd0d1 fdZdddd	 	 	 	 	 	 	 d2dZddd3dZd4 fdZd5d6dZd5d6dZd
ddd 	 	 	 	 	 	 	 d7d!Zd0d8d"Zd&d9d#Z  e!e"jF                        	 	 d:	 	 	 	 	 	 	 d; fd$       Z#d% Z$e$Z% xZ&S )<rs   aY  
    Extension array for string data.

    .. warning::

       StringArray is considered experimental. The implementation and
       parts of the API may change without warning.

    Parameters
    ----------
    values : array-like
        The array of data.

        .. warning::

           Currently, this expects an object-dtype ndarray
           where the elements are Python strings
           or nan-likes (``None``, ``np.nan``, ``NA``).
           This may change without warning in the future. Use
           :meth:`pandas.array` with ``dtype="string"`` for a stable way of
           creating a `StringArray` from any sequence.

        .. versionchanged:: 1.5.0

           StringArray now accepts array-likes containing
           nan-likes(``None``, ``np.nan``) for the ``values`` parameter
           in addition to strings and :attr:`pandas.NA`

    copy : bool, default False
        Whether to copy the array of data.

    Attributes
    ----------
    None

    Methods
    -------
    None

    See Also
    --------
    :func:`pandas.array`
        The recommended function for creating a StringArray.
    Series.str
        The string methods are available on Series backed by
        a StringArray.

    Notes
    -----
    StringArray returns a BooleanArray for comparison methods.

    Examples
    --------
    >>> pd.array(['This is', 'some text', None, 'data.'], dtype="string")
    <StringArray>
    ['This is', 'some text', <NA>, 'data.']
    Length: 4, dtype: string

    Unlike arrays instantiated with ``dtype="object"``, ``StringArray``
    will convert the values to strings.

    >>> pd.array(['1', 1], dtype="object")
    <NumpyExtensionArray>
    ['1', 1]
    Length: 2, dtype: object
    >>> pd.array(['1', 1], dtype="string")
    <StringArray>
    ['1', '1']
    Length: 2, dtype: string

    However, instantiating StringArrays directly with non-strings will raise an error.

    For comparison methods, `StringArray` returns a :class:`pandas.BooleanArray`:

    >>> pd.array(["a", None, "c"], dtype="string") == "a"
    <BooleanArray>
    [True, <NA>, False]
    Length: 3, dtype: boolean
    	extensionrJ   r   r;   Fc                   t        |      }t        | 	  ||       t        |t	        |             s| j                          t        j                  | | j                  t        | j                  | j                               y )Ncopyrz   )r'   rc   rW   rT   r_   	_validater   _ndarrayr7   _storager;   )r?   valuesr   re   s      r@   rW   zStringArray.__init__u  sa    v&d+&$t*-NNMMG	
rB   c                   t        | j                        r,t        j                  | j                  d      st	        d      | j                  j
                  dk7  r#t	        d| j                  j
                   d      | j                  j                  dkD  r/t        j                  | j                  j                  d             y	t        j                  | j                         y	)
z*Validate that we only store NA or strings.Tr   z7StringArray requires a sequence of strings or pandas.NAr   z>StringArray requires a sequence of strings or pandas.NA. Got '' dtype instead.ry   KN)	r   r   r   is_string_arrayrR   r}   r   convert_nans_to_NAravelr>   s    r@   r   zStringArray._validate  s    t}}c&9&9$--PT&UVWW==(*MM''((8: 
 ==!""4==#6#6s#;<""4==1rB   c           
         t        |      r| j                  j                  S t        |t              s2t        d| d| j                   dt        |      j                   d      |S )NInvalid value '' for dtype '3'. Value should be a string or missing value, got '
' instead.)r)   r}   rE   rT   r:   r^   r_   rm   r?   values     r@   _validate_scalarzStringArray._validate_scalar  sf    ;::&&&E3'!%djj\ B115e1E1E0FjR  rB   Nr}   r   c               l   |rAt        |t              r|dk(  s,t        |      }t        |t              r|j                  dk(  s4J t               rt        dt        j                        }nt        d      }ddlm	} |j                  }t        ||      r6|j                  }|j                  }t        j                  ||d      }|||<   nBt        j                  |      rt        j                   |      }t        j                  |||	      }| j#                  |       }t%        j&                  |||       |S )
Nr9   rJ   rz   rk   r   )BaseMaskedArrayF)r   convert_na_value)rE   r   )rT   r:   r   r7   rF   r
   rP   rQ   pandas.core.arrays.maskedr   rE   _mask_datar   r   is_pyarrow_arrayr   r   r   rW   )	rn   r   r}   r   r   rE   r   r   r   s	            r@   r   zStringArray._from_sequence  s    *UC0Uh5F 'Ee[1emmx6OOO!##HrvvF#H5=>>g/I]]F,,V$QVWF (F9 ##G, ((7+,,WxdSF ;;s+/?rB   c               *    | j                  |||      S )Nr   )r   )rn   stringsr}   r   s       r@   _from_sequence_of_stringsz%StringArray._from_sequence_of_strings  s     !!'T!BBrB   c                    t        j                  |t              }t        j                  |d d   | |      j                  |d      S )Nr   Fr   )rP   r   r   r<   r=   r   )rn   shaper}   r   s       r@   _emptyzStringArray._empty  s9    %v.MMq	6{!!%e!44rB   c                    ddl }||j                         }| j                  j                         }d|| j	                         <   |j                  ||d      S )z6
        Convert myself into a pyarrow Array.
        r   NT)r_   r   )rI   r9   r   r   r)   r   )r?   r_   r   r   s       r@   __arrow_array__zStringArray.__arrow_array__  sN     	<99;D##%"tyy{xxTtx<<rB   c                f    | j                   j                         }|| j                  j                  fS rD   )r   r   r}   rE   )r?   r   s     r@   _values_for_factorizez!StringArray._values_for_factorize  s)    mm  "DJJ''''rB   c           
     @   t        j                  |      rgt        |      r| j                  j                  }|S t        |t              s2t        d| d| j                   dt        |      j                   d      |S t        |d      }t        |      st        j                  |t              }n@t        |j                  t        | j                              r|S t        j                  |      }t        |      r"t        j                   |d      st        d	      |S )
z-Maybe convert value to be pyarrow compatible.r   r   r   r   T)extract_numpyr   r   z]Invalid value for dtype 'str'. Value should be a string or missing value (or array of those).)r   	is_scalarr)   r}   rE   rT   r:   r^   r_   rm   r'   r   rP   r   r   r   r   r   s     r@   _maybe_convert_setitem_valuez(StringArray._maybe_convert_setitem_value  s    ==E{

++, +  s+%eWM$** F::>u+:N:N9O P (  "%t<E '

57EKKdjj)9: 

5)5z#"5"5eD"IC  rB   c                   | j                  |      }t        | |      }t        j                  |      }t        j                  |      }|r|st	        d      |s|j
                  | j
                  k(  r|j                  }nbt        j                  |      }t        |      }|j                         r2|j                         }| j
                  j                  |t        |      <   t        | 9  ||       y )Nz)setting an array element with a sequence.)r  r(   r   r  rR   r}   r   rP   r   r)   r   r   rE   rc   __setitem__)r?   keyr   
scalar_keyscalar_valuer   re   s         r@   r
  zStringArray.__setitem__  s    11%8!$,]]3'
}}U+lHII{{djj(

5)E{88:!JJLE)-)<)<E$u+&C'rB   c                2    t        j                  | ||       y rD   )r!   _putmaskr?   r   r   s      r@   r  zStringArray._putmask  s     	dE2rB   c                0    t        j                  | ||      S rD   )r!   _wherer  s      r@   r  zStringArray._where  s     $$T477rB   c           	        t        |t              s%t        |t              r3t        |j                        r|j                  | j                  d      }nt        j                  t        j                  |      d      sut        j                  |D cg c]   }t        |t              st        |      s|" c}t              }t        |      s%t        j                  | j                   t"              S | j%                  || j                        }t'        t        j                  |       t        j                  |            S c c}w )NFr   Tr   r   )rT   r   r!   r   r}   r   r   r   rP   r   r   r:   r)   r   r   zerosr   r   r   r   )r?   r   vals      r@   r   zStringArray.isin  s    fo.v~.?6<<3P]]4::E]:F&&rzz&'9$G$*PFSjc.Bd3iSFP  6{88DJJd;;((tzz(BFBJJt$bjj&899 Qs    E2ETc                L   t        |      }|| j                  k(  r|r| j                         S | S t        |t              rX| j
                  j                         }| j                         }d||<   |j                  |j                        }t        ||d      S t        |t              rN| j                         }| j                         }d||<   |j                  |j                        }t        ||d      S t        |t              rt        j                  | ||      S t        j                  |t        j                         rU| j
                  j                         }| j                         }d||<   |j                  |      }t        j"                  ||<   |S t$        |   ||      S )Nr   Fr   0)r   r}   r   rT   r%   r   r)   r   numpy_dtyper$   r#   r"   r   r!   rP   
issubdtypefloatingrQ   rc   )r?   r}   r   r   r   r   re   s         r@   r   zStringArray.astype.  sT   U#DJJyy{"K|,--$$&C99;DCIZZ 1 12F599}-))+C99;DCIZZ 1 12F E::~.!((ud;;]]5"++.--$$&C99;DCIZZ&F66F4LMw~eT**rB   r   )r   keepdimsaxisc               x   | j                   j                  t        j                  u rK|dv rG|dk(  r!t	        j
                  | j                  |      S t	        j                  | j                  |      S |dv r7 t        | |      d	||d|}|r| j                  |g| j                         S |S t        d| d      )
N)r   allr   r   )minmaxargminargmaxsum)r   r  r   zCannot perform reduction 'z' with string dtype )r}   rE   rP   rQ   r   nananyr   nanallgetattrr   r^   )r?   rA   r   r  r  kwargsr   s          r@   _reducezStringArray._reduceO  s     ::"&&(T^-Cu}}}T]]6BB}}T]]6BB<<(WT4(LTLVLF**F84::*FFM4TF:MNOOrB   r   c                  |dk(  rd| d| j                    d}t        |      d}d}| j                  }t        j                  t        j
                  j                  t        j                  j                  d|   }| j                  rt        dt        |            }t        j                  |      r t        |       |      S |r^|dk(  rt        j                  |d	|      }n|j                         }t        j                   |d
d       t        j                   |dd       nVt        j"                  |      }	t        j$                  t'        |      |	z
  d      }| j                   j(                  |dd |d|	 } ||      }
|t        j*                  |
|f      }
n-|+t        j                  || j                   j(                  |
      }
 t        |       |
      }|S )a  
        Return an ExtensionArray performing an accumulation operation.

        The underlying data type might change.

        Parameters
        ----------
        name : str
            Name of the function, supported values are:
            - cummin
            - cummax
            - cumsum
            - cumprod
        skipna : bool, default True
            If True, skip NA values.
        **kwargs
            Additional keyword arguments passed to the accumulation function.
            Currently, there is no supported kwarg.

        Returns
        -------
        array

        Raises
        ------
        NotImplementedError : subclass does not define accumulations
        cumprodzoperation 'z' not supported for dtype 'rl   N)cumsumcummincummaxr   r,   padr   )methodr  backfillr   r   )r}   r^   r   rP   r,  minimum
accumulatemaximum_hasnar   r)   r  r_   wherer   r   pad_or_backfill_inplacer"  r   r   rE   hstack)r?   rA   r   r(  msgtailna_maskndarraynp_funcidx	np_resultr   s               r@   _accumulatezStringArray._accumulatee  s   8 9v%@ANCC.  #'%)--iijj++jj++
 	 ;;2DMBGvvg!tDz'**8# hhwG<G &llnG33$
 33) ii(xxGs 2(C**--Q!$3- G$			9d"34I $***=*=yIIdI&rB   c                    | j                   j                  t        j                  u r"|t        j
                  u rt        j                  S t        |   ||      S rD   )r}   rE   rP   rQ   r<   r=   rc   _wrap_reduction_result)r?   r  r   re   s      r@   rC  z"StringArray._wrap_reduction_result  s?    ::"&&(Vz}}-D66Mw-dF;;rB   c                    t        j                  d|       t        j                  | j	                         | j                         |      }| j                  ||      S Nr$  )r   r   r   )nvvalidate_minr    r  r   r)   rC  r?   r  r   r(  r   s        r@   r  zStringArray.min  H    
F#"&&==?V
 **488rB   c                    t        j                  d|       t        j                  | j	                         | j                         |      }| j                  ||      S rE  )rF  validate_maxr    r   r   r)   rC  rH  s        r@   r   zStringArray.max  rI  rB   )r  r   	min_countc                   t        j                  d|       t        j                  | j                  | j                         |      }| j                  ||      S rE  )rF  validate_sumr    r#  r   r)   rC  )r?   r  r   rL  r(  r   s         r@   r#  zStringArray.sum  sH     	F#"&&==tyy{6
 **488rB   c                D   ddl m}  || j                  |      j                  d      } || j                  d|      }|j                  j                  | j
                        |_        | j
                  j                  t        j                  u r|j                  d      }|S )Nr   )value_counts_internal)dropnaInt64F)sortrQ  )	pandas.core.algorithmsrP  r   r   indexr}   rE   r<   r=   )r?   rQ  value_countsr   s       r@   rV  zStringArray.value_counts  su    PdmmF;BB7Kdmm%G||**4::6::*--/]]7+FrB   c                z    | j                   j                  }|r"|t        j                  | j                         z   S |S rD   )r   nbytesr   memory_usage_of_objects)r?   deepr   s      r@   memory_usagezStringArray.memory_usage  s3    %%C77FFFrB   c                V    | j                   rt        d      t        |   |||      S )NzOsearchsorted requires array to be sorted, which is impossible with NAs present.)r   sidesorter)r6  rR   rc   searchsorted)r?   r   r]  r^  re   s       r@   r_  zStringArray.searchsorted  s7     ;;$  w#%d6#JJrB   c                   ddl m} t        |t              r|j                  }t        |       t        |      z  }| }t        j                  |      s_t        |      t        |       k7  r#t        dt        |        dt        |             t        |      st        j                  |      }||   }|j                  t        j                  v rdt        j                   | j                  d      }| j"                  j$                  ||<    || j                  |   |      ||<   | j'                  |      S t        j(                  t        | j                        d      } || j                  |   |      ||<    |||      }| j"                  j$                  t        j*                  u rU|t,        j.                  k(  r!|j1                  t        j2                  d	      S |j1                  t        j2                  d
	      S |S )Nr   r   z"Lengths of operands do not match: z != r   r   r   Trj   F)r   r   rT   rs   r   r)   r   r  r   rR   r   rP   r   rm   r   ARITHMETIC_BINOPS
empty_liker}   rE   _from_backing_datar  rQ   operatorner   bool_)r?   r`   opr   r   validr   res_arrs           r@   _cmp_methodzStringArray._cmp_method  s   .e[)NNEDzDK'}}U#5zSY& 8T4E
|T 
 !'

5)%LE;;#///]]4==AF::..F4Lt}}U3U;F5M**622 XXc$--0?Ft}}U3U;F5M"640Gzz""bff,$"++BHHt+DD"++BHHu+EENrB   r   )r   r   r   r   )r}   r   r   r   )r   rs   rD   )r   z,tuple[np.ndarray, libmissing.NAType | float]r   r   )r   r   r   r   )r   r   r   r2   )r   r+   r   r   )T)r   r   )rA   r:   r   r   r  r   r  AxisInt | None)rA   r:   r   r   r   rs   )r  rl  r   r   )NT)r   r   r   r1   )r  rl  r   r   rL  r   r   r1   )rQ  r   r   r5   )rZ  r   r   r   )leftN)r   z$NumpyValueArrayLike | ExtensionArrayr]  zLiteral['left', 'right']r^  zNumpySorter | Noner   znpt.NDArray[np.intp] | np.intp)'rm   r   r   r   _typr   r<   r=   r;   r   rW   r   r   r   r   r   r   r  r  r  r
  r  r  r   r   r)  rA  rC  r  r   r#  rV  r[  r   r!   r_  rj  _arith_methodr   r   s   @r@   rs   rs     s   Nb DH+5==I(8

2 	 >BQV "  " H /3%C ,C;?C C
 5 5
=(
8(*38:$+J  PP 	P
 P P, 8< Pd<99  $9 9 	9
 9 
9	 		$	$% *0%)	K3K 'K #	K
 
(K &K$L  MrB   rs   c                  `     e Zd ZdZej
                  ZddZeddd	 	 	 	 	 d fd       Z	 xZ
S )	rt   rJ   c                    t        | j                        r,t        j                  | j                  d      st	        d      | j                  j
                  dk7  r#t	        d| j                  j
                   d      y)z+Validate that we only store NaN or strings.Tr   z?StringArrayNumpySemantics requires a sequence of strings or NaNr   zFStringArrayNumpySemantics requires a sequence of strings or NaN. Got 'r   N)r   r   r   r   rR   r}   r>   s    r@   r   z#StringArrayNumpySemantics._validate%  su    t}}c&9&9$--PT&UQ  ==(*MM''((8:  +rB   NFr   c               b    |t        dt        j                        }t        |   |||      S )NrJ   rz   r   )r7   rP   rQ   rc   r   )rn   r   r}   r   re   s       r@   r   z(StringArrayNumpySemantics._from_sequence2  s1     =266BEw%gU%FFrB   rk  )r}   r   r   r   r   r2   )rm   r   r   r   rP   rQ   r;   r   r   r   r   r   s   @r@   rt   rt   !  sL    HI
 /3%G ,G;?G	G GrB   rt   )X
__future__r   	functoolsr   rd  typingr   r   r   r   rM   numpyrP   pandas._configr	   r
   pandas._libsr   r   r<   pandas._libs.arraysr   pandas._libs.libr   pandas.compatr   r   pandas.compat.numpyr   rF  pandas.util._decoratorsr   pandas.util._exceptionsr   pandas.core.dtypes.baser   r   r   pandas.core.dtypes.commonr   r   r   r   r   r   pandas.corer   r   rT  r   pandas.core.array_algosr    pandas.core.arrays.baser!   pandas.core.arrays.floatingr"   r#   pandas.core.arrays.integerr$   r%   pandas.core.arrays.numpy_r&   pandas.core.constructionr'   pandas.core.indexersr(   pandas.core.missingr)   pandas.io.formatsr*   rI   pandas._typingr+   r,   r-   r.   r/   r0   r1   r2   r3   r4   pandasr5   r7   r   rs   rt   r$  rB   r@   <module>r     s    "     
 . 0 / ' 4 
  
 ( 5 2 : 2 4 $ &    X ' X  X vd)n d)R /#6  DG GrB   