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 :  /Python312/Lib/site-packages/pandas/core/arrays/sparse/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

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

-	�g�0����dZddlmZddlmZddlZddlmZddl	m
Z
ddlmZddl
mZmZdd	lmZerdd
lmZmZGd�d�Zeegd
�d��Gd�dee��ZGd�dee�Zy)zSparse accessor�)�annotations)�
TYPE_CHECKINGN)�import_optional_dependency)�find_common_type)�SparseDtype)�PandasDelegate�delegate_names)�SparseArray)�	DataFrame�Seriesc� �eZdZdZddd�Zd�Zy)�BaseAccessorz5Can only use the '.sparse' accessor with Sparse data.Nc�4�||_|j|�y�N)�_parent�	_validate��self�datas  �DC:\Python312\Lib\site-packages\pandas/core/arrays/sparse/accessor.py�__init__zBaseAccessor.__init__s��������t��c��t�r)�NotImplementedErrorrs  rrzBaseAccessor._validate!s��!�!rr)�return�None)�__name__�
__module__�__qualname__�_validation_msgrr�rrrrs��M�O��"rr)�npoints�density�
fill_value�	sp_values�property)�typc�L�eZdZdZd�Zd	d�Zd	d�Zed
dd��Zdd
d�Z	dd�Z
y)�SparseAccessorz�
    Accessor for SparseSparse from other sparse matrix data types.

    Examples
    --------
    >>> ser = pd.Series([0, 0, 2, 2, 2], dtype="Sparse[int]")
    >>> ser.sparse.density
    0.6
    >>> ser.sparse.sp_values
    array([2, 2, 2])
    c�b�t|jt�st|j��yr)�
isinstance�dtyper�AttributeErrorr rs  rrzSparseAccessor._validate5s&���$�*�*�k�2� ��!5�!5�6�6�3rc�B�t|jj|�Sr)�getattrr�array�r�name�args�kwargss    r�_delegate_property_getz%SparseAccessor._delegate_property_get9s���t�|�|�)�)�4�0�0rc�j�|dk(r|j|i|��S|dk(r|j|i|��St�)N�from_coo�to_coo)r7r8�
ValueErrorr1s    r�_delegate_methodzSparseAccessor._delegate_method<sD���:�� �4�=�=�$�1�&�1�1�
�X�
��4�;�;��/��/�/��rc�p�ddlm}ddlm}|||��}||j|j
d��}|S)ae
        Create a Series with sparse values from a scipy.sparse.coo_matrix.

        Parameters
        ----------
        A : scipy.sparse.coo_matrix
        dense_index : bool, default False
            If False (default), the index consists of only the
            coords of the non-null entries of the original coo_matrix.
            If True, the index consists of the full sorted
            (row, col) coordinates of the coo_matrix.

        Returns
        -------
        s : Series
            A Series with sparse values.

        Examples
        --------
        >>> from scipy import sparse

        >>> A = sparse.coo_matrix(
        ...     ([3.0, 1.0, 2.0], ([1, 0, 0], [0, 2, 3])), shape=(3, 4)
        ... )
        >>> A
        <COOrdinate sparse matrix of dtype 'float64'
            with 3 stored elements and shape (3, 4)>

        >>> A.todense()
        matrix([[0., 0., 1., 2.],
        [3., 0., 0., 0.],
        [0., 0., 0., 0.]])

        >>> ss = pd.Series.sparse.from_coo(A)
        >>> ss
        0  2    1.0
           3    2.0
        1  0    3.0
        dtype: Sparse[float64, nan]
        r�r)�coo_to_sparse_series)�dense_indexF)�index�copy)�pandasr�&pandas.core.arrays.sparse.scipy_sparser=r0r?)�cls�Ar>rr=�results      rr7zSparseAccessor.from_cooDs2��T	"�O�%�a�[�A������F�L�L�u�E���
rc�L�ddlm}||j|||��\}}}|||fS)a�
        Create a scipy.sparse.coo_matrix from a Series with MultiIndex.

        Use row_levels and column_levels to determine the row and column
        coordinates respectively. row_levels and column_levels are the names
        (labels) or numbers of the levels. {row_levels, column_levels} must be
        a partition of the MultiIndex level names (or numbers).

        Parameters
        ----------
        row_levels : tuple/list
        column_levels : tuple/list
        sort_labels : bool, default False
            Sort the row and column labels before forming the sparse matrix.
            When `row_levels` and/or `column_levels` refer to a single level,
            set to `True` for a faster execution.

        Returns
        -------
        y : scipy.sparse.coo_matrix
        rows : list (row labels)
        columns : list (column labels)

        Examples
        --------
        >>> s = pd.Series([3.0, np.nan, 1.0, 3.0, np.nan, np.nan])
        >>> s.index = pd.MultiIndex.from_tuples(
        ...     [
        ...         (1, 2, "a", 0),
        ...         (1, 2, "a", 1),
        ...         (1, 1, "b", 0),
        ...         (1, 1, "b", 1),
        ...         (2, 1, "b", 0),
        ...         (2, 1, "b", 1)
        ...     ],
        ...     names=["A", "B", "C", "D"],
        ... )
        >>> s
        A  B  C  D
        1  2  a  0    3.0
                 1    NaN
           1  b  0    1.0
                 1    3.0
        2  1  b  0    NaN
                 1    NaN
        dtype: float64

        >>> ss = s.astype("Sparse")
        >>> ss
        A  B  C  D
        1  2  a  0    3.0
                 1    NaN
           1  b  0    1.0
                 1    3.0
        2  1  b  0    NaN
                 1    NaN
        dtype: Sparse[float64, nan]

        >>> A, rows, columns = ss.sparse.to_coo(
        ...     row_levels=["A", "B"], column_levels=["C", "D"], sort_labels=True
        ... )
        >>> A
        <COOrdinate sparse matrix of dtype 'float64'
            with 3 stored elements and shape (3, 4)>
        >>> A.todense()
        matrix([[0., 0., 1., 3.],
        [3., 0., 0., 0.],
        [0., 0., 0., 0.]])

        >>> rows
        [(1, 1), (1, 2), (2, 1)]
        >>> columns
        [('a', 0), ('a', 1), ('b', 0), ('b', 1)]
        r)�sparse_series_to_coo)�sort_labels)rBrGr)r�
row_levels�
column_levelsrHrGrD�rows�columnss        rr8zSparseAccessor.to_coovs6��V	P�/��L�L�*�m��
���4���$���rc��ddlm}||jjj	�|jj
|jjd��S)a�
        Convert a Series from sparse values to dense.

        Returns
        -------
        Series:
            A Series with the same values, stored as a dense array.

        Examples
        --------
        >>> series = pd.Series(pd.arrays.SparseArray([0, 1, 0]))
        >>> series
        0    0
        1    1
        2    0
        dtype: Sparse[int64, 0]

        >>> series.sparse.to_dense()
        0    0
        1    1
        2    0
        dtype: int64
        rr<F)r?r2r@)rArrr0�to_denser?r2)rrs  rrNzSparseAccessor.to_dense�sG��0	"���L�L���'�'�)��,�,�$�$����"�"��	
�	
rN)r2�str)F)r>�boolrr))r)�F)rHrP)rr)rrr�__doc__rr5r:�classmethodr7r8rNr!rrr)r)%s7��
�7�1���/��/�bP �d
rr)c�Z�eZdZdZd�Zed	d
d��Zd
d�Zd�Ze	dd��Z
ed��Zy)�SparseFrameAccessorz�
    DataFrame accessor for sparse data.

    Examples
    --------
    >>> df = pd.DataFrame({"a": [1, 2, 0, 0],
    ...                   "b": [3, 0, 0, 4]}, dtype="Sparse[int]")
    >>> df.sparse.density
    0.5
    c�j�|j}td�|D��st|j��y)Nc3�<K�|]}t|t����y�wr)r+r)�.0�ts  r�	<genexpr>z0SparseFrameAccessor._validate.<locals>.<genexpr>�s����>�!�:�a��-�>�s�)�dtypes�allr-r )rrr[s   rrzSparseFrameAccessor._validate�s/�������>�v�>�>� ��!5�!5�6�6�?rNc��ddlm}ddlm}|j	�}|j|||�\}}|j\}}|j�|j}|j}	|j}
t|
jd�}g}t|�D]P}
t|	|
|	|
dz�}||||d��}tj |
|||�}|j#|��R|j$|||d��S)a�
        Create a new DataFrame from a scipy sparse matrix.

        Parameters
        ----------
        data : scipy.sparse.spmatrix
            Must be convertible to csc format.
        index, columns : Index, optional
            Row and column labels to use for the resulting DataFrame.
            Defaults to a RangeIndex.

        Returns
        -------
        DataFrame
            Each column of the DataFrame is stored as a
            :class:`arrays.SparseArray`.

        Examples
        --------
        >>> import scipy.sparse
        >>> mat = scipy.sparse.eye(3, dtype=float)
        >>> pd.DataFrame.sparse.from_spmatrix(mat)
             0    1    2
        0  1.0    0    0
        1    0  1.0    0
        2    0    0  1.0
        r)�IntIndex�rrQF)�check_integrity)rLr?�verify_integrity)�pandas._libs.sparser^rAr�tocsc�_prep_index�shape�sort_indices�indices�indptrrrr,�range�slicer
�_simple_new�append�_from_arrays)rCrr?rLr^r�n_rows�	n_columnsrgrh�
array_datar,�arrays�i�sl�idx�arrs                 r�
from_spmatrixz!SparseFrameAccessor.from_spmatrix�s���:	1�$��z�z�|������u�g�>���w� �J�J���	�
	
�����,�,�������Y�Y�
��J�,�,�a�0�����y�!�	�A��v�a�y�&��Q��-�0�B��6�7�2�;��F�C��)�)�*�R�.�#�u�E�C��M�M�#��		�
&�y�%�%��G�5�5�
�	
rc�
�ddlm}|jj�D��cic] \}}||jj���"}}}|||jj|jj��Scc}}w)ay
        Convert a DataFrame with sparse values to dense.

        Returns
        -------
        DataFrame
            A DataFrame with the same values stored as dense arrays.

        Examples
        --------
        >>> df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1, 0])})
        >>> df.sparse.to_dense()
           A
        0  0
        1  1
        2  0
        rr_)r?rL)rArr�itemsr0rNr?rL)rr�k�vrs     rrNzSparseFrameAccessor.to_dense2sf��$	%�26�,�,�2D�2D�2F�G�$�!�Q��1�7�7�#�#�%�%�G��G���T�\�\�%7�%7����AU�AU�V�V��Hs�%A?c	�.�td�ddlm}t|jj
j
��}t|t�r|j}ggg}}}t|jj��D]�\}\}}|j}	|	jdk7rtd��|	jj }
|j#t%j&|t)|
���|j#|
�|j#|	j*j-|d�����t%j.|�}t%j.|�}t%j.|�}||||ff|jj0��S)a�
        Return the contents of the frame as a sparse SciPy COO matrix.

        Returns
        -------
        scipy.sparse.spmatrix
            If the caller is heterogeneous and contains booleans or objects,
            the result will be of dtype=object. See Notes.

        Notes
        -----
        The dtype will be the lowest-common-denominator type (implicit
        upcasting); that is to say if the dtypes (even of numeric types)
        are mixed, the one that accommodates all will be chosen.

        e.g. If the dtypes are float16 and float32, dtype will be upcast to
        float32. By numpy.find_common_type convention, mixing int64 and
        and uint64 will result in a float64 dtype.

        Examples
        --------
        >>> df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1, 0, 1])})
        >>> df.sparse.to_coo()
        <COOrdinate sparse matrix of dtype 'int64'
            with 2 stored elements and shape (4, 1)>
        �scipyr)�
coo_matrixz2fill value must be 0 when converting to COO matrixF)r@)re)r�scipy.sparser}rrr[�to_listr+r�subtype�	enumeraterxr0r$r9�sp_indexrgrl�np�repeat�lenr%�astype�concatenatere)rr}r,�colsrKr�col�_�ser�sp_arr�rows           rr8zSparseFrameAccessor.to_cooIs>��6	#�7�+�+� ����!4�!4�!<�!<�!>�?���e�[�)��M�M�E��r�2�D�d��&�t�|�|�'9�'9�';�<�	D�M�C��!�S��Y�Y�F�� � �A�%� �!U�V�V��/�/�)�)�C��K�K��	�	�#�s�3�x�0�1��K�K����K�K��(�(�/�/��E�/�B�C�	D��~�~�d�#���~�~�d�#���~�~�d�#���4�$���.�d�l�l�6H�6H�I�Irc��tj|jj�D��cgc]\}}|jj
��c}}�}|Scc}}w)z�
        Ratio of non-sparse points to total (dense) data points.

        Examples
        --------
        >>> df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1, 0, 1])})
        >>> df.sparse.density
        0.5
        )r��meanrrxr0r#)rr��column�tmps    rr#zSparseFrameAccessor.density{sC���g�g�T�\�\�=O�=O�=Q�R�	��6�v�|�|�+�+�R�S���
��Ss� A
c�$�ddlm}m}|j\}}|�	||�}n||�}|�	||�}n||�}t	|�|k7rtdt	|��d|����t	|�|k7rtdt	|��d|����||fS)Nr)�
default_index�ensure_indexzColumn length mismatch: z vs. zIndex length mismatch: )�pandas.core.indexes.apir�r�rer�r9)rr?rLr�r��N�Ks       rrdzSparseFrameAccessor._prep_index�s���	
�
�z�z���1��=�!�!�$�E� ��'�E��?�#�A�&�G�"�7�+�G��w�<�1���7��G��~�U�1�#�N�O�O��u�:��?��6�s�5�z�l�%��s�K�L�L��g�~�r)NN)rr)r�float)
rrrrRrrSrvrNr8r&r#�staticmethodrdr!rrrUrU�sV��	�7�
�4
��4
�lW�.0J�d�������rrU)rR�
__future__r�typingr�numpyr��pandas.compat._optionalr�pandas.core.dtypes.castr�pandas.core.dtypes.dtypesr�pandas.core.accessorrr	�pandas.core.arrays.sparse.arrayr
rArrrr)rUr!rr�<module>r�st���"� ��>�4�1��8���"�"���B�
��
�\�>�
��
�Dt�,��tr

Youez - 2016 - github.com/yon3zu
LinuXploit