# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/06_ispd.ipynb.

# %% auto 0
__all__ = ['pdna', 'dataframe', 'pdindex', 'pdseries', 'pdcindex', 'pdbindex', 'pdindexlike', 'ispdna', 'notpdna', 'isdf',
           'isidx', 'isseries', 'iscategoricalindex', 'iscatidx', 'iscidx', 'isboolindex', 'isboolidx', 'isbidx',
           'isindexlike', 'isidxlike']

# %% ../nbs/06_ispd.ipynb 4
from typing import TypeGuard, ForwardRef, TypeAlias, Any, Optional
try: 
    from pandas import (NA, DataFrame, Index, Series, CategoricalIndex)
except ImportError: 
    NA = None
    DataFrame, Index, Series, CategoricalIndex = list, list, list, list

pdna: TypeAlias      = ForwardRef('pd.NA',        module='pandas')
dataframe: TypeAlias = ForwardRef('pd.DataFrame', module='pandas', is_class=True)
pdindex: TypeAlias   = ForwardRef('pd.Index',     module='pandas', is_class=True)
pdseries: TypeAlias  = ForwardRef('pd.Series',    module='pandas', is_class=True)
pdcindex: TypeAlias  = ForwardRef('pd.CategoricalIndex', module='pandas', is_class=True)

# %% ../nbs/06_ispd.ipynb 5
try: 
    from atyp import (BoolIndex, IndexLike)
except ImportError: 
    BoolIndex, IndexLike = list, list

pdbindex: TypeAlias  = ForwardRef('BoolIndex', module='atyp', is_class=True)
pdindexlike: TypeAlias  = ForwardRef('IndexLike', module='atyp', is_class=True)

# %% ../nbs/06_ispd.ipynb 6
from .core import notnone

# %% ../nbs/06_ispd.ipynb 8
def ispdna(x) -> TypeGuard[pdna]:
    '''Check if `x` is `pd.NA`.'''
    return x is NA

def notpdna(x) -> TypeGuard[Any]:
    '''Check if `x` is not `pd.NA`.'''
    return not ispdna(x)

# %% ../nbs/06_ispd.ipynb 9
def isdf(x) -> TypeGuard[dataframe]:
    '''Check if `x` is an `pd.DataFrame`.'''
    return isinstance(x, DataFrame)

def isidx(x) -> TypeGuard[pdindex]:
    '''Check if `x` is an `pd.Index`.'''
    return isinstance(x, Index)

def isseries(x) -> TypeGuard[pdseries]:
    '''Check if `x` is an `pd.Series`.'''
    return isinstance(x, Series)

# %% ../nbs/06_ispd.ipynb 10
def iscategoricalindex(x) -> TypeGuard[pdcindex]:
    '''Check if `x` is an `pd.CategoricalIndex`.    
    
    See Also
    --------
    iscatidx : Alias for `iscategoricalindex`.
    iscidx : Alias for `iscategoricalindex`.
    '''
    return isinstance(x, CategoricalIndex)

def iscatidx(x) -> TypeGuard[pdcindex]:
    '''Check if `x` is an `pd.CategoricalIndex`.    
    
    See Also
    --------
    iscatidx : Alias for `iscatidx`.
    iscidx: Alias for `iscatidx`.
    '''
    return iscategoricalindex(x)

def iscidx(x) -> TypeGuard[pdcindex]:
    '''Check if `x` is an `pd.CategoricalIndex`.    
    
    See Also
    --------
    iscatidx : Alias for `iscidx`.
    iscategoricalindex: Alias for `iscidx`.
    '''
    return iscategoricalindex(x)


def isboolindex(x, r: Optional[pdindex] = None) -> TypeGuard[pdbindex]:
    '''Check if `x` is an `BoolIndex`. 

    Parameters
    ----------
    x : `Any`
        The object to check.

    r : `pd.Index`, default: None
        An optional reference index to check that `x` is the same length of.
    
    See Also
    --------
    isboolidx : Alias for `isboolindex`.
    isbidx : Alias for `isboolindex`.
    '''
    return isinstance(x, BoolIndex) and (len(x) == len(r) if notnone(r) else True)

def isboolidx(x, r: Optional[pdindex] = None) -> TypeGuard[pdbindex]:
    '''Check if `x` is an `BoolIndex`.    

    Parameters
    ----------
    x : `Any`
        The object to check.
        
    r : `pd.Index`, default: None
        An optional reference index to check that `x` is the same length of.
    
    See Also
    --------
    isboolindex : Alias for `isboolidx`.
    isbidx: Alias for `isboolidx`.
    '''
    return isboolindex(x, r)

def isbidx(x, r: Optional[pdindex] = None) -> TypeGuard[pdbindex]:
    '''Check if `x` is an `BoolIndex`.    
    Parameters
    ----------
    x : `Any`
        The object to check.
        
    r : `pd.Index`, default: None
        An optional reference index to check that `x` is the same length of.
    
    See Also
    --------
    isboolidx : Alias for `isbidx`.
    isboolindex: Alias for `isbidx`.
    '''
    return isboolindex(x, r)



def isindexlike(x) -> TypeGuard[pdindexlike]:
    '''Check if `x` is an `IndexLike`.    
    
    See Also
    --------
    isidxlike : Alias for `isindexlike`.
    '''
    return isinstance(x, IndexLike)

def isidxlike(x) -> TypeGuard[pdindexlike]:
    '''Check if `x` is an `IndexLike`.    
    
    See Also
    --------
    isindexlike : Alias for `isidxlike`.
    '''
    return isindexlike(x)
