403Webshell
Server IP : 209.209.40.120  /  Your IP : 216.73.217.112
Web Server : Microsoft-IIS/10.0
System : Windows NT NEWWWW 10.0 build 17763 (Windows Server 2019) i586
User : NEWWWW$ ( 0)
PHP Version : 8.3.30
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  C:/Python312/Lib/site-packages/pandas/core/arrays/sparse/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : C:/Python312/Lib/site-packages/pandas/core/arrays/sparse/__pycache__/array.cpython-312.pyc
�

-	�g����N�dZddlmZddlmZddlZddlZddlmZm	Z	m
Z
mZmZm
Z
ddlZddlZddlmZddlmcmZddlmZmZmZddlmZdd	lmZdd
lm Z ddl!m"Z"ddl#m$Z$dd
l%m&Z&m'Z'ddl(m)Z)ddl*m+Z+m,Z,m-Z-ddl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5ddl6m7Z7m8Z8ddl9m:Z:m;Z;ddl<m=Z=m>Z>m?Z?ddl@mAZAddlBmCcmDZEddlFmGZGddlHmIZIddlJmKZKddlLmCcmMZNddlOmPZPmQZQmRZRddlSmTZTmUZUddlVmWZWddlXmYZYerYddlZm[Z[ddl\m]Z]Gd�de]�Z^e^j�Z_dd l`maZadd!lbmcZcmdZded"Zedd#lbmfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZqdd$lrmsZsnete_�Z^d%d&iZud/d'�Zv										d0d(�Zw	d1					d2d)�ZxGd*�d&eGeKeI�Zy			d3					d4d+�Zze
d5d,��Z{e
d6d-��Z{d7d.�Z{y)8z
SparseArray data structure
�)�annotations)�abcN)�
TYPE_CHECKING�Any�Callable�Literal�cast�overload)�lib)�
BlockIndex�IntIndex�SparseIndex)�NaT)�function)�PerformanceWarning)�doc)�find_stack_level)�validate_bool_kwarg�validate_insert_loc)�astype_array)�"construct_1d_arraylike_from_scalar�find_common_type�maybe_box_datetimelike)�
is_bool_dtype�
is_integer�is_list_like�is_object_dtype�	is_scalar�is_string_dtype�pandas_dtype)�DatetimeTZDtype�SparseDtype)�ABCIndex�	ABCSeries)�isna�na_value_for_dtype�notna)�	arraylike)�OpsMixin)�ExtensionArray)�PandasObject)�ensure_wrapped_if_datetimelike�
extract_array�sanitize_array)�check_array_indexer�unpack_tuple_and_ellipses)�check_below_min_count)�printing)�Sequence)�Enumc��eZdZdZy)�ellipsisz...N)�__name__�
__module__�__qualname__�Ellipsis���AC:\Python312\Lib\site-packages\pandas/core/arrays/sparse/array.pyr6r6[s���r<r6)�spmatrix)�
FillnaOptions�NumpySorter)�integer�block)�	ArrayLike�	AstypeArg�Axis�AxisInt�Dtype�NpDtype�PositionalIndexer�Scalar�
ScalarIndexer�Self�SequenceIndexer�npt)�Series�klass�SparseArrayc���	tj|j|jj��S#t
$r"tj|j�cYSwxYw)a]
    Create a 0-dim ndarray containing the fill value

    Parameters
    ----------
    arr : SparseArray

    Returns
    -------
    fill_value : ndarray
        0-dim ndarray with just the fill value.

    Notes
    -----
    coerce fill_value to arr dtype if possible
    int64 SparseArray can have NaN as fill_value if there is no missing
    ��dtype)�np�asarray�
fill_valuerT�subtype�
ValueError)�arrs r=�	_get_fillr[�sH��$*��z�z�#�.�.��	�	�0A�0A�B�B���*��z�z�#�.�.�)�)�*�s�47�(A"�!A"c	��|jd�r|dd}|jj}|jj}||k7rlt||g�}t	||j
�}t	||j
�}|j
|d��}|j
|d��}|j}n|}d}|jjdk(s|jjdk(r�tjd�	�5||j�|j��}	|t|�t|��}
ddd�|jjdk(r|j}�n�|j}�n�|jj|j�retjd�	�5||j|j�}	|t|�t|��}
ddd�|j}�nX|dd
k(r	||}}|dd}|dvrd|d
k(r_d|�d�}|jjtj �}
|jjtj �}t"}n d|�d|��}|j}
|j}|dvrS|dk(j%�r@|jj&dvr(d|�d�}|
j
d�}
|j
d�}t)t*|�}tjd�	�5||
|j|j
||j|j
�\}	}}
ddd�|dk(r,t-|	d
d|��t-||	d||
d|��fS|�	j}t-|	
|��S#1swY��pxYw#1swY���xYw#1swY�rxYw)a4
    Perform a binary operation between two arrays.

    Parameters
    ----------
    left : Union[SparseArray, ndarray]
    right : Union[SparseArray, ndarray]
    op : Callable
        The binary operation to perform
    name str
        Name of the callable.

    Returns
    -------
    SparseArray
    �__����F��copyNr�ignore��all�r�)�and�or�xor�bool�sparse_�_uint8�_)�floordiv�mod�iu�_float64�float64�divmodrS)�
startswithrTrXrr"rW�astype�sp_index�ngapsrU�errstate�to_denser[�equals�	sp_values�view�uint8rj�any�kind�getattr�splib�_wrap_result)�left�right�op�name�ltype�rtyperXrT�result_dtype�result�fill�index�opname�left_sp_values�right_sp_values�	sparse_ops                r=�_sparse_array_opr��sl��&���t���A�b�z��
�J�J���E��K�K���E���~�"�E�5�>�2���G�T�_�_�5���G�U�%5�%5�6���{�{�5�u�{�-�����U���/���
�
�����L��}�}���a��5�>�>�#7�#7�1�#<�
�[�[�X�
&�	9���
�
�����)9�:�F��i��o�y��'7�8�D�	9��=�=���!�#��M�M�E��N�N�E�	
���	�	�e�n�n�	-�
�[�[�X�
&�	9��������8�F��i��o�y��'7�8�D�	9��
�
����7�c�>���%�D����8�D��'�'�E�V�O��t�f�F�+�F�!�^�^�0�0����:�N�#�o�o�2�2�2�8�8�<�O��L��t�f�A�e�W�-�F�!�^�^�N�#�o�o�O�
�'�'��!�� � �"��
�
���4�'��t�f�H�-�F�+�2�2�9�=�N�-�4�4�Y�?�O��E�6�*�	�
�[�[�X�
&�	�"+���
�
��������� � �
#��F�E�4�	��x��

��v�a�y�%��a���M���v�a�y�%��a���M�
�	
�
���|�|����f�e�T��F�F�	9�	9��	9�	9��@	�	�s%�AN/�99N<�:O	�/N9�<O�	Oc��|jd�r|dd}|dvrt}tj|�}t	|�rt|�}t||||��S)z.
    wrap op result to have correct dtype
    r]r^r_)�eq�ne�lt�gt�le�ge)�sparse_indexrWrT)rtrjr�item_from_zerodimrrQ)r��datar�rWrTs     r=r�r�sa�����t���A�b�z���3�3����&�&�z�2�J��U���*�%�
���<�J�e��r<c���eZdZUdZdZejeg�zZded<ded<ded<					dU							dVd�Z	e
								dWd��Ze
dXd
��Z	dY					dZd�Z
d[d�Ze
d	d
d�d\d��Ze
d��Zed]d��Zed^d��Zed_d��Zed��Zej,d[d��Zed`d��Zed^d��Zdad�Zedbd��Zdbd�Zedad��Zedcd��Zedad��Zddd �Zd	d	d!d"�									de�fd#�Z 				df							dg�fd$�
Z!dhdid%�Z"d&�Z#e$e%jL�	dj			dkd'��Z&ddd(�Z'd)�Z(	dl			dmd*�Z)dldnd+�Z*e+dod,��Z,e+				dpd-��Z,				dqd.�Z,d/�Z-d
d	d0�drd1�Z.dsd^d2�Z/ddd3�Z0		dt							dud4�Z1ddd5�Z2e
dvd6��Z3dwdxd7�Z4dsddd8�Z5d^d9�Z6d:�Z7d[d;�Z8dyd<�Z9d!d
d=�					dzd>�Z:dsd?�Z;d{d|d@�Z<			d}							d~dA�Z=d{ddB�Z>d{d�dC�Z?d	d!dD�d�dE�Z@d	d!dD�d�dF�ZAd�dG�ZBd�dH�ZCdld�dI�ZDdld�dJ�ZEeFj�eHj�fZJd�dK�ZKdL�ZLd�dM�ZMeMZNd�dN�ZOd�dO�ZPd�dP�ZQd�dQ�ZRd�dR�ZSd�dS�ZTd�d�dT�ZU�xZVS)�rQa�
    An ExtensionArray for storing sparse data.

    Parameters
    ----------
    data : array-like or scalar
        A dense array of values to store in the SparseArray. This may contain
        `fill_value`.
    sparse_index : SparseIndex, optional
    fill_value : scalar, optional
        Elements in data that are ``fill_value`` are not stored in the
        SparseArray. For memory savings, this should be the most common value
        in `data`. By default, `fill_value` depends on the dtype of `data`:

        =========== ==========
        data.dtype  na_value
        =========== ==========
        float       ``np.nan``
        int         ``0``
        bool        False
        datetime64  ``pd.NaT``
        timedelta64 ``pd.NaT``
        =========== ==========

        The fill value is potentially specified in three ways. In order of
        precedence, these are

        1. The `fill_value` argument
        2. ``dtype.fill_value`` if `fill_value` is None and `dtype` is
           a ``SparseDtype``
        3. ``data.dtype.fill_value`` if `fill_value` is None and `dtype`
           is not a ``SparseDtype`` and `data` is a ``SparseArray``.

    kind : str
        Can be 'integer' or 'block', default is 'integer'.
        The type of storage for sparse locations.

        * 'block': Stores a `block` and `block_length` for each
          contiguous *span* of sparse values. This is best when
          sparse data tends to be clumped together, with large
          regions of ``fill-value`` values between sparse values.
        * 'integer': uses an integer to store the location of
          each sparse value.

    dtype : np.dtype or SparseDtype, optional
        The dtype to use for the SparseArray. For numpy dtypes, this
        determines the dtype of ``self.sp_values``. For SparseDtype,
        this determines ``self.sp_values`` and ``self.fill_value``.
    copy : bool, default False
        Whether to explicitly copy the incoming `data` array.

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

    Methods
    -------
    None

    Examples
    --------
    >>> from pandas.arrays import SparseArray
    >>> arr = SparseArray([0, 0, 1, 2])
    >>> arr
    [0, 0, 1, 2]
    Fill: 0
    IntIndex
    Indices: array([2, 3], dtype=int32)
    �sparse_arrayr�
_sparse_index�
np.ndarray�_sparse_valuesr"�_dtypeNFc�:�|�t|t�r|j}t|t|��r6|�|j}|�|j}|�|j
}|j}t|t�r	tj|�}t|t�r|�|j}|j}t|�rftjdt|�j�d�t t#���|�d}n|j$}t'||d��}|j
}|�t|�}|�t)j*g|��}	t-|d��}|r|j7�}|�.|�|j
n|}|�t(j8}nt;|�}t|t|��r1|�/|j<}t)j4|j|��}	�n|��t?|d��}t|t(j@�s�t|j
tB�rgtjd	|j
�d
�tDt#���t)j4|d��}|tFurt)jHdd
�}t)j4|�}tK||||��\}	}}nGt)j4||��}	tM|	�|jNk7rtQdt|	��d���||_|	|_)t|	j
|�|_*y#t$rt|�}Y���wxYw#t.$rK|�Dt)j
t0�}t)j2t)j4||���}n�Y��:wxYw)Nz
Constructing z\ with scalar data is deprecated and will raise in a future version. Pass a sequence instead.��
stacklevelrfrS)r�T)�
extract_numpyzCreating SparseArray from z^ data loses timezone information. Cast to object before sparse to retain timezone information.zdatetime64[ns]r�ns)rrWrTzNon array-like type z' must have the same length as the index)+�
isinstancer"rW�typervrTr{�str�construct_from_string�	TypeErrorr rXr�warnings�warnr7�
FutureWarningr�lengthrrU�arrayr.rY�object�
atleast_1drVra�nanr&r�r-�ndarrayr!�UserWarningr�
datetime64�_make_sparse�len�npoints�AssertionErrorr�r�)
�selfr�r�rWrrTrar��fill_value_dtype�
sparse_valuess
          r=�__init__zSparseArray.__init__lsL����*�U�K�"@��)�)�J��d�D��J�'��#�#�}�}���!�!�_�_�
��}��
�
���>�>�D��e�S�!�
,�#�9�9�%�@���e�[�)��!�"�-�-�
��M�M�E��T�?��M�M���T�
� 3� 3�4�5O�O��+�-�	
��#���&�-�-��5�d�G�4�P�D��J�J�E��� ��'�E��<��8�8�B�e�,�D�		�!�$�d�3�D���9�9�;�D���-2�]�t�z�z����'��V�V�
�/�0@�A�
��d�D��J�'�L�,@��-�-�L��J�J����e��M��
!� ��T�:�D��d�B�J�J�/��d�j�j�/�:��M�M�4�T�Z�Z�L�AA�A�$�#3�#5���:�:�d�2B�C�D�!�S�(�%'�]�]�5�$�%?�
��z�z�$�'��6B���%��7�3�M�<���J�J�t�5�9�M��=�!�\�%9�%9�9�$�*�4�
�+>�*?�@8�8���*���+���!�-�"5�"5�z�B����M�
,�$�U�+��
,��N�	��}�����(���}�}�R�Z�Z��E�%B�C����	�s%�;L+�
M�+M�M�AN�Nc�Z�tj|�}||_||_||_|S�N)r��__new__r�r�r�)�clsr�r�rT�news     r=�_simple_newzSparseArray._simple_new�s.���n�n�S�!��(���)�����
��
r<c��|j\}}|dk7rtd|�d���|j�}|j�|j}|j
}t
jd|j��j�}t|j|�}t||�}|j|||�S)a�
        Create a SparseArray from a scipy.sparse matrix.

        Parameters
        ----------
        data : scipy.sparse.sp_matrix
            This should be a SciPy sparse matrix where the size
            of the second dimension is 1. In other words, a
            sparse matrix with a single column.

        Returns
        -------
        SparseArray

        Examples
        --------
        >>> import scipy.sparse
        >>> mat = scipy.sparse.coo_matrix((4, 1))
        >>> pd.arrays.SparseArray.from_spmatrix(mat)
        [0.0, 0.0, 0.0, 0.0]
        Fill: 0.0
        IntIndex
        Indices: array([], dtype=int32)
        rfz''data' must have a single column, not '�'rrS)
�shaperY�tocsc�sort_indicesr��indicesrUr�rT�itemr"r
r�)	r�r�r��ncolrZ�idx�zerorTr�s	         r=�
from_spmatrixzSparseArray.from_spmatrix�s���4�z�z�����1�9��F�t�f�A�N�O�O��z�z�|�������i�i���l�l���x�x�����+�0�0�2���C�I�I�t�,�����%�����s�E�5�1�1r<c��|j}|jjdk(r|jS|�t|jjj
dk(r|turtjd�}	tj|jjt|��}tj|j||��}|j||jj<|S#t$r	t}Y�XwxYw)Nr�MrrS)rWrvrwr{rTrrrUr��result_typer�r�r��fullr�r�)r�rTrarW�outs     r=�	__array__zSparseArray.__array__*s����_�_�
��=�=���!�#��>�>�!��=��~�~�#�#�(�(�C�/���$�!#���u�!5�J�
����t�~�~�';�';�T�*�=M�N���g�g�d�j�j�*�E�:��%)�^�^��D�M�M�!�!�"��
���
���
�s�53C/�/D�Dc��d}t|��)Nz8SparseArray does not support item assignment via setitem)r�)r��key�value�msgs    r=�__setitem__zSparseArray.__setitem__Es��I����n�r<�rTrac��|||��S�NrSr;)r��scalarsrTras    r=�_from_sequencezSparseArray._from_sequenceLs���7�%�(�(r<c�*�|||j��Sr�rS)r��values�originals   r=�_from_factorizedzSparseArray._from_factorizedPs���6����0�0r<c��|jS)zX
        The SparseIndex containing the location of non- ``fill_value`` points.
        )r��r�s r=rvzSparseArray.sp_indexWs��
�!�!�!r<c��|jS)a
        An ndarray containing the non- ``fill_value`` values.

        Examples
        --------
        >>> from pandas.arrays import SparseArray
        >>> s = SparseArray([0, 0, 1, 0, 2], fill_value=0)
        >>> s.sp_values
        array([1, 2])
        )r�r�s r=r{zSparseArray.sp_values^s���"�"�"r<c��|jSr�)r�r�s r=rTzSparseArray.dtypels���{�{�r<c�.�|jjS)a�
        Elements in `data` that are `fill_value` are not stored.

        For memory savings, this should be the most common value in the array.

        Examples
        --------
        >>> ser = pd.Series([0, 0, 2, 2, 2], dtype="Sparse[int]")
        >>> ser.sparse.fill_value
        0
        >>> spa_dtype = pd.SparseDtype(dtype=np.int32, fill_value=2)
        >>> ser = pd.Series([0, 0, 2, 2, 2], dtype=spa_dtype)
        >>> ser.sparse.fill_value
        2
        )rTrWr�s r=rWzSparseArray.fill_valueps��"�z�z�$�$�$r<c�N�t|jj|�|_yr�)r"rTrXr�)r�r�s  r=rWzSparseArray.fill_value�s��!�$�*�*�"4�"4�e�<��r<c�:�t|jt�ryy)zW
        The kind of sparse index for this array. One of {'integer', 'block'}.
        rArB)r�rvr
r�s r=rzSparseArray.kind�s��
�d�m�m�X�.��r<c�:�|j}t|�}||Sr�)r{r')r��sp_vals�masks   r=�_valid_sp_valueszSparseArray._valid_sp_values�s���.�.���W�~���t�}�r<c�.�|jjSr�)rvr�r�s r=�__len__zSparseArray.__len__�s���}�}�#�#�#r<c�.�|jjSr�)r��_is_na_fill_valuer�s r=�_null_fill_valuezSparseArray._null_fill_value�s���{�{�,�,�,r<c�N�|jrt|�S|j|k(Sr�)r�r%rW)r�rWs  r=�_fill_value_matcheszSparseArray._fill_value_matches�s%��� � ��
�#�#��?�?�j�0�0r<c�\�|jj|jjzSr�)r{�nbytesrvr�s r=r�zSparseArray.nbytes�s!���~�~�$�$�t�}�}�';�';�;�;r<c�\�|jj|jjzS)z�
        The percent of non- ``fill_value`` points, as decimal.

        Examples
        --------
        >>> from pandas.arrays import SparseArray
        >>> s = SparseArray([0, 0, 1, 1, 1], fill_value=0)
        >>> s.density
        0.6
        )rvr�r�r�s r=�densityzSparseArray.density�s#���}�}�$�$�t�}�}�';�';�;�;r<c�.�|jjS)z�
        The number of non- ``fill_value`` points.

        Examples
        --------
        >>> from pandas.arrays import SparseArray
        >>> s = SparseArray([0, 0, 1, 1, 1], fill_value=0)
        >>> s.npoints
        3
        )rvr�r�s r=r�zSparseArray.npoints�s���}�}�$�$�$r<c��tt|j�}|jr9t|�j	t|j�|j|�Stjt|�dtj��}t|j�||jj<t|�|d|��S)NFrS�rWrT)
r"rjr�r�r�r%r{rvrUr�r��bool_r�)r�rTr�s   r=r%zSparseArray.isna�s����D�$�"7�"7�8��� � ���:�)�)�$�t�~�~�*>��
�
�u�U�U��w�w�s�4�y�%�r�x�x�8��&*�4�>�>�&:��T�]�]�
"�
"�#��t�D�z�$�5��>�>r<T)�limit�
limit_arearac�*��t�|�||||��S)N)�methodr�r�ra)�super�_pad_or_backfill)r�rr�r�ra�	__class__s     �r=rzSparseArray._pad_or_backfill�s%����w�'���:�D�(�
�	
r<c�f��|�|�|�
|�td��|�t�|�	||��Stjt|j�||j�}|jr"t|jj|��}n|j}|j||j|�S)a�
        Fill missing values with `value`.

        Parameters
        ----------
        value : scalar, optional
        method : str, optional

            .. warning::

               Using 'method' will result in high memory use,
               as all `fill_value` methods will be converted to
               an in-memory ndarray

        limit : int, optional

        copy: bool, default True
            Ignored for SparseArray.

        Returns
        -------
        SparseArray

        Notes
        -----
        When `value` is specified, the result's ``fill_value`` depends on
        ``self.fill_value``. The goal is to maintain low-memory use.

        If ``self.fill_value`` is NA, the result dtype will be
        ``SparseDtype(self.dtype, fill_value=value)``. This will preserve
        amount of memory used before and after filling.

        When ``self.fill_value`` is not NA, the result dtype will be
        ``self.dtype``. Again, this preserves the amount of memory used.
        z(Must specify one of 'method' or 'value'.)rr��rW)
rYr�fillnarU�wherer%r{r�r"rTrXr�r�)r�r�rr�ra�
new_values�	new_dtypers       �r=rzSparseArray.fillna�s����T
�N�u�}���5�#4��G�H�H����7�>��u�>�=�=����$�t�~�~�"6��t�~�~�N�J��$�$�'��
�
�(:�(:�u�M�	� �J�J�	����
�D�,>�,>�	�J�Jr<c	�6�t|�r|dk(r|j�St|�r|jj}tj||jj�}||jjk7r&|jt||j��}n|}|j|gtt|�t|��z|j��}|dkDr	|}|d|}n|t|�d}|}|j||g�S)NrrS)r�rar%rT�na_valuerUr�rXrur"rWr��min�abs�_concat_same_type)r��periodsrWrXrZ�empty�a�bs        r=�shiftzSparseArray.shifts����4�y�G�q�L��9�9�;���
�����,�,�J��.�.��T�Z�Z�-?�-?�@���d�j�j�(�(�(��+�+�k�'�4�?�?�C�D�C��C��#�#�
�L�3�s�7�|�S��Y�7�7�s�y�y�$�
���Q�;��A��I�g�X��A��C��L�N�#�A��A��$�$�a��V�,�,r<c�:�t|�dk(s"|jjt|�k(ry|jj}t|�r|ddkDrytj
t	j|�df}||dkDj�dzS)zh
        Get the location of the first fill value.

        Returns
        -------
        int
        r���r^rf)r�rvr�r�rU�r_�diff�argmax)r�r�rs   r=�_first_fill_value_locz!SparseArray._first_fill_value_loc6s����t�9��>�T�]�]�2�2�c�$�i�?���-�-�'�'���7�|�w�q�z�A�~��
�u�u�R�W�W�W�%�q�(�)����q��(�(�*�+�a�/�/r<c��tj|�}tj|j��}tj|||��S)N)�keepr�)rUrVr%�algos�
duplicated)r�rr�r�s    r=rzSparseArray.duplicatedKs;�����D�!���z�z�$�)�)�+�&������T��=�=r<c��tj|j�}t|j�t|�k7r\|j	�}ttj|jd|��}tj|||j�}t|�j||j��Sr�)r�uniquer{r�rrU�insertrWr�r�rT)r��uniques�fill_loc�
insert_locs    r=r zSparseArray.uniqueSs����,�,�t�~�~�.���t�~�~��#�d�)�+��1�1�3�H��U�\�\�$�.�.��(�*C�D�E�J��i�i���T�_�_�E�G��D�z�(�(���
�
�(�C�Cr<c�D�tj|�|jfSr�)rUrVrWr�s r=�_values_for_factorizez!SparseArray._values_for_factorizeas���z�z�$�����0�0r<c��tjtj|�|��\}}t	||j
��}||fS)N)�use_na_sentinelrS)r�	factorizerUrVrQrT)r�r(�codesr"�
uniques_sps     r=r)zSparseArray.factorizeesA������J�J�t��o�
���w�!���
�
�;�
��j� � r<c���ddlm}m}tj|j
|��\}}}|jj}|dkDr�|jr|s||jrt|�n||jk(}|j�r||xx|z
cc<n8tj|d|j�}tj|d|�}t|t�s	||�}	n|}	|||	d��S)a
        Returns a Series containing counts of unique values.

        Parameters
        ----------
        dropna : bool, default True
            Don't include counts of NaN, even if NaN is in sp_values.

        Returns
        -------
        counts : Series
        r)�IndexrO)�dropnaF)r�ra)�pandasr-rOr�value_counts_arrayliker{rvrwr�r%rWr~rUr!r�r#)
r�r.r-rO�keys�countsrm�fcountsr�r�s
          r=�value_countszSparseArray.value_countsts���	
�
 �6�6�t�~�~�f�U���f�a��-�-�%�%���Q�;�� 5� 5�V�!%�!6�!6�4��:�D�D�O�O�<S�D��x�x�z��t���'���y�y��q�$�/�/�:�����6�1�g�6���$��)��$�K�E��E��f�E��6�6r<c��yr�r;�r�r�s  r=�__getitem__zSparseArray.__getitem__�s��r<c��yr�r;r6s  r=r7zSparseArray.__getitem__�s��
	r<c���t|t�rt|�}|turt	d��t|�r|j
|�St|t�r|j�|}�nft|t��r~|j�|jdk(�r |j�dn|j}|dkr|t|�z
}|j�t|�n|j}|dkr|t|�z
}|jj}tj ||k\||kz�}|j"|}||j%�}|dkDr||z}tt't|��|�}	t)|	||j*�}
t-|�j/||
|j0�Stj2t|�tj4��|}|j7|�St9|�st;d��t|t<��r	t?|�r�tA|jB�r2|j7|jj|j"�S|jBs%|j7|jj�St|�}tjD|dtjF��}d||jj<|j7tj2|�|�StjH|�}tK||�}tMjN|�rZtQtjR|�}|j7tj2t|�tj4��|�StU|d�r|j7|�St	d	|�d
���t-|�||j*��S)NzCannot slice with EllipsisrfrrSzuonly integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indicesTFr�zCannot slice with 'r��r)+r��tupler0r:rYr�_get_val_atry�slice�step�startr��stoprvr�rU�flatnonzeror{ra�range�make_sparse_indexrr�r�rT�arange�int32�taker�
IndexErrorrQrr%rWr�r�rVr/�com�is_bool_indexerr	r��hasattr)
r�r��
data_slicer?�endr��	keep_indsr�rv�new_len�new_sp_index�nr�s
             r=r7zSparseArray.__getitem__�s���c�5�!�+�C�0�C��h�� �!=�>�>��c�?��#�#�C�(�(�
��U�
#������-�J�
��U�
#��x�x��3�8�8�q�=� �Y�Y�.��C�I�I���1�9��S��Y�&�E�#&�8�8�#3�c�$�i�������7��3�t�9�$�C��-�-�/�/���N�N�G�u�,<��3��+O�P�	��.�.��3��"�9�-�2�2�4���1�9���%�H��e�C��I�.�s�3�4��0��(�D�I�I�N���D�z�-�-�g�|�T�Z�Z�P�P��)�)�C��I�R�X�X�>�s�C���y�y��)�)��c�"��L��
��#�{�+�
!��%��C�N�N�+�#�y�y����)=�)=�c�m�m�)L�M�M��>�>�#�y�y����)=�)=�>�>��D�	�A��7�7�1�d�"�(�(�;�D�16�D����-�-�.��9�9�R�Y�Y�q�\�$�%7�8�8��*�*�S�/�C�%�d�C�0�C��"�"�3�'��2�:�:�s�+���y�y����3�s�8�2�8�8�!D�S�!I�J�J���i�(��y�y��~�%� �#6�s�e�1�!=�>�>��t�D�z�*�4�9�9�5�5r<c���t|t|��}|jj|�}|dk(r|jS|j
|}t
||j
j�}|S)Nr)rr�rv�lookuprWr{rrT)r��loc�sp_loc�vals    r=r<zSparseArray._get_val_ats`��!�#�s�4�y�1�����%�%�c�*���R�<��?�?�"��.�.��(�C�(��d�n�n�.B�.B�C�C��Jr<)�
allow_fillrWc��t|�rtd|�d���tj|tj��}d}|j
dk(r$tjgd��}|j}n'|r|j||��}n|j|�St|�||j|j|��S)Nz*'indices' must be an array, not a scalar 'z'.rSrr�r)rWrrT)
rrYrUrVrE�sizer�rT�_take_with_fill�_take_without_fillr�rWr)r�r�rVrWrTr�s      r=rFzSparseArray.takes����W���I�'��RT�U�V�V��*�*�W�B�H�H�5�����<�<�1���X�X�b��1�F��J�J�E�
��)�)�'�j�)�I�F��*�*�7�3�3��t�D�z��t���T�Y�Y�e�
�	
r<c��|�|jj}|j�dkrtd��|j	�t|�k\rt
d��t|�dk(rq|dk(j�rStj|jt|��}tj||��}|j|�|St
d��|jj|�}|dk(}|dk(|z}|jj dk(rR|j�rBtj"|j$|j&|jj(��}|S|jj dk(rftj|jj(t|��}tj"|j$||��}|j&||<|S|jj+|�}||dk}	||dk}
|j}|	j-�rItj|t|j&��}|j/|�}|j&||<|
j-�r5tj|t|��}|j/|�}|||<|S)NrzKInvalid value in 'indices'. Must be between -1 and the length of the array.�!out of bounds value in 'indices'.rrS�.cannot do a non-empty take from an empty axes.r�)rTrr
rY�maxr�rGrdrUr�r{r��
empty_liker�rv�lookup_arrayr�r�r�rWrXrFr~ru)r�r�rWrT�taken�
sp_indexer�new_fill_indices�old_fill_indicesr��m0�m1r�s            r=rYzSparseArray._take_with_fill%sX�������,�,�J��;�;�=�2���/��
�
�;�;�=�C��I�%��@�A�A��t�9��>��2�
�"�"�$����t�~�~�t�J�7G�H���
�
�g�U�;���
�
�:�&��� �!Q�R�R�
�]�]�/�/��8�
�"�b�=��&�"�,�1A�0A�A���=�=� � �A�%�*:�*>�*>�*@��G�G�� � �T�_�_�D�J�J�DV�DV��E�@��9�]�]�
"�
"�a�
'��^�^�D�J�J�$6�$6��Z�8H�I�F��G�G�J�,�,��6�R�E�&*�o�o�E�"�#�0��-�N�N�'�'�
�3�E��,�-��1�B��,�-��1�B��+�+�K��v�v�x� �n�n�[�$�t���:O�P�����[�1��*.�/�/��&�'��v�v�x� �n�n�[�$�z�:J�K�����[�1��*4��&�'��r<c�\�|dk}t|�}|j�|k\s|j�|kr|dk(rtd��td��|j	�r|j�}||xx|z
cc<|jj|�}|dk7}|j||}tj|�jtjd��}tt|�||j��}t|�j!|||j"��S)	Nrr]r\rFr`r:rS)r�r^r
rGr~rarvr`r{rUrArurErCrr�r�rT)	r�r��to_shiftrPrb�
value_mask�
new_sp_values�
value_indicesrOs	         r=rZzSparseArray._take_without_fillgs����Q�;����I���K�K�M�Q��G�K�K�M�Q�B�$6��A�v� �!Q�R�R��@�A�A��<�<�>��l�l�n�G��H���"���]�]�/�/��8�
��2�%�
����z�*�'=�>�
����z�2�9�9�"�(�(��9�O�
�(��W��}�4�9�9�U���D�z�%�%�m�\����%�T�Tr<c���d}tj|tt���t	j
|�}t	j
||jj��j|||�S)Nz(searchsorted requires high memory usage.r�rS)	r�r�rrrUrVrTrX�searchsorted)r��v�side�sorterr�s     r=rmzSparseArray.searchsorted~sV��9���
�
�c�-�:J�:L�M��J�J�q�M���z�z�$�d�j�j�&8�&8�9�F�F�q�$�PV�W�Wr<c��|jj�}|j||j|j�Sr�)r{rar�rvrT)r�r�s  r=razSparseArray.copy�s1�����$�$�&�������
�
�t�z�z�B�Br<c��|dj}g}d}|r|dj}nd}|dk(r�g}|D]p}|jjj	�}||z
}||jj
z
}|j
|j�|j
|��rtj|�}	tj|�}
t||
�}n�g}g}
|D]�}|jj�}|j
|j�|
j
|jj	�|z�|j
|j�||jj
z
}��tj|�}	tj|
�}tj|�}t|||�}||	||��S)NrrA�r�rW)rWrrvr�rar��appendr{rU�concatenater
�to_block_index�blocs�blengthsr)r��	to_concatrWr�r��sp_kindr�rZ�int_idxr��indices_arrrvrxrw�	block_idx�	blocs_arr�blengths_arrs                 r=rzSparseArray._concat_same_type�s����q�\�,�,�
��������l�'�'�G��G��i���G� �
(���,�,�.�.�3�3�5���6�!���#�,�,�-�-�-���
�
�c�m�m�,����w�'�

(��>�>�&�)�D��.�.��1�K� ���4�H��H��E� �
.���L�L�7�7�9�	��
�
�c�m�m�,����Y�_�_�1�1�3�f�<�=����	� 2� 2�3��#�,�,�-�-�-��

.��>�>�&�)�D����u�-�I��>�>�(�3�L�!�&�)�\�B�H��4�h�:�F�Fr<c��||jk(r|s|S|j�St|�}t|t�s.tj|�}t|�}t||d��S|jj|�}t|j�}tt
j|�}t|j�}t|||��}tj|�}|j||j|�S)aE
        Change the dtype of a SparseArray.

        The output will always be a SparseArray. To convert to a dense
        ndarray with a certain dtype, use :meth:`numpy.asarray`.

        Parameters
        ----------
        dtype : np.dtype or ExtensionDtype
            For SparseDtype, this changes the dtype of
            ``self.sp_values`` and the ``self.fill_value``.

            For other dtypes, this only changes the dtype of
            ``self.sp_values``.

        copy : bool, default True
            Whether to ensure a copy is made, even if not necessary.

        Returns
        -------
        SparseArray

        Examples
        --------
        >>> arr = pd.arrays.SparseArray([0, 0, 1, 2])
        >>> arr
        [0, 0, 1, 2]
        Fill: 0
        IntIndex
        Indices: array([2, 3], dtype=int32)

        >>> arr.astype(SparseDtype(np.dtype('int32')))
        [0, 0, 1, 2]
        Fill: 0
        IntIndex
        Indices: array([2, 3], dtype=int32)

        Using a NumPy dtype with a different kind (e.g. float) will coerce
        just ``self.sp_values``.

        >>> arr.astype(SparseDtype(np.dtype('float64')))
        ... # doctest: +NORMALIZE_WHITESPACE
        [nan, nan, 1.0, 2.0]
        Fill: nan
        IntIndex
        Indices: array([2, 3], dtype=int32)

        Using a SparseDtype, you can also change the fill value as well.

        >>> arr.astype(SparseDtype("float64", fill_value=0.0))
        ... # doctest: +NORMALIZE_WHITESPACE
        [0.0, 0.0, 1.0, 2.0]
        Fill: 0.0
        IntIndex
        Indices: array([2, 3], dtype=int32)
        Fr�r`)r�rar r�r"rUrVr,rrT�update_dtype�_subtype_with_strr	r{r�rv)r�rTra�future_dtyper�rXr{s       r=ruzSparseArray.astype�s���r�D�K�K������y�y�{�"�#�E�*���,��4��Z�Z��%�F�3�F�;�F���l��G�G��
�
�'�'��.���u�6�6�7���r�x�x��)��/����?�� ���t�<�	��J�J�y�)�	����	�4�=�=�%�@�@r<c�D����t�tjtf��|j�|�t��r�r�j
���n�������fd�}|jD�cgc]
}||���}}t|�||j���Scc}w)af
        Map categories using an input mapping or function.

        Parameters
        ----------
        mapper : dict, Series, callable
            The correspondence from old values to new.
        na_action : {None, 'ignore'}, default None
            If 'ignore', propagate NA values, without passing them to the
            mapping correspondence.

        Returns
        -------
        SparseArray
            The output array will have the same density as the input.
            The output fill value will be the result of applying the
            mapping to ``self.fill_value``

        Examples
        --------
        >>> arr = pd.arrays.SparseArray([0, 1, 2])
        >>> arr.map(lambda x: x + 10)
        [10, 11, 12]
        Fill: 10
        IntIndex
        Indices: array([1, 2], dtype=int32)

        >>> arr.map({0: 10, 1: 11, 2: 12})
        [10, 11, 12]
        Fill: 10
        IntIndex
        Indices: array([1, 2], dtype=int32)

        >>> arr.map(pd.Series([10, 11, 12], index=[0, 1, 2]))
        [10, 11, 12]
        Fill: 10
        IntIndex
        Indices: array([1, 2], dtype=int32)
        c�l���r�j|d�n�|�}|�us|�k(r
d}t|��|S)Nz-fill value in the sparse values not supported)�getrY)�sp_val�
new_sp_valr��fill_val�is_map�mappers   ���r=�funczSparseArray.map.<locals>.funcCs?���5;����F�D�1����J��X�%��x�)?�E�� ��o�%��r<rs)
r�r�Mappingr$rWr'r�r{r�rv)r�r��	na_actionr��xr{r�r�s `    @@r=�mapzSparseArray.maps����P�F�S�[�[�)�$<�=���?�?�����h��9?�v�z�z�(�H�5�V�H�EU�H�	�'+�n�n�5��T�!�W�5�	�5��t�D�z�)�$�-�-�H�U�U��6s�.Bc�X�tj||jj��S)zr
        Convert SparseArray to a NumPy array.

        Returns
        -------
        arr : NumPy array
        rS)rUrVr{rTr�s r=ryzSparseArray.to_denseOs���z�z�$�d�n�n�&:�&:�;�;r<c��tj|||�}t|j|j��}t|�j
||��}|S)NrrS)rUrr"rTrWr�r�)r�r�r��naive_implementationrTr�s      r=�_wherezSparseArray._whereYsM�� "�x�x��d�E�:���0�6�6�4�?�?�S���d��*�*�+?�u�*�M���
r<c�
�t|t�rX|\}\}}tjg�}|j	|�||_||_t|j|�|_	y|jj|�y)z*Necessary for making this object picklableN)r�r;rUr��__setstate__r�r�r"rTr��__dict__�update)r��state�nd_staterWrvr�s      r=r�zSparseArray.__setstate__dsl���e�U�#�/4�,�H�,�z�8��H�H�R�L�M��&�&�x�0�"/�D��!)�D��%�m�&9�&9�:�F�D�K��M�M� � ��'r<c��|jdk(r|jjfS|jj|jdk7fS)Nr)rWrvr�r{r�s r=�nonzerozSparseArray.nonzerorsB���?�?�a���M�M�)�)�+�+��M�M�)�)�$�.�.�A�*=�>�@�@r<)�skipna�keepdimsc���t||d�}|�td|�d|j����|r|}n|j�}t||�di|��}|rt	|�|g|j��S|S)Nzcannot perform z with type rSr;)r�r�rTr.r�)r�r�r�r��kwargsrrZr�s        r=�_reducezSparseArray._reduce|s}����t�T�*���>��o�d�V�;�t�z�z�l�K�L�L���C��+�+�-�C�#���d�#�-�f�-����4��:�v�h�d�j�j�9�9��Mr<c���tj||�|j}t|�t|�k7r t	j
|j�sy|j�S)z�
        Tests whether all elements evaluate True

        Returns
        -------
        all : bool

        See Also
        --------
        numpy.all
        F)�nv�validate_allr{r�rUrdrW�r��axis�argsr�r�s     r=rdzSparseArray.all�sI��	����f�%������v�;�#�d�)�#�B�F�F�4�?�?�,C���z�z�|�r<c���tj||�|j}t|�t|�k7r t	j
|j�ry|j�j�S)z�
        Tests whether at least one of elements evaluate True

        Returns
        -------
        any : bool

        See Also
        --------
        numpy.any
        T)r��validate_anyr{r�rUr~rWr�r�s     r=r~zSparseArray.any�sR��	����f�%������v�;�#�d�)�#����t���(?���z�z�|� � �"�"r<c�R�tj||�|j}|j�}|jj
dkDxr
|j}|r#|s!t|jjd��S|jr:t|jd|�r!t|jjd��S|S|jj
}	t|jd||	z
�r!t|jjd��S||j|	zzS)a
        Sum of non-NA/null values

        Parameters
        ----------
        axis : int, default 0
            Not Used. NumPy compatibility.
        min_count : int, default 0
            The required number of valid values to perform the summation. If fewer
            than ``min_count`` valid values are present, the result will be the missing
            value indicator for subarray type.
        *args, **kwargs
            Not Used. NumPy compatibility.

        Returns
        -------
        scalar
        rF��compatN)
r��validate_sumr��sumrvrwr�r&rTrXr1r�rW)
r�r��	min_countr�r�r��
valid_vals�sp_sum�has_na�nsparses
          r=r�zSparseArray.sum�s���4	����f�%��*�*�
����!�����$�$�q�(�F��1F�1F�-F���&�%�d�j�j�&8�&8��G�G�� � �$�Z�%5�%5�t�Y�G�)�$�*�*�*<�*<�U�K�K��M��m�m�)�)�G�$�Z�%5�%5�t�Y��=P�Q�)�$�*�*�*<�*<�U�K�K��D�O�O�g�5�5�5r<c�H�tj||�|�||jk\rtd|�d���|js't|j
��j�St|jj�|j|j��S)a 
        Cumulative sum of non-NA/null values.

        When performing the cumulative summation, any non-NA/null values will
        be skipped. The resulting SparseArray will preserve the locations of
        NaN values, but the fill value will be `np.nan` regardless.

        Parameters
        ----------
        axis : int or None
            Axis over which to perform the cumulative summation. If None,
            perform cumulative summation over flattened array.

        Returns
        -------
        cumsum : SparseArray
        zaxis(=z) out of boundsrs)r��validate_cumsum�ndimrYr�rQry�cumsumr{rvrW)r�r�r�r�s    r=r�zSparseArray.cumsum�s���$	���4��(�����	�	� 1��v�d�V�?�;�<�<��$�$��t�}�}��/�6�6�8�8���N�N�!�!�#�������
�	
r<c��tj||�|j}|j�}t	|�}|j
r||zS|jj}||j|zz||zzS)zb
        Mean of non-NA/null values

        Returns
        -------
        mean : float
        )	r��
validate_meanr�r�r�r�rvrwrW)r�r�r�r�r�r��ctr�s        r=�meanzSparseArray.meanss��	����v�&��*�*�
����!��
��_��� � ��B�;���m�m�)�)�G��T�_�_�w�6�6�2��<�H�Hr<)r�r�c�h�tj||j�|jd|��S)a4
        Max of array values, ignoring NA values if specified.

        Parameters
        ----------
        axis : int, default 0
            Not Used. NumPy compatibility.
        skipna : bool, default True
            Whether to ignore NA values.

        Returns
        -------
        scalar
        r^�r��r��validate_minmax_axisr��_min_max�r�r�r�s   r=r^zSparseArray.max�+��	����d�i�i�0��}�}�U�6�}�2�2r<c�h�tj||j�|jd|��S)a4
        Min of array values, ignoring NA values if specified.

        Parameters
        ----------
        axis : int, default 0
            Not Used. NumPy compatibility.
        skipna : bool, default True
            Whether to ignore NA values.

        Returns
        -------
        scalar
        r
r�r�r�s   r=r
zSparseArray.min+r�r<c���|j}|jxr|jjdkD}t	|�dkDrwt||��}|r$|dk(rtnt}|||j�S|r|S|jjdk(r|St|jjd��S|r|jSt|jjd��S)z�
        Min/max of non-NA/null values

        Parameters
        ----------
        kind : {"min", "max"}
        skipna : bool

        Returns
        -------
        scalar
        rr^Fr�)r�r�rvrwr�r�r^r
rWr&rTrX)r�rr�r��has_nonnull_fill_vals�
sp_min_maxr�s       r=r�zSparseArray._min_max=s����*�*�
�$(�$9�$9� 9� U�d�m�m�>Q�>Q�TU�>U���z�?�Q��2���T�2�4�J�%�"�e�m�s����J����8�8��!�!����$�$��)�!�!�)�$�*�*�*<�*<�U�K�K�
"��?�?�"�%�d�j�j�&8�&8��G�Gr<c��|j}|jj}tjt|��}|dk(rtjntj}tj|jd�}||}||}|||�}	||	}
t|j�r|
S|dk(r||
|jkr|
S|dk(r||
|jkDr|
S|j�}|dk(r|
S|S)Nrr�argminr)r�r�r�rUrVr%rr�rDr�rWr)r�rr�r�r�r�r��non_nans�non_nan_idx�
_candidate�	candidate�_locs            r=�_argmin_argmaxzSparseArray._argmin_argmax`s����$�$���"�"�*�*���z�z�$�v�,�'�� �H�,�r�y�y�"�)�)���i�i����Q��(���4�%�=���4�%�j�� ��h��0�
��*�%�	����� ����8���Y��$�/�/� A����8���Y��$�/�/� A����)�)�+���2�:����Kr<c�d�t|d�|s|jrt�|jd�S)Nr�r�r�_hasna�NotImplementedErrorr��r�r�s  r=rzSparseArray.argmaxz�,���F�H�-��$�+�+�%�%��"�"�8�,�,r<c�d�t|d�|s|jrt�|jd�S)Nr�r�r�r�s  r=r�zSparseArray.argmin�r�r<c���|jdd�}||zD](}t|�jtfz�r�"tcStj�||g|��i|��}|tur|Sd|vrtj�||g|��i|��}|S|dk(r%tj�||g|��i|��}|tur|St|�dk(r�t||��jfi|��}	t||��jfi|��}
|jdkDr t�fd�t|	|
�D��}|S|dk(r|	S�j!|	�j"t%|	j&|
��Std�|D��}t||�|i|��}|rt|�dk(r|d}|S|jdkDrt�fd�|D��S|d	k(ryt)��|�S)
Nr�r;�reducerfc	3��K�|]8\}}�j|�jt|j|�����:y�wr�)r�rvr"rT)�.0�sp_value�fvr�s   �r=�	<genexpr>z.SparseArray.__array_ufunc__.<locals>.<genexpr>�s@������%��"��$�$� �$�-�-��X�^�^�R�1P���s�>Ac3�FK�|]}tj|����y�wr�)rUrV)r�r�s  r=r�z.SparseArray.__array_ufunc__.<locals>.<genexpr>�s����9�Q�2�:�:�a�=�9�s�!rc3�@�K�|]}t��|����y�wr�)r�)r�r�r�s  �r=r�z.SparseArray.__array_ufunc__.<locals>.<genexpr>�s�����7�1���d��A��7�s��at)r�r��_HANDLED_TYPESrQ�NotImplementedr(�!maybe_dispatch_ufunc_to_dunder_op�dispatch_ufunc_with_out�dispatch_reduction_ufuncr�r�r{rW�noutr;�zipr�rvr"rTr�)
r��ufuncr�inputsr�r�r�r��resr{rW�arrays�
new_inputss
`            r=�__array_ufunc__zSparseArray.__array_ufunc__�s����j�j���#���#��	&�A��a��!4�!4��~�!E�F�%�%�	&�
�<�<��%��
�"(�
�,2�
����'��M��F�?��3�3��e�V��&,��06��C��J��X���7�7��e�V��&,��06��F��^�+��
��v�;�!��.���v�.�t�~�~�H��H�I�/����/����J�6�J�J��z�z�A�~���),�I�z�(B�	����
��8�#� � ��#�#��4�=�=�+�i�o�o�z�*R��
��9�&�9�9�
�'����'��>�v�>����3�x�1�}��!�f���J��:�:��>��7��7�7�7�
�t�^���4��:�f�%�%r<c	�^�|j}t|t�rt||||�St	|�r�tjd��5|t|�tj|��}||j|�}ddd�|dk(r:\}}\}}	t|||j|�t|||j|	�fSt||j�Stj|�}tjd��5t|�t|�k7r#tdt|��dt|�����t|t�s%t|dd�}
t||j|
��}t||||�cddd�S#1swY��xYw#1swYyxYw)Nrbrcrszlength mismatch: z vs. rTr�)r7r�rQr�rrUrxr[rVr{r�rvr�r�r�rW)r��otherr��op_namer�r�r�r��lfill�rfillrTs           r=�
_arith_methodzSparseArray._arith_method�s����+�+���e�[�)�#�D�%��W�=�=�
�u�
�����*�
3��)�D�/�2�:�:�e�+<�=���D�N�N�E�2��
3��(�"�$���e�#���u� ��$��
�
�u�E� ��%�����F���
 �������E�E��J�J�u�%�E�����*�
B��t�9��E�
�*�(�+�C��I�;�e�C��J�<�H���"�%��5�#�E�7�D�9�E�'��$�/�/�QV�W�E�'��e�R��A�
B�
B�!
3�
3�� 
B�
B�s�9F�A=F#�F �#F,c���t|�s*t|t|��stj|�}t|tj
�rt
||j��}t|t�rct|�t|�k7r#tdt|��dt|�����|jjd�}t||||�S||j|�}tjt|�|tj��}||j|�||j j"<t|�||tj��S)Nrz operands have mismatched length z and rmrSr�)rr�r�rUrVr�rQrWr�rYr7�stripr�r�r�r{rvr�)r�r�r�r�rWr�s      r=�_cmp_methodzSparseArray._cmp_method�s�����
�5�$�t�*�(E��J�J�u�%�E��e�R�Z�Z�(���$�/�/�B�E��e�[�)��4�y�C��J�&� �6�s�4�y�k��s�5�z�l�S����k�k�'�'��,�G�#�D�%��W�=�=��D�O�O�U�3�J��W�W�S��Y�
�"�(�(�C�F�,.�t�~�~�u�,E�F�4�=�=�(�(�)��4��:��%��h�h��
r<c���|tj|j��j�}t	|j
j|�}t|j�s||jk(rB||j�}t|�j||j|j
�St|�||j��|��Sr�)
rUr�rWr�r"rTrXr%r{r�r�rvry)r�r�rWrTr�s     r=�
_unary_methodzSparseArray._unary_methods����������1�2�7�7�9�
��D�J�J�.�.�
�;������ �J�$�/�/�$A�����'�F���:�)�)�&�$�-�-����L�L��t�D�z�"�T�]�]�_�-�U�;�;r<c�@�|jtj�Sr�)r��operator�posr�s r=�__pos__zSparseArray.__pos__����!�!�(�,�,�/�/r<c�@�|jtj�Sr�)r�r��negr�s r=�__neg__zSparseArray.__neg__ r�r<c�@�|jtj�Sr�)r�r��invertr�s r=�
__invert__zSparseArray.__invert__#s���!�!�(�/�/�2�2r<c�@�|jtj�Sr�)r�r�rr�s r=�__abs__zSparseArray.__abs__&r�r<c��tj|�}tj|j�}tj|j�}|�d|�d|��S)Nz
Fill: �
)r2�pprint_thingrWrv)r��pp_str�pp_fill�pp_indexs    r=�__repr__zSparseArray.__repr__,sQ���&�&�t�,���'�'����8���(�(����7�����'��"�X�J�7�7r<c��yr�r;)r��boxeds  r=�
_formatterzSparseArray._formatter2s��r<)NNrANF)r�SparseIndexKindrT�Dtype | Nonerarj�return�None)r�r�r�rrTr"rrL)r�r>rrL)NN)rTzNpDtype | Nonerazbool | Nonerr�)rr)rTrrarj)rr)rr�)rr")rr)r�int)rrj)r�float)rrL)
rr?r��
int | Noner�z#Literal['inside', 'outside'] | NonerarjrrL)NNNT)rzFillnaOptions | Noner�rrarjrrL)rfN)rrrrL)�first)rzLiteral['first', 'last', False]rznpt.NDArray[np.bool_])T)r(rjrztuple[np.ndarray, SparseArray])r.rjrrO)r�rKrr)r�z,SequenceIndexer | tuple[int | ellipsis, ...]rrL)r�z.PositionalIndexer | tuple[int | ellipsis, ...]rz
Self | Any)rVrjrrLr�)r�N)rnzArrayLike | objectrozLiteral['left', 'right']rpzNumpySorter | Nonerznpt.NDArray[np.intp] | np.intp)ryzSequence[Self]rrL)NT)rTzAstypeArg | Nonerarj)rztuple[npt.NDArray[np.int32]])r�r�r�rjr�rj)r)r�rFrrj)rrT)r�rFr�rr�rjrrJ)r�rFrrQ)r�rE)r�zAxisInt | Noner�rj)rzLiteral['min', 'max']r�rjrrJ)rzLiteral['argmin', 'argmax']rr)r�rjrr)r�znp.ufuncrr�)rrQ)rr�)F)r
rj)Wr7r8r9�__doc__�_subtypr+�
_hidden_attrs�	frozenset�__annotations__r��classmethodr�r�r�r�r�r��propertyrvr{rTrW�setterrr�r�r�r�r�r�r�r%rrrrrr*rr r&r)r4r
r7r<rFrYrZrmrarrur�ryr�r�r�r�rdr~r�r�r�r^r
r�r�rr�rUr��numbers�Numberr�r�r�r��_logical_methodr�r�r�rrrr�
__classcell__)rs@r=rQrQs����D�L�G� �.�.��2��>�M�������
�� )�"��CC�
�CC��
CC��CC�
�CC�J�
� �
�"�
��	
�

�
��
��)2��)2�XAE��#��2=��	��6��>B�QV�)��)��1��1��"��"��#��#������%��%�$���=��=���������
$��-��-�1��<��<��<��<��%��%�?�!�:>��

��
��	
�
8�
��

�
�
� �'+� ��;K�%�;K��	;K�
�;K�
�
;K�z-�60�*	��	"�	"�#�6=�>�3�>�	�>�$�>�D�1�!%�
!��
!�
(�
!�&7�V������
9��
����\6�
;�\6�
�\6�|	�38�D�
�$@�DU�4*0�%)�		X��	X�'�	X�#�		X�

(�	X�C��5G��5G�nMA�^9V�v<��(�A�,0�%����$(��;?��(�*#�.���	*6��*6��*6��	*6�
�*6�X
�@I�&-1��3�$-1��3�$!H�F�4-�-��j�j�'�.�.�1�N�@&�LB�B�:"�O�	<�0�0�3�0�8��r<c���t|tj�sJ�|jdkDrt	d��|�t|j�}t|�rt|�}n[t|j�r|jt�}t|j�rtj||�}n||k7}t|�}|t|�k7r|j j"}n0|j%�djtj&�}t)|||�}||}|�-t+|�}t-||��}tj.|�}|||fS)a@
    Convert ndarray to sparse format

    Parameters
    ----------
    arr : ndarray
    kind : {'block', 'integer'}
    fill_value : NaN or another value
    dtype : np.dtype, optional
    copy : bool, default False

    Returns
    -------
    (sparse_values, index, fill_value) : (ndarray, SparseIndex, Scalar)
    rfzexpected dimension <= 1 datarrS)r�rUr�r�r�r&rTr%r'rrur�rr��make_mask_object_ndarrayr�rvr�r�rErCr,rrV)	rZrrWrTr�r�r�r��sparsified_valuess	         r=r�r�8s4��*�c�2�:�:�&�&�&�
�x�x�!�|��6�7�7���'��	�	�2�
��J���S�z���3�9�9�%��*�*�V�$�C��3�9�9�%��1�1�#�z�B�D��*�$�D�
��X�F�
��T����-�-�'�'���,�,�.��#�*�*�2�8�8�4���f�g�t�4�E��D�	����:�;L�M��(�):�%�H���J�J�'8�9���e�Z�/�/r<c��yr�r;�r�r�rs   r=rCrCv���r<c��yr�r;r's   r=rCrC{r(r<c��|dk(r'tj|�\}}t|||�}|S|dk(rt||�}|St	d��)NrBrAzmust be block or integer type)r��
get_blocksrr
rY)r�r�r�locs�lensr�s      r=rCrC�s]���w���%�%�g�.�
��d��6�4��.��
�L�	
��	����)���L��8�9�9r<)rZrQrr�)
r�rQr�rQr�rr�r�rrQr�)r�r�rTrrrQ)rBNN)rZr�rrrTznp.dtype | None)r�rrzLiteral['block']rr)r�rrzLiteral['integer']rr
)r�rrrrr)|r�
__future__r�collectionsrrr��typingrrrrr	r
r��numpyrU�pandas._libsr�pandas._libs.sparse�_libs�sparser�rr
r�pandas._libs.tslibsr�pandas.compat.numpyrr��
pandas.errorsr�pandas.util._decoratorsr�pandas.util._exceptionsr�pandas.util._validatorsrr�pandas.core.dtypes.astyper�pandas.core.dtypes.castrrr�pandas.core.dtypes.commonrrrrrrr �pandas.core.dtypes.dtypesr!r"�pandas.core.dtypes.genericr#r$�pandas.core.dtypes.missingr%r&r'�pandas.corer(�pandas.core.algorithms�core�
algorithmsr�pandas.core.arrayliker)�pandas.core.arraysr*�pandas.core.baser+�pandas.core.common�commonrH�pandas.core.constructionr,r-r.�pandas.core.indexersr/r0�pandas.core.nanopsr1�pandas.io.formatsr2�collections.abcr3�enumr4r6r:�scipy.sparser>�pandas._typingr?r@rrCrDrErFrGrHrIrJrKrLrMrNr/rOr��_sparray_doc_kwargsr[r�r�rQr�rCr;r<r=�<module>rTs����#���������#�#���
$�.�,�'�4��
3���
�������"�&�&�*�-�)� � ���
�5�&��(���4��� � �H�%��
�0�1�O�
�
�
�
���H�~�H��
�.��*�0iG�
�iG�)�iG�/7�iG�?B�iG��iG�ZFJ��

��6B����.V�(�L�.�V�v0$��!�	;0�	�;0�
�;0��	;0�|
��
��
��
��	r<

Youez - 2016 - github.com/yon3zu
LinuXploit