U
    cP                     @  s   d Z ddlmZ ddlmZmZmZ ddlZddl	m
Z
mZ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 ed
ddZG dd deZG dd deZdddddZdS )zc
Base class for the internal managers. Both BlockManager and ArrayManager
inherit from this class.
    )annotations)LiteralTypeVarfinalN)	ArrayLikeDtypeObjShapeAbstractMethodError)find_common_typenp_can_hold_element)PandasObject)Indexdefault_indexTDataManager)boundc                   @  s&  e Zd ZU ded< eddddZedddd	Zeddd
dZeddddZ	eddddddZ
d2dddddddddZed3ddddddddZdddddd Zed!dd"d#d$Zd4dd%ddd&d'd(Zeddd)d*d+Zddd,d-Zddd)d.d/Zddd0d1ZdS )5r   zlist[Index]axesr   returnc                 C  s   t | d S Nr	   self r   >/tmp/pip-unpacked-wheel-g7fro6k3/pandas/core/internals/base.pyitems*   s    zDataManager.itemsintc                 C  s
   t | jS r   )lenr   r   r   r   r   __len__.   s    zDataManager.__len__c                 C  s
   t | jS r   )r   r   r   r   r   r   ndim2   s    zDataManager.ndimr   c                 C  s   t dd | jD S )Nc                 s  s   | ]}t |V  qd S r   )r   ).0Zaxr   r   r   	<genexpr>8   s     z$DataManager.shape.<locals>.<genexpr>)tupler   r   r   r   r   shape6   s    zDataManager.shapeNone)axis
new_labelsr   c                 C  sP   t | j| }t |}|dkr.t | jdkr.n||krLtd| d| dd S )N   r   z#Length mismatch: Expected axis has z elements, new values have z	 elements)r   r   r   
ValueError)r   r%   r&   Zold_lenZnew_lenr   r   r   _validate_set_axis:   s    zDataManager._validate_set_axisNFTr   bool)r   r%   
allow_dupscopy
only_slicer   c                 C  s   t | d S r   r	   )r   Znew_axisindexerr%   
fill_valuer+   r,   r-   r   r   r   reindex_indexerK   s    
zDataManager.reindex_indexer)r   	new_indexr%   r-   r   c                 C  s*   | j | |\}}| j||||d|dS )z4
        Conform data manager to new index.
        F)r%   r/   r,   r-   )r   Zreindexr0   )r   r1   r%   r/   r-   r.   r   r   r   reindex_axisW   s    zDataManager.reindex_axis)r   otherr   c                 C  s   t | dS )z
        To be implemented by the subclasses. Only check the column values
        assuming shape and indexes have already been checked.
        Nr	   )r   r3   r   r   r   _equal_valuesm   s    zDataManager._equal_valuesobject)r3   r   c                 C  sV   t |tsdS | j|j }}t|t|kr0dS tdd t||D sLdS | |S )z5
        Implementation for DataFrame.equals
        Fc                 s  s   | ]\}}| |V  qd S r   )equals)r    Zax1Zax2r   r   r   r!      s     z%DataManager.equals.<locals>.<genexpr>)
isinstancer   r   r   allzipr4   )r   r3   Z	self_axesZ
other_axesr   r   r   r6   t   s    
zDataManager.equalszlist[str] | None)r   
align_keysignore_failuresr   c                 K  s   t | d S r   r	   )r   fr:   r;   kwargsr   r   r   apply   s    zDataManager.apply)r   r   c                 C  s   | j d|dS )Nr>   )func)r>   )r   r?   r   r   r   isna   s    zDataManager.isnac                 C  s   dS )NTr   r   r   r   r   is_consolidated   s    zDataManager.is_consolidatedc                 C  s   | S r   r   r   r   r   r   consolidate   s    zDataManager.consolidatec                 C  s   d S r   r   r   r   r   r   _consolidate_inplace   s    z DataManager._consolidate_inplace)NFTF)NF)NF)__name__
__module____qualname____annotations__propertyr   r   r   r   r#   r)   r0   r2   r4   r6   r>   r@   rA   rB   rC   r   r   r   r   r   $   s>   
        	c                   @  sf   e Zd ZeddddZeeddddZddd	d
ZdddddZe	dddddZ
dS )SingleDataManagerz
Literal[1]r   c                 C  s   dS )Nr'   r   r   r   r   r   r      s    zSingleDataManager.ndimr   c                 C  s
   | j d S )zW
        Quick access to the backing array of the Block or SingleArrayManager.
        r   )Zarraysr   r   r   r   array   s    zSingleDataManager.arrayr$   c                 C  s*   | j }t|tjrt|j|}|||< dS )a'  
        Set values with indexer.

        For Single[Block/Array]Manager, this backs s[indexer] = value

        This is an inplace version of `setitem()`, mutating the manager/values
        in place, not returning a new Manager (and Block), and thus never changing
        the dtype.
        N)rJ   r7   npZndarrayr   Zdtype)r   r.   valuearrr   r   r   setitem_inplace   s    
z!SingleDataManager.setitem_inplaceFr*   )r;   c                 C  s.   | j }||}tt|}t| ||}|S )z
        ignore_failures : bool, default False
            Not used; for compatibility with ArrayManager/BlockManager.
        )rJ   r   r   type
from_array)r   r?   r;   rM   resindexZmgrr   r   r   grouped_reduce   s
    z SingleDataManager.grouped_reducer   )rM   rR   c                 C  s   t | d S r   r	   )clsrM   rR   r   r   r   rP      s    zSingleDataManager.from_arrayN)F)rD   rE   rF   rH   r   r   rJ   rN   rS   classmethodrP   r   r   r   r   rI      s   rI   zlist[DtypeObj]zDtypeObj | None)dtypesr   c                 C  s   t | sdS t| S )z
    Find the common dtype for `blocks`.

    Parameters
    ----------
    blocks : List[DtypeObj]

    Returns
    -------
    dtype : np.dtype, ExtensionDtype, or None
        None is returned when `blocks` is empty.
    N)r   r   )rV   r   r   r   interleaved_dtype   s    rW   )__doc__
__future__r   typingr   r   r   ZnumpyrK   Zpandas._typingr   r   r   Zpandas.errorsr
   Zpandas.core.dtypes.castr   r   Zpandas.core.baser   Zpandas.core.indexes.apir   r   r   r   rI   rW   r   r   r   r   <module>   s   z4