
     j                    B   d Z ddlmZ ddlmZ ddlZddlZddlmZm	Z	m
Z
mZmZmZ ddlZddlZddlmZ ddlmc mZ ddlmZmZmZ ddlmZ dd	lmZ dd
l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+m,Z,m-Z- ddl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 ddl6m7Z7m8Z8 ddl9m:Z:m;Z; ddl<m=Z=m>Z>m?Z? ddl@mAZA ddlBmCc mDZE ddlFmGZG ddlHmIZI ddlJmKZK ddlLmCc mMZN ddlOmPZPmQZQmRZR ddlSmTZTmUZU ddlVmWZW ddlXmYZY erZddlZm[Z[ ddl\m]Z]  G d de]          Z^e^j_        Z_dd l`maZa dd!lbmcZcmdZd ed"         Zedd#lbmfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZq dd$lrmsZs n ete_          Z^d%d&iZudEd*ZvdFd1Zw	 dGdHd4Zx G d5 d&eGeKeI          Zy	 	 	 dIdJd:ZzedKd?            Z{edLdB            Z{dMdDZ{dS )Nz
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                      e Zd ZdZdS )ellipsisz...N)__name__
__module____qualname__Ellipsis     sC:\Users\Terasoftware\OneDrive\Desktop\faahhh\fyndo\fyndo\venv\Lib\site-packages\pandas/core/arrays/sparse/array.pyr6   r6   [   s        r<   r6   )spmatrix)FillnaOptionsNumpySorter)integerblock)	ArrayLike	AstypeArgAxisAxisIntDtypeNpDtypePositionalIndexerScalarScalarIndexerSelfSequenceIndexernpt)SeriesklassSparseArrayarrreturn
np.ndarrayc                    	 t          j        | j        | j        j                  S # t
          $ r t          j        | j                  cY S w xY w)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_valuerW   subtype
ValueError)rR   s    r=   	_get_fillr]      sV    $*z#.	0ABBBB * * *z#.)))))*s   $' #AAleftrightopr   namestrc           	        |                     d          r
|dd         }| j        j        }|j        j        }||k    rqt          ||g          }t	          || j                  }t	          ||j                  }|                     |d          } |                    |d          }|j        }n|}d}| j        j        dk    s|j        j        dk    rt          j
        d	          5   ||                                 |                                          }	 |t          |           t          |                    }
ddd           n# 1 swxY w Y   | j        j        dk    r	| j        }n|j        }n| j                            |j                  rrt          j
        d	          5   || j        |j                  }	 |t          |           t          |                    }
ddd           n# 1 swxY w Y   | j        }nT|d         d
k    r|| }} |dd         }|dv r\|dk    rVd| d}| j                            t          j                  }|j                            t          j                  }t"          }nd| d| }| j        }|j        }|dv rV|dk                                    r>| j        j        dv r0d| d}|                    d          }|                    d          }t)          t*          |          }t          j
        d	          5   ||| j        | j        ||j        |j                  \  }	}}
ddd           n# 1 swxY w Y   |dk    r@t-          ||	d         ||
d         |          t-          ||	d         ||
d         |          fS ||	j        }t-          ||	||
|          S )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divmodrV   )
startswithrW   r[   r   r"   rZ   astypesp_indexngapsrX   errstateto_denser]   equals	sp_valuesviewuint8rq   anykindgetattrsplib_wrap_result)r^   r_   r`   ra   ltypertyper[   rW   result_dtyperesultfillindexopnameleft_sp_valuesright_sp_values	sparse_ops                   r=   _sparse_array_opr      s   & t AbDz JEKE~ 	"E5>22GT_55GU%566{{5u{--U// L}a 25>#71#< 2[X&&& 	9 	9R)9)9::F2iooy'7'788D	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 =!# 	#MEENEE			en	-	- )[X&&& 	9 	9R88F2iooy'7'788D	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 7c> 	%D8D'' 		.EVO 		.+t+++F!^00::N#o2228<<OLL-t--e--F!^N#oO ''	@!  ""	@ 
4'	@ .t---F+229==N-44Y??OE6**	[X&&& 	 	"+) # #FE4	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 x 

 vay%aMMMvay%aMMM
 	

  $|feTFFFFs7   (AEEE,=G55G9<G9)MMMrW   Dtype | Nonec                    |                      d          r
| dd         } | dv rt          }t          j        |          }t	          |          rt          |          }t          ||||          S )z.
    wrap op result to have correct dtype
    rd   re   rf   )eqneltgtlege)sparse_indexrZ   rW   )r{   rq   r   item_from_zerodimr   rQ   )ra   datar   rZ   rW   s        r=   r   r     s     t AbDz33 &z22JU &*%%
<Je   r<   c                  j    e Zd ZU dZdZej         eg           z  Zded<   ded<   ded<   	 	 	 	 	 dddZ	e
dd            Ze
dd            Z	 dddZddZe
d	dddd             Ze
d!             Zedd"            Zedd#            Zedd$            Zed%             Zej        dd&            Zedd'            Zedd(            Zdd*Zedd+            Zdd,Zedd-            Zedd/            Zedd0            Zdd1Zd	d	d2d3d fd:Z 	 	 	 	 dd fd<Z!ddd?Z"d@ Z# e$e%j&                  	 dddE            Z&ddFZ'dG Z(	 dddJZ)dddMZ*e+ddQ            Z,e+ddS            Z,ddVZ,dW Z-dd	dXddZZ.ddd[Z/dd\Z0	 	 dddeZ1ddfZ2e
ddi            Z3dddkZ4dddlZ5ddmZ6dn Z7ddoZ8ddqZ9d2ddrddwZ:ddxZ;ddd|Z<	 	 	 dddZ=dddZ>dddZ?d	d2dddZ@d	d2dddZAddZBddZCdddZDdddZEeFjG        eHjI        fZJddZKd ZLddZMeMZNddZOddZPddZQddZRddZSddZTdddZU xZVS )rQ   a  
    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_indexrT   _sparse_valuesr"   _dtypeNrA   Fr   SparseIndexKindrW   r   rh   rq   rS   Nonec                H   |t          |t                    r|j        }t          |t          |                     r"||j        }||j        }||j        }|j        }t          |t                    r5	 t          j        |          }n# t          $ r t          |          }Y nw xY wt          |t                    r||j        }|j        }t          |          rct          j        dt          |           j         dt           t#                                 |d}n|j        }t'          ||d           }|j        }|t          |          }|t)          j        g |          }	 t-          |d           }nU# t.          $ rH |Bt)          j        t0                    }t)          j        t)          j        ||                    }n Y nw xY w|r|                                }|)||j        n|}|t(          j        }nt;          |          }t          |t          |                     r&|$|j        }t)          j        |j        |          }	n&|t?          |d          }t          |t(          j                   st          |j        tB                    ret          j        d	|j         d
tD          t#                                 t)          j        |d          }|tF          u rt)          j$        dd          }t)          j        |          }tK          ||||          \  }	}}nNt)          j        ||          }	tM          |	          |j'        k    r tQ          dt          |	           d          || _        |	| _)        t          |	j        |          | _*        d S )NzConstructing z\ with scalar data is deprecated and will raise in a future version. Pass a sequence instead.
stacklevelrm   rV   )r   T)extract_numpyzCreating SparseArray from z^ data loses timezone information. Cast to object before sparse to retain timezone information.zdatetime64[ns]r   ns)r   rZ   rW   zNon array-like type z' must have the same length as the index)+
isinstancer"   rZ   typer}   rW   r   rb   construct_from_string	TypeErrorr    r[   r   warningswarnr7   FutureWarningr   lengthr   rX   arrayr.   r\   object
atleast_1drY   rh   nanr&   r   r-   ndarrayr!   UserWarningr   
datetime64_make_sparselennpointsAssertionErrorr   r   )
selfr   r   rZ   r   rW   rh   r   fill_value_dtypesparse_valuess
             r=   __init__zSparseArray.__init__l  sB     	**UK"@"@ 	*)JdDJJ'' 		" -#} -!_
 #
>D eS!! 	,,#9%@@ , , ,$U++, e[)) 	" ."-
MET?? 	MOT

 3 O O O+--	     .&-5dG4PPPDJE 	( ''E  	- 8Be,,,D		!$d333DD 	 	 	  ((}RZE%B%B%BCC 	  	99;;D 	B-2Etzz BV

/0@AA
dDJJ'' (	L (	-L Je  MM  !	 T:::DdBJ// (dj/:: 
@MATZ A A A $#3#5#5    :d2BCCCD!S( @%']5$%?%?
z$''6B %7 7 73M< Jt5999M=!!\%99 $84+>+> 8 8 8   *+!-"5zBBs%   4B	 	B%$B%)E; ;AGGr   rL   c                d    t                               |           }||_        ||_        ||_        |S N)r   __new__r   r   r   )clsr   r   rW   news        r=   _simple_newzSparseArray._simple_new  s1     nnS!!()

r<   r   r>   c                   |j         \  }}|dk    rt          d| d          |                                }|                                 |j        }|j        }t          j        d|j                  	                                }t          |j        |          }t          ||          }|                     |||          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)
        rm   z''data' must have a single column, not ''r   rV   )shaper\   tocscsort_indicesr   indicesrX   r   rW   itemr"   r   r   )	r   r   r   ncolrR   idxzerorW   r   s	            r=   from_spmatrixzSparseArray.from_spmatrix  s    4 z19 	PNtNNNOOO zz||ilx+++0022CIt,,%%sE5111r<   NpDtype | Nonebool | Nonec                   | j         }| j        j        dk    r| j        S |w| j        j        j        dk    r|t          u rt          j        d          }	 t          j	        | j        j        t          |                    }n# t          $ r
 t          }Y nw xY wt          j        | j        ||          }| j        || j        j        <   |S )Nr   Mr   rV   )rZ   r}   r~   r   rW   r   r   rX   r   result_typer   r   r   fullr   r   )r   rW   rh   rZ   outs        r=   	__array__zSparseArray.__array__*  s     _
=!# 	">! 	 ~#(C/ 6 $ 6!#u!5!5Jt~';T*=M=MNN    gdj*E:::%)^DM!"
s   ,B BBc                $    d}t          |          )Nz8SparseArray does not support item assignment via setitem)r   )r   keyvaluemsgs       r=   __setitem__zSparseArray.__setitem__E  s     Innr<   rW   rh   c                    | ||          S NrV   r;   )r   scalarsrW   rh   s       r=   _from_sequencezSparseArray._from_sequenceL  s    s7%((((r<   c                &     | ||j                   S r   rV   )r   valuesoriginals      r=   _from_factorizedzSparseArray._from_factorizedP  s    s60000r<   c                    | j         S )zX
        The SparseIndex containing the location of non- ``fill_value`` points.
        )r   r   s    r=   r}   zSparseArray.sp_indexW  s    
 !!r<   c                    | j         S )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   zSparseArray.sp_values^  s     ""r<   c                    | j         S r   )r   r   s    r=   rW   zSparseArray.dtypel  s
    {r<   c                    | j         j        S )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
        )rW   rZ   r   s    r=   rZ   zSparseArray.fill_valuep  s    " z$$r<   c                D    t          | j        j        |          | _        d S r   )r"   rW   r[   r   )r   r   s     r=   rZ   zSparseArray.fill_value  s    !$*"4e<<r<   c                >    t          | j        t                    rdS dS )zW
        The kind of sparse index for this array. One of {'integer', 'block'}.
        rA   rB   )r   r}   r   r   s    r=   r   zSparseArray.kind  s"    
 dmX.. 	97r<   c                >    | j         }t          |          }||         S r   )r   r'   )r   sp_valsmasks      r=   _valid_sp_valueszSparseArray._valid_sp_values  s    .W~~t}r<   intc                    | j         j        S r   )r}   r   r   s    r=   __len__zSparseArray.__len__  s    }##r<   c                    | j         j        S r   )r   _is_na_fill_valuer   s    r=   _null_fill_valuezSparseArray._null_fill_value  s    {,,r<   c                D    | j         rt          |          S | j        |k    S r   )r   r%   rZ   )r   rZ   s     r=   _fill_value_matcheszSparseArray._fill_value_matches  s(      	1
###?j00r<   c                4    | j         j        | j        j        z   S r   )r   nbytesr}   r   s    r=   r   zSparseArray.nbytes  s    ~$t}';;;r<   floatc                4    | j         j        | j         j        z  S )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
        )r}   r   r   r   s    r=   densityzSparseArray.density  s     }$t}';;;r<   c                    | j         j        S )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
        )r}   r   r   s    r=   r   zSparseArray.npoints  s     }$$r<   c                   t          t          | j                  }| j        r;t          |                               t          | j                  | j        |          S t          j	        t          |           dt          j                  }t          | j                  || j        j        <    t          |           |d|          S )NFrV   rZ   rW   )r"   rq   r   r   r   r%   r   r}   rX   r   r   bool_r   )r   rW   r   s      r=   r%   zSparseArray.isna  s     D$"788  	V::))$t~*>*>uUUUws4yy%rx888&*4>&:&:T]"#tDzz$5>>>>r<   T)limit
limit_arearh   methodr?   r  
int | Noner  #Literal['inside', 'outside'] | Nonec               N    t                                          ||||          S )N)r  r  r  rh   )super_pad_or_backfill)r   r  r  r  rh   	__class__s        r=   r  zSparseArray._pad_or_backfill  s/     ww'':D ( 
 
 	
r<   FillnaOptions | Nonec                b   ||||t          d          |#t                                          ||          S t          j        t          | j                  || j                  }| j        rt          | j	        j
        |          }n| 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.
        Nz(Must specify one of 'method' or 'value'.)r  r  rZ   )r\   r  fillnarX   wherer%   r   r   r"   rW   r[   r   r   )r   r   r  r  rh   
new_values	new_dtyper  s          r=   r  zSparseArray.fillna  s    T  	Iu 	I	I#(	I GHHH 
	'77>>u>=== $t~"6"6t~NNJ$ ''
(:uMMM		 J	
D,>	JJJr<   rm   periodsc           	     V   t          |           r|dk    r|                                 S t          |          r| j        j        }t          j        || j        j                  }|| j        j        k    r)|                     t          || j
                            }n| }|                     |gt          t          |          t          |                     z  |j                  }|dk    r|}|d |          }n|t          |          d          }|}|                    ||g          S )Nr   rV   )r   rh   r%   rW   na_valuerX   r   r[   r|   r"   rZ   r   minabs_concat_same_type)r   r  rZ   r[   rR   emptyabs           r=   shiftzSparseArray.shift  s"   4yy 	GqL 	99;;
 	-,J.TZ-?@@dj(( 	++k'4?CCDDCCC##L3s7||SYY777sy $ 
 
 Q; 	AIgXIAACLLNN#AA$$aV,,,r<   c                F   t          |           dk    s| j        j        t          |           k    rdS | j        j        }t          |          r|d         dk    rdS t          j        t	          j        |          df         }||dk                                             dz   S )zh
        Get the location of the first fill value.

        Returns
        -------
        int
        r   re   rm   )r   r}   r   r   rX   r_diffargmax)r   r   r#  s      r=   _first_fill_value_locz!SparseArray._first_fill_value_loc6  s     t99> 	T]2c$ii? 	2-'7|| 	wqzA~ 	1
 uRWW%%q()q((**+a//r<   firstkeepLiteral['first', 'last', False]npt.NDArray[np.bool_]c                    t          j        |           }t          j        |                                           }t          j        |||          S )N)r'  r   )rX   rY   r%   algos
duplicated)r   r'  r   r   s       r=   r,  zSparseArray.duplicatedK  sB     D!!z$))++&&T====r<   c                   t          j        | j                  }t          | j                  t          |           k    r]|                                 }t          t          j        | j        d |                             }t          j        ||| j                  }t          |           	                    || j
                  S r   )r+  uniquer   r   r%  rX   insertrZ   r   r   rW   )r   uniquesfill_loc
insert_locs       r=   r.  zSparseArray.uniqueS  s    ,t~..t~#d))+ 		F1133H U\$.(*CDDEEJiT_EEGDzz((
(CCCr<   c                8    t          j        |           | j        fS r   )rX   rY   rZ   r   s    r=   _values_for_factorizez!SparseArray._values_for_factorizea  s    z$00r<   use_na_sentineltuple[np.ndarray, SparseArray]c                    t          j        t          j        |           |          \  }}t	          || j                  }||fS )N)r5  rV   )r+  	factorizerX   rY   rQ   rW   )r   r5  codesr0  
uniques_sps        r=   r8  zSparseArray.factorizee  sN     Jto
 
 
w !
;;;
j  r<   dropnarO   c                   ddl m}m} t          j        | j        |          \  }}}| j        j        }|dk    r| j        r|sw| j        rt          |          n
|| j
        k    }|                                r||xx         |z  cc<   n1t          j        |d| j
                  }t          j        |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   )r;  F)r   rh   )pandasr=  rO   r+  value_counts_arrayliker   r}   r~   r   r%   rZ   r   rX   r/  r   r#   )
r   r;  r=  rO   keyscountsrt   fcountsr   r   s
             r=   value_countszSparseArray.value_countst  s   	
 	
 	
 	
 	
 	
 	
 	

  6t~fUUUfa-%Q; 	7 5 	7V 	7!%!6S4:::DDO<SDxxzz 
7t' yq$/::61g66$)) 	E$KKEEEvfE6666r<   r   rK   r   c                    d S r   r;   r   r   s     r=   __getitem__zSparseArray.__getitem__  s    r<   ,SequenceIndexer | tuple[int | ellipsis, ...]c                    d S r   r;   rE  s     r=   rF  zSparseArray.__getitem__  s	    
 	r<   .PositionalIndexer | tuple[int | ellipsis, ...]
Self | Anyc                X   t          |t                    r't          |          }|t          u rt	          d          t          |          r|                     |          S t          |t                    r|                                 |         }n{t          |t                    r|j	        |j	        dk    r(|j
        dn|j
        }|dk     r|t          |           z  }|j        t          |           n|j        }|dk     r|t          |           z  }| j        j        }t          j        ||k    ||k     z            }| j        |         }||                                         }|dk    r||z  }t          t'          t          |                     |                   }	t)          |	|| j                  }
t-          |                               ||
| j                  S t          j        t          |           t          j                  |         }|                     |          S t9          |          st;          d          t          |t<                    rt?          |          rtA          |j!                  r*|                     |j        j        |j                           S |j!        s|                     |j        j                  S t          |           }t          j"        |dt          j#                  }d||j        j        <   |                     t          j        |          |                   S t          j$        |          }tK          | |          }tM          j'        |          r`tQ          t          j)        |          }|                     t          j        t          |          t          j                  |                   S tU          |d          r|                     |          S t	          d	| d
           t-          |           || j                  S )NzCannot slice with Ellipsisrm   r   rV   zuonly integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indicesTFr   zCannot slice with 'r   r   )+r   tupler0   r:   r\   r   _get_val_atr   slicestepstartr   stopr}   r   rX   flatnonzeror   rh   rangemake_sparse_indexr   r   r   rW   arangeint32taker   
IndexErrorrQ   r   r%   rZ   r   r  rY   r/   comis_bool_indexerr	   r   hasattr)r   r   
data_slicerQ  endr   	keep_indsr   r}   new_lennew_sp_indexnr   s                r=   rF  zSparseArray.__getitem__  s    c5!! 	?+C00Ch ? !=>>>c?? Q	?##C(((U## O	? -JJU## D	?x *38q= * Y=CI19 'SYY&E#&8Ac$iii7 %3t99$C-/NGu,<3+OPP	.3"9-2244 19 &%H eCII..s3440(DINNDzz--g|TZPPP)CIIRX>>>sCyy)))c"" #	? L   #{++ *
 !%% 
*CN++ N#yy)=cm)LMMM> ?#yy)=>>>D		A71d"(;;;D16D-.99RYq\\$%7888*S//C%dC00C"3'' ?2:s++yy3s8828!D!D!DS!IJJJi(( ?yy~~% !=s!=!=!=>>>tDzz*495555r<   c                    t          |t          |                     }| j                            |          }|dk    r| j        S | j        |         }t          || j        j                  }|S )Nr!  )r   r   r}   lookuprZ   r   r   rW   )r   locsp_locvals       r=   rN  zSparseArray._get_val_at  se    !#s4yy11%%c**R< 	?".(C(dn.BCCCJr<   )
allow_fillrZ   rh  c                  t          |          rt          d| d          t          j        |t          j                  }d }|j        dk    rt          j        g d          }| j        }n/|r|                     ||          }n| 	                    |          S  t          |           || j        | j        |          S )Nz*'indices' must be an array, not a scalar 'z'.rV   r   r   r  )rZ   r   rW   )r   r\   rX   rY   rW  sizer   rW   _take_with_fill_take_without_fillr   rZ   r   )r   r   rh  rZ   rW   r   s         r=   rX  zSparseArray.take  s    W 	WU'UUUVVV*WBH555<1 	4Xb111FJEE 	4))'j)IIFF**7333tDzztTYe
 
 
 	
r<   c                v   || j         j        }|                                dk     rt          d          |                                t          |           k    rt          d          t          |           dk    r{|dk                                    rTt          j	        | j
        t          |                    }t          j        ||          }|                    |           |S t          d          | j                            |          }|dk    }|dk    | z  }| j        j        dk    rA|                                r-t          j        |j        | j        | j         j                  }nF| j        j        dk    rSt          j	        | j         j        t          |                    }t          j        |j        ||          }| j        ||<   n| j
                            |          }||         dk     }	||         dk     }
|j         }|	                                rFt          j	        |t          | j                            }|                    |          }| j        ||<   |
                                r<t          j	        |t          |                    }|                    |          }|||<   |S )Nr!  zKInvalid value in 'indices'. Must be between -1 and the length of the array.!out of bounds value in 'indices'.r   rV   .cannot do a non-empty take from an empty axes.r  )rW   r  r  r\   maxr   rY  rk   rX   r   r   r   
empty_liker   r}   lookup_arrayr   r   r   rZ   r[   rX  r   r|   )r   r   rZ   rW   taken
sp_indexernew_fill_indicesold_fill_indicesr   m0m1r   s               r=   rk  zSparseArray._take_with_fill%  s    	-,J;;==2 	/  
 ;;==CII% 	B@AAAt99> 	S2""$$ St~tJ7G7GHHgU;;;

:&&& !QRRR
 ]//88
"b=&",1A0AA= A%  	5*:*>*>*@*@  	5G T_DJDV  EE ]"a' 	5^DJ$6Z8H8HIIFGJ,6RRRE&*oE"##N''
33E ,-1B,-1B+Kvvxx : n[$t:O:OPP[11*./&'vvxx 5 n[$z:J:JKK[11*4&'r<   c                   |dk     }t          |           }|                                |k    s|                                | k     r$|dk    rt          d          t          d          |                                r$|                                }||xx         |z  cc<   | j                            |          }|dk    }| j        ||                  }t          j
        |                              t          j        d          }t          t          |          || j                  }t          |                               ||| j                  S )	Nr   ro  rn  r!  Frg   rL  rV   )r   rp  r  rY  r   rh   r}   rr  r   rX   rS  r|   rW  rU  r   r   r   rW   )	r   r   to_shiftrb  rt  
value_masknew_sp_valuesvalue_indicesra  s	            r=   rl  zSparseArray._take_without_fillg  s:   Q;IIKKMMQ 	BGKKMMQB$6 	BAv S !QRRR@AAA<<>> 	#llnnGH"]//88
2%
z*'=>z2299"(9OO(W}49UUUDzz%%m\%TTTr<   r^   vArrayLike | objectsideLiteral['left', 'right']sorterNumpySorter | Nonenpt.NDArray[np.intp] | np.intpc                    d}t          j        |t          t                                 t	          j        |          }t	          j        | | j        j                                      |||          S )Nz(searchsorted requires high memory usage.r   rV   )	r   r   r   r   rX   rY   rW   r[   searchsorted)r   r~  r  r  r   s        r=   r  zSparseArray.searchsorted~  sb     9c-:J:L:LMMMMJqMMz$dj&8999FFq$PVWWWr<   c                v    | j                                         }|                     || j        | j                  S r   )r   rh   r   r}   rW   )r   r   s     r=   rh   zSparseArray.copy  s1    $$&&tzBBBr<   	to_concatSequence[Self]c                t   |d         j         }g }d}|r|d         j        }nd}|dk    rg }|D ]c}|j        j                                        }||z  }||j        j        z  }|                    |j                   |                    |           dt          j	        |          }	t          j	        |          }
t          ||
          }ng }g }|D ]}|j                                        }|                    |j                   |                    |j                                        |z              |                    |j                   ||j        j        z  }t          j	        |          }	t          j	        |          }t          j	        |          }t          |||          } | |	||          S )Nr   rA   r   rZ   )rZ   r   r}   r   rh   r   appendr   rX   concatenater   to_block_indexblocsblengthsr   )r   r  rZ   r   r   sp_kindr   rR   int_idxr   indices_arrr}   r  r  	block_idx	blocs_arrblengths_arrs                    r=   r  zSparseArray._concat_same_type  s   q\,
 	 l'GGG i '	CG  ( (,.33556!#,--cm,,,w''''>&))D.11K  44HH HE  . .L7799	cm,,,Y_1133f<===	 2333#,-->&))Du--I>(33L!&)\BBHs4h:FFFFr<   AstypeArg | Nonec                6   || j         k    r|s| S |                                 S t          |          }t          |t                    s5t          j        |           }t          |          }t          ||d          S | j	        
                    |          }t          |j                  }t          t
          j	        |          }t          | j                  }t          |||          }t          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   rg   )r   rh   r    r   r"   rX   rY   r,   r   rW   update_dtype_subtype_with_strr	   r   r   r}   )r   rW   rh   future_dtyper   r[   r   s          r=   r|   zSparseArray.astype  s   r DK 	# #yy{{"#E**,44 	HZ%%F3F;;FlGGGG
''..u677rx))/?? t<<<	Jy))		4=%@@@r<   c                6   t          t          j        t          f          | j        |t                    r#r                              n
           fdfd| j        D             } t          |           || j	                  S )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)
        Nc                    r                     | d           n
 |           }|u s|k    rd}t          |          |S )Nz-fill value in the sparse values not supported)getr\   )sp_val
new_sp_valr   fill_valis_mapmappers      r=   funczSparseArray.map.<locals>.funcC  sX    5;OFD111JX% &x)? &E oo%r<   c                &    g | ]} |          S r;   r;   ).0xr  s     r=   
<listcomp>z#SparseArray.map.<locals>.<listcomp>K  s!    555TT!WW555r<   r  )
r   r   Mappingr$   rZ   r'   r  r   r   r}   )r   r  	na_actionr   r  r  r  s    `  @@@r=   mapzSparseArray.map  s    P FS[)$<==? 	Vh 	V9?Uvzz(H555VVHEUEUH	 	 	 	 	 	 	 6555dn555	tDzz)$-HUUUUr<   c                B    t          j        | | j        j                  S )zr
        Convert SparseArray to a NumPy array.

        Returns
        -------
        arr : NumPy array
        rV   )rX   rY   r   rW   r   s    r=   r   zSparseArray.to_denseO  s     z$dn&:;;;;r<   c                    t          j        || |          }t          |j        | j                  }t          |                               ||          }|S )Nr  rV   )rX   r  r"   rW   rZ   r   r   )r   r   r   naive_implementationrW   r   s         r=   _wherezSparseArray._whereY  sT      "xdE::064?SSSd**+?u*MMr<   c                   t          |t                    r[|\  }\  }}t          j        g           }|                    |           || _        || _        t          |j        |          | _	        dS | j
                            |           dS )z*Necessary for making this object picklableN)r   rM  rX   r   __setstate__r   r   r"   rW   r   __dict__update)r   statend_staterZ   r}   r   s         r=   r  zSparseArray.__setstate__d  s    eU## 
	(/4,H,z8HRLLM&&x000"/D!)D%m&9:FFDKKKM  '''''r<   tuple[npt.NDArray[np.int32]]c                j    | j         dk    r| j        j        fS | j        j        | j        dk             fS )Nr   )rZ   r}   r   r   r   s    r=   nonzerozSparseArray.nonzeror  s:    ?a 	AM)++M)$.A*=>@@r<   )skipnakeepdimsra   rb   r  r  c                  t          | |d           }|t          d| d| j                   |r| }n|                                 } t          ||          di |}|r  t	          |           |g| j                  S |S )Nzcannot perform z with type rV   r;   )r   r   rW   r;  r   )r   ra   r  r  kwargsr  rR   r   s           r=   _reducezSparseArray._reduce|  s     tT** 	MKdKKtzKKLLL 	 CC++--C#d##--f-- 	4::vhdj9999Mr<   c                    t          j        ||           | j        }t          |          t          |           k    rt	          j        | j                  sdS |                                S )z
        Tests whether all elements evaluate True

        Returns
        -------
        all : bool

        See Also
        --------
        numpy.all
        F)nvvalidate_allr   r   rX   rk   rZ   r   axisargsr  r   s        r=   rk   zSparseArray.all  s\     	f%%%v;;#d))# 	BF4?,C,C 	5zz||r<   r   r  rF   c                    t          j        ||           | j        }t          |          t          |           k    rt	          j        | j                  rdS |                                                                S )z
        Tests whether at least one of elements evaluate True

        Returns
        -------
        any : bool

        See Also
        --------
        numpy.any
        T)r  validate_anyr   r   rX   r   rZ   r   r  s        r=   r   zSparseArray.any  sh     	f%%%v;;#d))# 	t(?(? 	4zz||  """r<   	min_countrJ   c                   t          j        ||           | j        }|                                }| j        j        dk    o| j         }|r|st          | j        j	        d          S | j        r3t          |j        d|          rt          | j        j	        d          S |S | j        j        }	t          |j        d||	z
            rt          | j        j	        d          S || j        |	z  z   S )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
        r   FcompatN)r  validate_sumr   sumr}   r~   r   r&   rW   r[   r1   r   rZ   )
r   r  r  r  r  r  
valid_valssp_sumhas_nansparses
             r=   r  zSparseArray.sum  s   4 	f%%%*
!!$q(F1F-F 	H& 	H%dj&8GGGG  	6$Z%5tYGG L)$**<UKKKKMm)G$Z%5tY=PQQ L)$**<UKKKKDOg555r<   c                F   t          j        ||           ||| j        k    rt          d| d          | j        s3t          |                                                                           S t          | j                                        | 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
        Nzaxis(=z) out of boundsr  )r  validate_cumsumndimr\   r   rQ   r   cumsumr   r}   rZ   )r   r  r  r  s       r=   r  zSparseArray.cumsum  s    $ 	4((( 	=	 1 	=;d;;;<<<$ 	9t}}//66888N!!##
 
 
 	
r<   rE   c                    t          j        ||           | j        }|                                }t	          |          }| j        r||z  S | j        j        }|| j        |z  z   ||z   z  S )zb
        Mean of non-NA/null values

        Returns
        -------
        mean : float
        )	r  validate_meanr   r  r   r   r}   r~   rZ   )r   r  r  r  r  r  ctr  s           r=   meanzSparseArray.mean  st     	v&&&*
!!__  	IB;m)GT_w662<HHr<   )r  r  AxisInt | Nonec               d    t          j        || j                   |                     d|          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
        rp  r  r  validate_minmax_axisr  _min_maxr   r  r  s      r=   rp  zSparseArray.max  /     	di000}}U6}222r<   c               d    t          j        || j                   |                     d|          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  zSparseArray.min+  r  r<   Literal['min', 'max']c                   | j         }| j         o| j        j        dk    }t	          |          dk    rp t          ||                      }|r%|dk    rt          nt          } ||| j                  S |r|S | j        j        dk    r|S t          | j
        j        d          S |r| j        S t          | j
        j        d          S )z
        Min/max of non-NA/null values

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

        Returns
        -------
        scalar
        r   rp  Fr  )r   r   r}   r~   r   r   rp  r  rZ   r&   rW   r[   )r   r   r  r  has_nonnull_fill_vals
sp_min_maxr  s          r=   r  zSparseArray._min_max=  s     *
$($9 9 Udm>QTU>Uz??Q 	H2T2244J % 	L"em4sstJ888 L!!$) L!!)$**<UKKKK" 	H?"%dj&8GGGGr<   Literal['argmin', 'argmax']c                   | j         }| j        j        }t          j        t          |                    }|dk    rt          j        nt          j        }t          j        |j	        d                   }||          }||          }| ||                   }	||	         }
t          | j
                  r|
S |dk    r| |
         | j
        k     r|
S |dk    r| |
         | j
        k    r|
S |                                 }|dk    r|
S |S )Nr$  r   argminr!  )r   r   r   rX   rY   r%   r$  r  rV  r   rZ   r%  )r   r   r   r   r   r  r   non_nansnon_nan_idx
_candidate	candidate_locs               r=   _argmin_argmaxzSparseArray._argmin_argmax`  s   $"*z$v,,'' H,;ryy")iQ((4%=4%j h0
*%	   	8 	Y$/ A 	8 	Y$/ A 	))++2: 	Kr<   c                l    t          |d           |s| j        rt          |                     d          S )Nr  r$  r   _hasnaNotImplementedErrorr  r   r  s     r=   r$  zSparseArray.argmaxz  =    FH--- 	&$+ 	&%%""8,,,r<   c                l    t          |d           |s| j        rt          |                     d          S )Nr  r  r  r  s     r=   r  zSparseArray.argmin  r  r<   ufuncnp.ufuncc                    |                     dd          }||z   D ])}t          | j        t          fz             s	t          c S *t          j         ||g|R i |}|t          ur|S d|v rt          j         ||g|R i |}|S |dk    r"t          j         ||g|R i |}|t          ur|S t          |          dk    r t          ||           j        fi |}	 t          ||           j        fi |}
|j        dk    r+t           fdt          |	|
          D                       }|S |dk    r|	S                      |	 j        t%          |	j        |
                    S t          d |D                       } t          ||          |i |}|rt          |          dk    r|d         }|S |j        dk    rt           fd|D                       S |d	k    rd S  t)                     |          S )
Nr   r;   reducerm   c           	   3  |   K   | ]6\  }}                     |j        t          |j        |                    V  7d S r   )r   r}   r"   rW   )r  sp_valuefvr   s      r=   	<genexpr>z.SparseArray.__array_ufunc__.<locals>.<genexpr>  sb         %" $$ $-X^R1P1P      r<   c              3  >   K   | ]}t          j        |          V  d S r   )rX   rY   )r  r  s     r=   r  z.SparseArray.__array_ufunc__.<locals>.<genexpr>  s*      99Q2:a==999999r<   r   c              3  H   K   | ]} t                    |          V  d S r   )r   )r  r  r   s     r=   r  z.SparseArray.__array_ufunc__.<locals>.<genexpr>  s1      771dA777777r<   at)r  r   _HANDLED_TYPESrQ   NotImplementedr(   !maybe_dispatch_ufunc_to_dunder_opdispatch_ufunc_with_outdispatch_reduction_ufuncr   r   r   rZ   noutrM  zipr   r}   r"   rW   r   )r   r  r  inputsr  r   r  r   resr   rZ   arrays
new_inputss   `            r=   __array_ufunc__zSparseArray.__array_ufunc__  s   jj### 	& 	&Aa!4~!EFF &%%%%& <%
"(
 
 
,2
 
 ' 	MF? 	3eV&,  06 C JX 	7eV&,  06 F ^+ v;;! 	.v..t~HHHHI///JJ6JJJzA~ !     ),Iz(B(B	     8# !  ##4=+ioz*R*R   99&99999
'''>v>> 	3xx1} !fJ:> 	&7777777777t^ 	&44::f%%%r<   c           	        |j         }t          |t                    rt          | |||          S t	          |          rt          j        d          5   |t          |           t          j        |                    } || j	        |          }d d d            n# 1 swxY w Y   |dk    r8|\  }}|\  }}	t          ||| j        |          t          ||| j        |	          fS t          ||| j        |          S t          j        |          }t          j        d          5  t          |           t          |          k    r/t          dt          |            dt          |                     t          |t                    s(t          |dd           }
t          || j        |
          }t          | |||          cd d d            S # 1 swxY w Y   d S )Nri   rj   rz   zlength mismatch: z vs. rW   r  )r7   r   rQ   r   r   rX   r   r]   rY   r   r   r}   r   r   r   rZ   )r   otherr`   op_namer   r   r^   r_   lfillrfillrW   s              r=   _arith_methodzSparseArray._arith_method  sz   +e[)) 	B#D%W===u 	B*** 3 3r)D//2:e+<+<==DNE223 3 3 3 3 3 3 3 3 3 3 3 3 3 3 (" $e#u $uEE %FF 
  EEE Ju%%E*** B Bt99E

* (HCIIHHCJJHH   "%55 X#E7D99E'$/QVWWWE'eRAAB B B B B B B B B B B B B B B B B Bs%   =BB #B %BGGGc                   t          |          s1t          |t          |                     st          j        |          }t          |t          j                  rt          || j                  }t          |t                    r{t          |           t          |          k    r/t          dt          |            dt          |                     |j
                            d          }t          | |||          S  || j        |          }t          j        t          |           |t          j                  } || j        |          || j        j        <    t          |           ||t          j                  S )Nr  z operands have mismatched length z and rt   rV   r  )r   r   r   rX   rY   r   rQ   rZ   r   r\   r7   stripr   r   r  r   r}   r   )r   r  r`   r  rZ   r   s         r=   _cmp_methodzSparseArray._cmp_method  sb    	&
5$t**(E(E 	&Ju%%EeRZ(( 	C$/BBBEe[)) 	4yyCJJ&  Ss4yySSs5zzSS   k'',,G#D%W=== DOU33JWSYY
"(CCCF,.Bt~u,E,EF4=()4::%h   r<   c                    |t          j        | j                                                            }t	          | j        j        |          }t          | j                  s|| j        k    r> || j                  }t          |           
                    || j        | j                  S  t          |            ||                                           |          S r   )rX   r   rZ   r   r"   rW   r[   r%   r   r   r   r}   r   )r   r`   rZ   rW   r   s        r=   _unary_methodzSparseArray._unary_method  s    R11227799
DJ.
;;    	MJ$/$A 	MR''F::))&$-LLLtDzz""T]]__--U;;;;r<   c                @    |                      t          j                  S r   )r  operatorposr   s    r=   __pos__zSparseArray.__pos__      !!(,///r<   c                @    |                      t          j                  S r   )r  r  negr   s    r=   __neg__zSparseArray.__neg__   r  r<   c                @    |                      t          j                  S r   )r  r  invertr   s    r=   
__invert__zSparseArray.__invert__#  s    !!(/222r<   c                @    |                      t          j                  S r   )r  r  r  r   s    r=   __abs__zSparseArray.__abs__&  r  r<   c                    t          j        |           }t          j        | j                  }t          j        | j                  }| d| d| S )Nz
Fill: 
)r2   pprint_thingrZ   r}   )r   pp_strpp_fillpp_indexs       r=   __repr__zSparseArray.__repr__,  sR    &t,,'88(7777'77X777r<   boxedc                    d S r   r;   )r   r+  s     r=   
_formatterzSparseArray._formatter2  s	     tr<   )NNrA   NF)r   r   rW   r   rh   rq   rS   r   )r   rT   r   r   rW   r"   rS   rL   )r   r>   rS   rL   )NN)rW   r   rh   r   rS   rT   )rS   r   )rW   r   rh   rq   )rS   r   )rS   rT   )rS   r"   )rS   r   )rS   r   )rS   rq   )rS   r   )rS   rL   )
r  r?   r  r	  r  r
  rh   rq   rS   rL   )NNNT)r  r  r  r	  rh   rq   rS   rL   )rm   N)r  r   rS   rL   )r&  )r'  r(  rS   r)  )T)r5  rq   rS   r6  )r;  rq   rS   rO   )r   rK   rS   r   )r   rG  rS   rL   )r   rI  rS   rJ  )rh  rq   rS   rL   r   )r^   N)r~  r  r  r  r  r  rS   r  )r  r  rS   rL   )NT)rW   r  rh   rq   )rS   r  )ra   rb   r  rq   r  rq   )r   )r  rF   rS   rq   )r   r   T)r  rF   r  r   r  rq   rS   rJ   )r  rF   rS   rQ   )r  rE   )r  r  r  rq   )r   r  r  rq   rS   rJ   )r   r  rS   r   )r  rq   rS   r   )r  r  r  rb   )rS   rQ   )rS   rb   )F)r+  rq   )Wr7   r8   r9   __doc___subtypr+   _hidden_attrs	frozenset__annotations__r   classmethodr   r   r   r   r   r   propertyr}   r   rW   rZ   setterr   r   r   r   r   r   r  r   r%   r  r  r  r%  r   r*   r,  r.  r4  r8  rC  r
   rF  rN  rX  rk  rl  r  rh   r  r|   r  r   r  r  r  r  rk   r   r  r  r  rp  r  r  r  r$  r  rX   r   numbersNumberr   r  r  r  _logical_methodr  r  r  r!  r#  r*  r-  __classcell__)r  s   @r=   rQ   rQ     s         D DL G .2>M
  )"CC CC CC CC CCJ 
 
 
 [
 )2 )2 )2 [)2X AE    6    >BQV ) ) ) ) ) [) 1 1 [1 " " " X" # # # X#    X % % X%$ = = = =    X    X
$ $ $ $ - - - X-1 1 1 1 < < < X< < < < X< % % % X%? ? ? ? !:>
 
 
 
 
 
 
 
  '+ ;K ;K ;K ;K ;K ;K ;Kz- - - - -60 0 0* 	S	"##6=> > > > $#>D D D D1 1 1 !%! ! ! ! !&7 &7 &7 &7 &7V    X    X\6 \6 \6 \6|	 	 	 38D 
 
 
 
 
 
$@ @ @ @ @DU U U U4 *0%)		X 	X 	X 	X 	XC C C C 5G 5G 5G [5GnMA MA MA MA MA^9V 9V 9V 9V 9Vv< < < <  ( ( ( (A A A A ,0%     (   *# # # # #. 	*6 *6 *6 *6 *6X
 
 
 
 
@I I I I I& -1 3 3 3 3 3 3$ -1 3 3 3 3 3 3$!H !H !H !HF   4- - - - -- - - - - j'.1N@& @& @& @&LB B BB   : "O	< 	< 	< 	<0 0 0 00 0 0 03 3 3 30 0 0 08 8 8 8        r<   rB   r   r   np.dtype | Nonec                   t          | t          j                  sJ | j        dk    rt	          d          |t          | j                  }t          |          rt          |           }n^t          | j                  r| 
                    t                    } t          | j                  rt          j        | |          }n| |k    }t          |           }|t          |          k    r|j        j        }n7|                                d         
                    t          j                  }t)          |||          }| |         }|4t+          |          }t-          ||          }t          j        |          }|||fS )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)
    rm   zexpected dimension <= 1 dataNr   rV   )r   rX   r   r  r   r&   rW   r%   r'   r   r|   r   r   r   make_mask_object_ndarrayr   r}   r   r  rW  rU  r,   r   rY   )	rR   r   rZ   rW   r   r   r   r   sparsified_valuess	            r=   r   r   8  sv   * c2:&&&&&
x!| 86777 3'	22
J %Szz 39%% 	%**V$$C39%% 	% 1#zBBDD*$DXXFT 5-',,..#**2844fgt44ED	 ::;LMM():%HHHJ'899 eZ//r<   r   r   Literal['block']r   c                    d S r   r;   r   r   r   s      r=   rU  rU  v      Cr<   Literal['integer']r   c                    d S r   r;   r@  s      r=   rU  rU  {  rA  r<   r   c                    |dk    r)t          j        |          \  }}t          | ||          }n&|dk    rt          | |          }nt	          d          |S )NrB   rA   zmust be block or integer type)r   
get_blocksr   r   r\   )r   r   r   locslensr   s         r=   rU  rU    sg    w :%g..
d64..		 :))8999Lr<   )rR   rQ   rS   rT   )
r^   rQ   r_   rQ   r`   r   ra   rb   rS   rQ   r   )ra   rb   rW   r   rS   rQ   )rB   NN)rR   rT   r   r   rW   r:  )r   r   r   r>  rS   r   )r   r   r   rB  rS   r   )r   r   r   r   rS   r   )|r.  
__future__r   collectionsr   r6  r  typingr   r   r   r   r	   r
   r   numpyrX   pandas._libsr   pandas._libs.sparse_libssparser   r   r   r   pandas._libs.tslibsr   pandas.compat.numpyr   r  pandas.errorsr   pandas.util._decoratorsr   pandas.util._exceptionsr   pandas.util._validatorsr   r   pandas.core.dtypes.astyper   pandas.core.dtypes.castr   r   r   pandas.core.dtypes.commonr   r   r   r   r   r   r    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commonrZ  pandas.core.constructionr,   r-   r.   pandas.core.indexersr/   r0   pandas.core.nanopsr1   pandas.io.formatsr2   collections.abcr3   enumr4   r6   r:   scipy.sparser>   pandas._typingr?   r@   r   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   r>  rO   r   _sparray_doc_kwargsr]   r   r   rQ   r   rU  r;   r<   r=   <module>rn     s&    # " " " " "                                   # # # # # # # # #         
 $ # # # # # . . . . . . , , , , , , ' ' ' ' ' ' 4 4 4 4 4 4       
 3 2 2 2 2 2         
                                         " ! ! ! ! ! & & & & & & & & & * * * * * * - - - - - - ) ) ) ) ) )                           
        5 4 4 4 4 4 & & & & & &  $((((((    4     H%%%%%%       
 01O                             tH~~H . * * * *0iG iG iG iGZ FJ    .V V V V V(L. V V Vv0 $!	;0 ;0 ;0 ;0 ;0| 
   
 
   
	 	 	 	 	 	r<   