18
18
from pandas import compat
19
19
from pandas .compat import (BytesIO , range , long , u , zip , map , string_types ,
20
20
iteritems )
21
- from pandas .types .api import *
21
+ from pandas .types import api as gt
22
+ from pandas .types .api import * # noqa
22
23
from pandas .core .config import get_option
23
24
24
25
@@ -71,63 +72,6 @@ def __str__(self):
71
72
_int64_max = np .iinfo (np .int64 ).max
72
73
73
74
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
-
131
75
def isnull (obj ):
132
76
"""Detect missing values (NaN in numeric arrays, None/NaN in object arrays)
133
77
@@ -155,9 +99,9 @@ def _isnull_new(obj):
155
99
# hack (for now) because MI registers as ndarray
156
100
elif isinstance (obj , pd .MultiIndex ):
157
101
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 )):
159
103
return _isnull_ndarraylike (obj )
160
- elif isinstance (obj , ABCGeneric ):
104
+ elif isinstance (obj , gt . ABCGeneric ):
161
105
return obj ._constructor (obj ._data .isnull (func = isnull ))
162
106
elif isinstance (obj , list ) or hasattr (obj , '__array__' ):
163
107
return _isnull_ndarraylike (np .asarray (obj ))
@@ -181,9 +125,9 @@ def _isnull_old(obj):
181
125
# hack (for now) because MI registers as ndarray
182
126
elif isinstance (obj , pd .MultiIndex ):
183
127
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 )):
185
129
return _isnull_ndarraylike_old (obj )
186
- elif isinstance (obj , ABCGeneric ):
130
+ elif isinstance (obj , gt . ABCGeneric ):
187
131
return obj ._constructor (obj ._data .isnull (func = _isnull_old ))
188
132
elif isinstance (obj , list ) or hasattr (obj , '__array__' ):
189
133
return _isnull_ndarraylike_old (np .asarray (obj ))
@@ -250,7 +194,7 @@ def _isnull_ndarraylike(obj):
250
194
result = np .isnan (values )
251
195
252
196
# box
253
- if isinstance (obj , ABCSeries ):
197
+ if isinstance (obj , gt . ABCSeries ):
254
198
from pandas import Series
255
199
result = Series (result , index = obj .index , name = obj .name , copy = False )
256
200
@@ -279,7 +223,7 @@ def _isnull_ndarraylike_old(obj):
279
223
result = ~ np .isfinite (values )
280
224
281
225
# box
282
- if isinstance (obj , ABCSeries ):
226
+ if isinstance (obj , gt . ABCSeries ):
283
227
from pandas import Series
284
228
result = Series (result , index = obj .index , name = obj .name , copy = False )
285
229
@@ -1687,10 +1631,10 @@ def _possibly_infer_to_datetimelike(value, convert_dates=False):
1687
1631
1688
1632
"""
1689
1633
1690
- if isinstance (value , (ABCDatetimeIndex , ABCPeriodIndex )):
1634
+ if isinstance (value , (gt . ABCDatetimeIndex , gt . ABCPeriodIndex )):
1691
1635
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 ):
1694
1638
return value ._values
1695
1639
1696
1640
v = value
@@ -1760,7 +1704,7 @@ def _try_timedelta(v):
1760
1704
1761
1705
1762
1706
def is_bool_indexer (key ):
1763
- if isinstance (key , (ABCSeries , np .ndarray )):
1707
+ if isinstance (key , (gt . ABCSeries , np .ndarray )):
1764
1708
if key .dtype == np .object_ :
1765
1709
key = np .asarray (_values_from_object (key ))
1766
1710
@@ -2088,22 +2032,23 @@ def is_period_arraylike(arr):
2088
2032
""" return if we are period arraylike / PeriodIndex """
2089
2033
if isinstance (arr , pd .PeriodIndex ):
2090
2034
return True
2091
- elif isinstance (arr , (np .ndarray , ABCSeries )):
2035
+ elif isinstance (arr , (np .ndarray , gt . ABCSeries )):
2092
2036
return arr .dtype == object and lib .infer_dtype (arr ) == 'period'
2093
2037
return getattr (arr , 'inferred_type' , None ) == 'period'
2094
2038
2095
2039
2096
2040
def is_datetime_arraylike (arr ):
2097
2041
""" return if we are datetime arraylike / DatetimeIndex """
2098
- if isinstance (arr , ABCDatetimeIndex ):
2042
+ if isinstance (arr , gt . ABCDatetimeIndex ):
2099
2043
return True
2100
- elif isinstance (arr , (np .ndarray , ABCSeries )):
2044
+ elif isinstance (arr , (np .ndarray , gt . ABCSeries )):
2101
2045
return arr .dtype == object and lib .infer_dtype (arr ) == 'datetime'
2102
2046
return getattr (arr , 'inferred_type' , None ) == 'datetime'
2103
2047
2104
2048
2105
2049
def 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
2107
2052
is_datetimetz (arr ))
2108
2053
2109
2054
@@ -2334,12 +2279,12 @@ def is_bool_dtype(arr_or_dtype):
2334
2279
2335
2280
def is_sparse (array ):
2336
2281
""" return if we are a sparse array """
2337
- return isinstance (array , (ABCSparseArray , ABCSparseSeries ))
2282
+ return isinstance (array , (gt . ABCSparseArray , gt . ABCSparseSeries ))
2338
2283
2339
2284
2340
2285
def is_datetimetz (array ):
2341
2286
""" return if we are a datetime with tz array """
2342
- return ((isinstance (array , ABCDatetimeIndex ) and
2287
+ return ((isinstance (array , gt . ABCDatetimeIndex ) and
2343
2288
getattr (array , 'tz' , None ) is not None ) or
2344
2289
is_datetime64tz_dtype (array ))
2345
2290
@@ -2360,7 +2305,7 @@ def is_internal_type(value):
2360
2305
2361
2306
def is_categorical (array ):
2362
2307
""" 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 )
2364
2309
2365
2310
2366
2311
def is_categorical_dtype (arr_or_dtype ):
0 commit comments