U
    Mfx                     @  s   d Z ddlmZ ddl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)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dZed3dd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-eb6vo0j3/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   ndim1   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>7   s     z$DataManager.shape.<locals>.<genexpr>)tupler   r   r   r   r   shape5   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_axis9   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_indexerJ   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reindexr0   )r   r1   r$   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_valueso   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   v   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   r,      s    zDataManager.consolidatec                 C  s   d S r   r   r   r   r   r   _consolidate_inplace   s    z DataManager._consolidate_inplace)NFTTF)NTF)NF)__name__
__module____qualname____annotations__propertyr   r   r   r   r"   r(   r0   r2   r4   r6   r>   r@   rA   r,   rB   r   r   r   r   r   #   sB   
          	c                   @  sX   e Zd Z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 )SingleDataManagerr&   r   r   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)rI   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.
        )rI   r   r   type
from_array)r   r?   r;   rL   resindexZmgrr   r   r   grouped_reduce   s
    z SingleDataManager.grouped_reducer   )rL   rQ   c                 C  s   t | d S r   r   )clsrL   rQ   r   r   r   rO      s    zSingleDataManager.from_arrayN)F)rC   rD   rE   r   r   rG   rI   rM   rR   classmethodrO   r   r   r   r   rH      s   rH   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
   )rU   r   r   r   interleaved_dtype   s    rV   )__doc__
__future__r   typingr   r   ZnumpyrJ   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   rH   rV   r   r   r   r   <module>   s   }2