HOME


sh-3ll 1.0
DIR:/usr/local/lib64/python3.6/site-packages/pandas/core/__pycache__/
Upload File :
Current File : //usr/local/lib64/python3.6/site-packages/pandas/core/__pycache__/common.cpython-36.pyc
3

���h.6�@s�dZddlmZmZddlZddlmZmZddlmZddl	Z	ddl
mZmZm
Z
mZmZmZddlZddlZddlmZmZddlmZmZmZdd	lmZdd
lmZddlm Z m!Z!m"Z"m#Z#ddl$m%Z%m&Z&m'Z'm(Z(dd
l)m*Z*ddl+m,Z,m-Z-m.Z.Gdd�de/�Z0Gdd�de1�Z2dd�Z3dd�Z4dOdd�Z5ee6d�dd�Z7dPdd�Z8dd �Z9e6d!�d"d#�Z:e6d!�d$d%�Z;e6d!�d&d'�Z<e6d!�d(d)�Z=e>d!�d*d+�Z?dQd,d-�Z@dRd.d/�ZAd0d1�ZBee
eefeeeefd2�d3d4�ZCe6d!�d5d6�ZDd7d8�ZEe6d!�d9d:�ZFd;d<�ZGd=d>�ZHd?d@�ZIdAdB�ZJdSdCdD�ZKdEdF�ZLdGdH�ZMeee
efeeefdI�dJdK�ZNejOePeddL�dMdN��ZQdS)Tzh
Misc tools for implementing data structures

Note: pandas.core.common is *not* part of the public API.
�)�abc�defaultdictN)�datetime�	timedelta)�partial)�Any�
Collection�Iterable�Iterator�List�Union)�lib�tslibs)�AnyArrayLike�Scalar�T)�_np_version_under1p18)�'construct_1d_object_array_from_listlike)�
is_array_like�
is_bool_dtype�is_extension_array_dtype�
is_integer)�ABCExtensionArray�ABCIndex�
ABCIndexClass�	ABCSeries)�_iterable_not_string)�isna�isnull�notnullc@seZdZdS)�SettingWithCopyErrorN)�__name__�
__module__�__qualname__�r$r$�4/tmp/pip-build-5_djhm0z/pandas/pandas/core/common.pyr &sr c@seZdZdS)�SettingWithCopyWarningN)r!r"r#r$r$r$r%r&*sr&ccs:x4|D],}t|�r,xt|�D]
}|VqWq|VqWdS)a
    Flatten an arbitrarily nested sequence.

    Parameters
    ----------
    l : sequence
        The non string sequence to flatten

    Notes
    -----
    This doesn't consider strings sequences.

    Returns
    -------
    flattened : generator
    N)r�flatten)�l�el�sr$r$r%r'.s

r'cCsP|dj}x@|dd�D]0}y|j|kr,d}Wqtk
rFd}YqXqW|S)Nr�)�name�
ValueError)�objsr,�objr$r$r%�consensus_name_attrGs

r0cCsF|tkr|St|tjtf�r(tj|�}nt|tjtf�rBtj	|�}|S)N)
�object�
isinstance�npZ
datetime64rrZ	TimestampZtimedelta64rZ	Timedelta)�value�dtyper$r$r%�maybe_box_datetimelikeRs
r6)�key�returncCs�t|ttjtf�s$t|�rtt|j�rt|jtjkrdtj	|�}t
j|�s`d}t|�j
�r\t|��dSdSt|j�r�dSnFt|t�r�y&tj	|�}|jtjko�t|�t|�kStk
r�dSXdS)a�
    Check whether `key` is a valid boolean indexer.

    Parameters
    ----------
    key : Any
        Only list-likes may be considered boolean indexers.
        All other types are not considered a boolean indexer.
        For array-like input, boolean ndarrays or ExtensionArrays
        with ``_is_boolean`` set are considered boolean indexers.

    Returns
    -------
    bool
        Whether `key` is a valid boolean indexer.

    Raises
    ------
    ValueError
        When the array is an object-dtype ndarray or ExtensionArray
        and contains missing values.

    See Also
    --------
    check_array_indexer : Check that `key` is a valid array to index,
        and convert to an ndarray.
    z=Cannot mask with non-boolean array containing NA / NaN valuesFT)r2rr3�ndarrayrrrr5�object_�asarrayr
Z
is_bool_arrayr�anyr-r�listZbool_�len�	TypeError)r7Zna_msgZarrr$r$r%�is_bool_indexeras&




r@FcCs2tj|�r.|j�r.|r&tjdtdd�t|�S|S)a
    To avoid numpy DeprecationWarnings, cast float to integer where valid.

    Parameters
    ----------
    val : scalar
    warn_float : bool, default False
        If True, issue deprecation warning for a float indexer.

    Returns
    -------
    outval : scalar
    z�Indexing with a float is deprecated, and will raise an IndexError in pandas 2.0. You can manually convert to an integer key instead.�)�
stacklevel)r
Zis_floatr�warnings�warn�
FutureWarning�int)�valZ
warn_floatr$r$r%�cast_scalar_indexer�srHcGsdd�|D�S)zL
    Returns a generator consisting of the arguments that are not None.
    css|]}|dk	r|VqdS)Nr$)�.0�argr$r$r%�	<genexpr>�sznot_none.<locals>.<genexpr>r$)�argsr$r$r%�not_none�srM)r8cGstdd�|D��S)z?
    Returns a boolean indicating if any argument is None.
    css|]}|dkVqdS)Nr$)rIrJr$r$r%rK�szany_none.<locals>.<genexpr>)r<)rLr$r$r%�any_none�srNcGstdd�|D��S)zA
    Returns a boolean indicating if all arguments are None.
    css|]}|dkVqdS)Nr$)rIrJr$r$r%rK�szall_none.<locals>.<genexpr>)�all)rLr$r$r%�all_none�srPcGstdd�|D��S)zC
    Returns a boolean indicating if any argument is not None.
    css|]}|dk	VqdS)Nr$)rIrJr$r$r%rK�szany_not_none.<locals>.<genexpr>)r<)rLr$r$r%�any_not_none�srQcGstdd�|D��S)zE
    Returns a boolean indicating if all arguments are not None.
    css|]}|dk	VqdS)Nr$)rIrJr$r$r%rK�szall_not_none.<locals>.<genexpr>)rO)rLr$r$r%�all_not_none�srRcGstdd�|D��S)z;
    Returns the count of arguments that are not None.
    css|]}|dk	VqdS)Nr$)rI�xr$r$r%rK�sz!count_not_none.<locals>.<genexpr>)�sum)rLr$r$r%�count_not_none�srUcCs�t|ttf�pt|d�s"t|�}nt|t�r2|jSt|t�rR|tjtgkrRt	|�Stj
||d�}t|jj
t�r|tj
|td�}|jdkr�dd�|D�}t	|�}|S)NZ	__array__)r5�cSsg|]}t|��qSr$)�tuple)rIrSr$r$r%�
<listcomp>�sz%asarray_tuplesafe.<locals>.<listcomp>)r2r=rW�hasattrrZ_valuesr3r:r1rr;�
issubclassr5�type�str�ndim)�valuesr5�resultr$r$r%�asarray_tuplesafe�s


r`cCs\t|ttf�r|g}t|ttjf�sLyt|�}Wntk
rJ|g}YnXt||d�}|S)z�
    Transform label or iterable of labels to array, for use in Index.

    Parameters
    ----------
    dtype : dtype
        If specified, use as dtype of the resulting array, otherwise infer.

    Returns
    -------
    array
    )r5)r2r\rWr=r3r9r?r`)�labelsr5r$r$r%�index_labels_to_array�s
rbcCs"|dk	rt|ttf�r|gS|S)N)r2rWr=)r/r$r$r%�maybe_make_listsrc)r/r8cCs&t|tj�r"t|tj�r"t|�S|S)zB
    If obj is Iterable but not list-like, consume into list.
    )r2rr	�Sizedr=)r/r$r$r%�maybe_iterable_to_listsrecCs(t|t�o&|jdko&|jdko&|jdkS)z
    We have a null slice.
    N)r2�slice�start�stop�step)r/r$r$r%�
is_null_slices


rjcCsdd�|D�S)zU
    Find non-trivial slices in "l": return a list of booleans with same length.
    cSs g|]}t|t�ot|��qSr$)r2rfrj)rI�kr$r$r%rX+sz"is_true_slices.<locals>.<listcomp>r$)r(r$r$r%�is_true_slices'srlcCs(t|t�o&|jdko&|j|ko&|jdkS)z&
    We have a full length slice.
    rN)r2rfrgrhri)r/r(r$r$r%�
is_full_slice/srmcCs@t|d�rt|d�St|t�r(t|j�St|d�r<t|�jSdS)Nr!�__call__)rY�getattrr2r�get_callable_name�funcr[r!)r/r$r$r%rp8s





rpcKst|�r||f|�S|S)z�
    Evaluate possibly callable input using obj and kwargs if it is callable,
    otherwise return as it is.

    Parameters
    ----------
    maybe_callable : possibly a callable
    obj : NDFrame
    **kwargs
    )�callable)Zmaybe_callabler/�kwargsr$r$r%�apply_if_callableIsrtcCsdd�|j�D�S)z�
    Helper function to convert datetimelike-keyed dicts
    to Timestamp-keyed dict.

    Parameters
    ----------
    d: dict like object

    Returns
    -------
    dict

    cSsi|]\}}|t|��qSr$)r6)rIr7r4r$r$r%�
<dictcomp>hszdict_compat.<locals>.<dictcomp>)�items)�dr$r$r%�dict_compatZsrxcCsXtj|�s(t|t�r tt|j�St|�}t|tj	�sDt
d|����n|tkrTt
d��|S)a
    Helper function to standardize a supplied mapping.

    Parameters
    ----------
    into : instance or subclass of collections.abc.Mapping
        Must be a class, an initialized collections.defaultdict,
        or an instance of a collections.abc.Mapping subclass.

    Returns
    -------
    mapping : a collections.abc.Mapping subclass or other constructor
        a callable object that can accept an iterator to create
        the desired Mapping.

    See Also
    --------
    DataFrame.to_dict
    Series.to_dict
    zunsupported type: z/to_dict() only accepts initialized defaultdicts)�inspectZisclassr2rr�default_factoryr[rZr�Mappingr?)Zintor$r$r%�standardize_mappingks

r|cCs\t|�s$t|�s$tr0t|tjj�r0tjj|�St|tjj�rB|S|dkrPtjStd��dS)a�
    Helper function for processing random_state arguments.

    Parameters
    ----------
    state : int, array-like, BitGenerator (NumPy>=1.17), np.random.RandomState, None.
        If receives an int, array-like, or BitGenerator, passes to
        np.random.RandomState() as seed.
        If receives an np.random.RandomState object, just returns object.
        If receives `None`, returns np.random.
        If receives anything else, raises an informative ValueError.

        .. versionchanged:: 1.1.0

            array-like and BitGenerator (for NumPy>=1.18) object now passed to
            np.random.RandomState() as seed

        Default None.

    Returns
    -------
    np.random.RandomState

    NzYrandom_state must be an integer, array-like, a BitGenerator, a numpy RandomState, or None)	rrrr2r3�randomZBitGeneratorZRandomStater-)�stater$r$r%�random_state�srcOsRt|t�r>|\}}||kr,|�d�}t|��|||<|||�S||f|�|�SdS)ar
    Apply a function ``func`` to object ``obj`` either by passing obj as the
    first argument to the function or, in the case that the func is a tuple,
    interpret the first element of the tuple as a function and pass the obj to
    that function as a keyword argument whose key is the value of the second
    element of the tuple.

    Parameters
    ----------
    func : callable or tuple of (callable, str)
        Function to apply to this object or, alternatively, a
        ``(callable, data_keyword)`` tuple where ``data_keyword`` is a
        string indicating the keyword of `callable`` that expects the
        object.
    *args : iterable, optional
        Positional arguments passed into ``func``.
    **kwargs : dict, optional
        A dictionary of keyword arguments passed into ``func``.

    Returns
    -------
    object : the return type of ``func``.
    z/ is both the pipe target and a keyword argumentN)r2rWr-)r/rqrLrs�target�msgr$r$r%�pipe�s


r�cs&t�tjtf�r�fdd�}n�}|S)zv
    Returns a function that will map names/labels, dependent if mapper
    is a dict, Series or just a function.
    cs|�kr�|S|SdS)Nr$)rS)�mapperr$r%�f�szget_rename_function.<locals>.f)r2rr{r)r�r�r$)r�r%�get_rename_function�sr�)r^r8cCs@t|ttjtttf�r|St|tj�r:t|t	�r:t|�S|gS)z�
    Convert list-like or scalar input to list-like. List, numpy and pandas array-like
    inputs are returned unmodified whereas others are converted to list.
    )
r2r=r3r9rrrrr	r\)r^r$r$r%�convert_to_list_like�s
r�)�attrr8ccs,t||�}t|||�|Vt|||�dS)z�Temporarily set attribute on an object.

    Args:
        obj: Object whose attribute will be modified.
        attr: Attribute to modify.
        value: Value to temporarily set attribute to.

    Yields:
        obj with modified attribute.
    N)ro�setattr)r/r�r4�	old_valuer$r$r%�temp_setattr�s
r�)N)F)N)N)N)R�__doc__�collectionsrr�
contextlibrr�	functoolsrryZtypingrrr	r
rrrCZnumpyr3Zpandas._libsr
rZpandas._typingrrrZpandas.compat.numpyrZpandas.core.dtypes.castrZpandas.core.dtypes.commonrrrrZpandas.core.dtypes.genericrrrrZpandas.core.dtypes.inferencerZpandas.core.dtypes.missingrrrr-r �Warningr&r'r0r6�boolr@rHrMrNrPrQrRrFrUr`rbrcrerjrlrmrprtrxr|rr�r�r��contextmanagerr\r�r$r$r$r%�<module>s^ 
4


(		 
,#