1818from pandas import compat
1919from pandas .compat import (BytesIO , range , long , u , zip , map , string_types ,
2020 iteritems )
21- from pandas .types .api import *
21+ from pandas .types import api as gt
22+ from pandas .types .api import * # noqa
2223from pandas .core .config import get_option
2324
2425
@@ -71,63 +72,6 @@ def __str__(self):
7172_int64_max = np .iinfo (np .int64 ).max
7273
7374
74- # define abstract base classes to enable isinstance type checking on our
75- # objects
76- def create_pandas_abc_type (name , attr , comp ):
77- @classmethod
78- def _check (cls , inst ):
79- return getattr (inst , attr , '_typ' ) in comp
80-
81- dct = dict (__instancecheck__ = _check , __subclasscheck__ = _check )
82- meta = type ("ABCBase" , (type , ), dct )
83- return meta (name , tuple (), dct )
84-
85-
86- ABCIndex = create_pandas_abc_type ("ABCIndex" , "_typ" , ("index" , ))
87- ABCInt64Index = create_pandas_abc_type ("ABCInt64Index" , "_typ" ,
88- ("int64index" , ))
89- ABCRangeIndex = create_pandas_abc_type ("ABCRangeIndex" , "_typ" ,
90- ("rangeindex" , ))
91- ABCFloat64Index = create_pandas_abc_type ("ABCFloat64Index" , "_typ" ,
92- ("float64index" , ))
93- ABCMultiIndex = create_pandas_abc_type ("ABCMultiIndex" , "_typ" ,
94- ("multiindex" , ))
95- ABCDatetimeIndex = create_pandas_abc_type ("ABCDatetimeIndex" , "_typ" ,
96- ("datetimeindex" , ))
97- ABCTimedeltaIndex = create_pandas_abc_type ("ABCTimedeltaIndex" , "_typ" ,
98- ("timedeltaindex" , ))
99- ABCPeriodIndex = create_pandas_abc_type ("ABCPeriodIndex" , "_typ" ,
100- ("periodindex" , ))
101- ABCCategoricalIndex = create_pandas_abc_type ("ABCCategoricalIndex" , "_typ" ,
102- ("categoricalindex" , ))
103- ABCIndexClass = create_pandas_abc_type ("ABCIndexClass" , "_typ" ,
104- ("index" , "int64index" , "rangeindex" ,
105- "float64index" ,
106- "multiindex" , "datetimeindex" ,
107- "timedeltaindex" , "periodindex" ,
108- "categoricalindex" ))
109-
110- ABCSeries = create_pandas_abc_type ("ABCSeries" , "_typ" , ("series" , ))
111- ABCDataFrame = create_pandas_abc_type ("ABCDataFrame" , "_typ" , ("dataframe" , ))
112- ABCPanel = create_pandas_abc_type ("ABCPanel" , "_typ" , ("panel" , ))
113- ABCSparseSeries = create_pandas_abc_type ("ABCSparseSeries" , "_subtyp" ,
114- ('sparse_series' ,
115- 'sparse_time_series' ))
116- ABCSparseArray = create_pandas_abc_type ("ABCSparseArray" , "_subtyp" ,
117- ('sparse_array' , 'sparse_series' ))
118- ABCCategorical = create_pandas_abc_type ("ABCCategorical" , "_typ" ,
119- ("categorical" ))
120- ABCPeriod = create_pandas_abc_type ("ABCPeriod" , "_typ" , ("period" , ))
121-
122-
123- class _ABCGeneric (type ):
124- def __instancecheck__ (cls , inst ):
125- return hasattr (inst , "_data" )
126-
127-
128- ABCGeneric = _ABCGeneric ("ABCGeneric" , tuple (), {})
129-
130-
13175def isnull (obj ):
13276 """Detect missing values (NaN in numeric arrays, None/NaN in object arrays)
13377
@@ -155,9 +99,9 @@ def _isnull_new(obj):
15599 # hack (for now) because MI registers as ndarray
156100 elif isinstance (obj , pd .MultiIndex ):
157101 raise NotImplementedError ("isnull is not defined for MultiIndex" )
158- elif isinstance (obj , (ABCSeries , np .ndarray , pd .Index )):
102+ elif isinstance (obj , (gt . ABCSeries , np .ndarray , pd .Index )):
159103 return _isnull_ndarraylike (obj )
160- elif isinstance (obj , ABCGeneric ):
104+ elif isinstance (obj , gt . ABCGeneric ):
161105 return obj ._constructor (obj ._data .isnull (func = isnull ))
162106 elif isinstance (obj , list ) or hasattr (obj , '__array__' ):
163107 return _isnull_ndarraylike (np .asarray (obj ))
@@ -181,9 +125,9 @@ def _isnull_old(obj):
181125 # hack (for now) because MI registers as ndarray
182126 elif isinstance (obj , pd .MultiIndex ):
183127 raise NotImplementedError ("isnull is not defined for MultiIndex" )
184- elif isinstance (obj , (ABCSeries , np .ndarray , pd .Index )):
128+ elif isinstance (obj , (gt . ABCSeries , np .ndarray , pd .Index )):
185129 return _isnull_ndarraylike_old (obj )
186- elif isinstance (obj , ABCGeneric ):
130+ elif isinstance (obj , gt . ABCGeneric ):
187131 return obj ._constructor (obj ._data .isnull (func = _isnull_old ))
188132 elif isinstance (obj , list ) or hasattr (obj , '__array__' ):
189133 return _isnull_ndarraylike_old (np .asarray (obj ))
@@ -250,7 +194,7 @@ def _isnull_ndarraylike(obj):
250194 result = np .isnan (values )
251195
252196 # box
253- if isinstance (obj , ABCSeries ):
197+ if isinstance (obj , gt . ABCSeries ):
254198 from pandas import Series
255199 result = Series (result , index = obj .index , name = obj .name , copy = False )
256200
@@ -279,7 +223,7 @@ def _isnull_ndarraylike_old(obj):
279223 result = ~ np .isfinite (values )
280224
281225 # box
282- if isinstance (obj , ABCSeries ):
226+ if isinstance (obj , gt . ABCSeries ):
283227 from pandas import Series
284228 result = Series (result , index = obj .index , name = obj .name , copy = False )
285229
@@ -1687,10 +1631,10 @@ def _possibly_infer_to_datetimelike(value, convert_dates=False):
16871631
16881632 """
16891633
1690- if isinstance (value , (ABCDatetimeIndex , ABCPeriodIndex )):
1634+ if isinstance (value , (gt . ABCDatetimeIndex , gt . ABCPeriodIndex )):
16911635 return value
1692- elif isinstance (value , ABCSeries ):
1693- if isinstance (value ._values , ABCDatetimeIndex ):
1636+ elif isinstance (value , gt . ABCSeries ):
1637+ if isinstance (value ._values , gt . ABCDatetimeIndex ):
16941638 return value ._values
16951639
16961640 v = value
@@ -1760,7 +1704,7 @@ def _try_timedelta(v):
17601704
17611705
17621706def is_bool_indexer (key ):
1763- if isinstance (key , (ABCSeries , np .ndarray )):
1707+ if isinstance (key , (gt . ABCSeries , np .ndarray )):
17641708 if key .dtype == np .object_ :
17651709 key = np .asarray (_values_from_object (key ))
17661710
@@ -2088,22 +2032,23 @@ def is_period_arraylike(arr):
20882032 """ return if we are period arraylike / PeriodIndex """
20892033 if isinstance (arr , pd .PeriodIndex ):
20902034 return True
2091- elif isinstance (arr , (np .ndarray , ABCSeries )):
2035+ elif isinstance (arr , (np .ndarray , gt . ABCSeries )):
20922036 return arr .dtype == object and lib .infer_dtype (arr ) == 'period'
20932037 return getattr (arr , 'inferred_type' , None ) == 'period'
20942038
20952039
20962040def is_datetime_arraylike (arr ):
20972041 """ return if we are datetime arraylike / DatetimeIndex """
2098- if isinstance (arr , ABCDatetimeIndex ):
2042+ if isinstance (arr , gt . ABCDatetimeIndex ):
20992043 return True
2100- elif isinstance (arr , (np .ndarray , ABCSeries )):
2044+ elif isinstance (arr , (np .ndarray , gt . ABCSeries )):
21012045 return arr .dtype == object and lib .infer_dtype (arr ) == 'datetime'
21022046 return getattr (arr , 'inferred_type' , None ) == 'datetime'
21032047
21042048
21052049def is_datetimelike (arr ):
2106- return (arr .dtype in _DATELIKE_DTYPES or isinstance (arr , ABCPeriodIndex ) or
2050+ return (arr .dtype in _DATELIKE_DTYPES or
2051+ isinstance (arr , gt .ABCPeriodIndex ) or
21072052 is_datetimetz (arr ))
21082053
21092054
@@ -2334,12 +2279,12 @@ def is_bool_dtype(arr_or_dtype):
23342279
23352280def is_sparse (array ):
23362281 """ return if we are a sparse array """
2337- return isinstance (array , (ABCSparseArray , ABCSparseSeries ))
2282+ return isinstance (array , (gt . ABCSparseArray , gt . ABCSparseSeries ))
23382283
23392284
23402285def is_datetimetz (array ):
23412286 """ return if we are a datetime with tz array """
2342- return ((isinstance (array , ABCDatetimeIndex ) and
2287+ return ((isinstance (array , gt . ABCDatetimeIndex ) and
23432288 getattr (array , 'tz' , None ) is not None ) or
23442289 is_datetime64tz_dtype (array ))
23452290
@@ -2360,7 +2305,7 @@ def is_internal_type(value):
23602305
23612306def is_categorical (array ):
23622307 """ return if we are a categorical possibility """
2363- return isinstance (array , ABCCategorical ) or is_categorical_dtype (array )
2308+ return isinstance (array , gt . ABCCategorical ) or is_categorical_dtype (array )
23642309
23652310
23662311def is_categorical_dtype (arr_or_dtype ):
0 commit comments