Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/pandas/core/dtypes/generic.py : 97%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1""" define generic base classes for pandas objects """
4# define abstract base classes to enable isinstance type checking on our
5# objects
6def create_pandas_abc_type(name, attr, comp):
8 # https://github.com/python/mypy/issues/1006
9 # error: 'classmethod' used with a non-method
10 @classmethod # type: ignore
11 def _check(cls, inst) -> bool:
12 return getattr(inst, attr, "_typ") in comp
14 dct = dict(__instancecheck__=_check, __subclasscheck__=_check)
15 meta = type("ABCBase", (type,), dct)
16 return meta(name, tuple(), dct)
19ABCIndex = create_pandas_abc_type("ABCIndex", "_typ", ("index",))
20ABCInt64Index = create_pandas_abc_type("ABCInt64Index", "_typ", ("int64index",))
21ABCUInt64Index = create_pandas_abc_type("ABCUInt64Index", "_typ", ("uint64index",))
22ABCRangeIndex = create_pandas_abc_type("ABCRangeIndex", "_typ", ("rangeindex",))
23ABCFloat64Index = create_pandas_abc_type("ABCFloat64Index", "_typ", ("float64index",))
24ABCMultiIndex = create_pandas_abc_type("ABCMultiIndex", "_typ", ("multiindex",))
25ABCDatetimeIndex = create_pandas_abc_type(
26 "ABCDatetimeIndex", "_typ", ("datetimeindex",)
27)
28ABCTimedeltaIndex = create_pandas_abc_type(
29 "ABCTimedeltaIndex", "_typ", ("timedeltaindex",)
30)
31ABCPeriodIndex = create_pandas_abc_type("ABCPeriodIndex", "_typ", ("periodindex",))
32ABCCategoricalIndex = create_pandas_abc_type(
33 "ABCCategoricalIndex", "_typ", ("categoricalindex",)
34)
35ABCIntervalIndex = create_pandas_abc_type(
36 "ABCIntervalIndex", "_typ", ("intervalindex",)
37)
38ABCIndexClass = create_pandas_abc_type(
39 "ABCIndexClass",
40 "_typ",
41 (
42 "index",
43 "int64index",
44 "rangeindex",
45 "float64index",
46 "uint64index",
47 "multiindex",
48 "datetimeindex",
49 "timedeltaindex",
50 "periodindex",
51 "categoricalindex",
52 "intervalindex",
53 ),
54)
56ABCSeries = create_pandas_abc_type("ABCSeries", "_typ", ("series",))
57ABCDataFrame = create_pandas_abc_type("ABCDataFrame", "_typ", ("dataframe",))
59ABCSparseArray = create_pandas_abc_type(
60 "ABCSparseArray", "_subtyp", ("sparse_array", "sparse_series")
61)
62ABCCategorical = create_pandas_abc_type("ABCCategorical", "_typ", ("categorical"))
63ABCDatetimeArray = create_pandas_abc_type("ABCDatetimeArray", "_typ", ("datetimearray"))
64ABCTimedeltaArray = create_pandas_abc_type(
65 "ABCTimedeltaArray", "_typ", ("timedeltaarray")
66)
67ABCPeriodArray = create_pandas_abc_type("ABCPeriodArray", "_typ", ("periodarray",))
68ABCPeriod = create_pandas_abc_type("ABCPeriod", "_typ", ("period",))
69ABCDateOffset = create_pandas_abc_type("ABCDateOffset", "_typ", ("dateoffset",))
70ABCInterval = create_pandas_abc_type("ABCInterval", "_typ", ("interval",))
71ABCExtensionArray = create_pandas_abc_type(
72 "ABCExtensionArray",
73 "_typ",
74 ("extension", "categorical", "periodarray", "datetimearray", "timedeltaarray"),
75)
76ABCPandasArray = create_pandas_abc_type("ABCPandasArray", "_typ", ("npy_extension",))
79class _ABCGeneric(type):
80 def __instancecheck__(cls, inst) -> bool:
81 return hasattr(inst, "_data")
84ABCGeneric = _ABCGeneric("ABCGeneric", tuple(), {})