U
    f/e                     @  s   d Z ddlmZ ddl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 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)TypeVar)DtypeObjShapefinalAbstractMethodError)find_common_type)PandasObject)IndexTDataManager)boundc                	   @  s   e Zd ZU ded< eddddZ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
d,ddddddddddZe	d-dddddddddZdddddd Zd!dd"d#d$Zd.dd%ddd&d'd(Zddd)d*d+ZdS )/r   zlist[Index]axesr   )returnc                 C  s   t | d S Nr   self r   >/tmp/pip-unpacked-wheel-tiezk1ph/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   ndim%   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>+   s     z$DataManager.shape.<locals>.<genexpr>)tupler   r   r   r   r   shape)   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consolidate
only_slicer   c	           	      C  s   t | d S r   r   )	r   Znew_axisindexerr    
fill_valuer&   r'   r(   r)   r   r   r   reindex_indexer>   s    zDataManager.reindex_indexer)r   	new_indexr    r(   r)   r   c              	   C  s,   | j | |\}}| j||||d||dS )z4
        Conform data manager to new index.
        F)r    r+   r'   r(   r)   )r   Zreindexr,   )r   r-   r    r+   r(   r)   r*   r   r   r   reindex_axisK   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   r/   r   r   r   _equal_valuesc   s    zDataManager._equal_valuesobject)r/   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   t   s     z%DataManager.equals.<locals>.<genexpr>)
isinstancer   r   r   allzipr0   )r   r/   Z	self_axesZ
other_axesr   r   r   r2   j   s    
zDataManager.equalszlist[str] | None)r   
align_keysignore_failuresr   c                 K  s   t | d S r   r   )r   fr6   r7   kwargsr   r   r   applyy   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.isna)NFTTF)NTF)NF)__name__
__module____qualname____annotations__propertyr   r   r   r   r   r$   r,   r.   r0   r2   r:   r<   r   r   r   r   r      s6   
          	c                   @  s   e Zd ZdZedd ZdS )SingleDataManagerr"   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.arrayN)r=   r>   r?   r   rA   rC   r   r   r   r   rB      s   rB   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	   )rD   r   r   r   interleaved_dtype   s    rE   N)__doc__
__future__r   typingr   Zpandas._typingr   r   r   Zpandas.errorsr   Zpandas.core.dtypes.castr	   Zpandas.core.baser
   Zpandas.core.indexes.apir   r   r   rB   rE   r   r   r   r   <module>   s   n