Skip to content

Commit 4cef979

Browse files
Amir-101Amirjorisvandenbossche
authored
ENH: set __module__ for Dtype and Index classes (#59909)
Co-authored-by: Amir <[email protected]> Co-authored-by: Joris Van den Bossche <[email protected]>
1 parent 3f7bc81 commit 4cef979

File tree

10 files changed

+36
-0
lines changed

10 files changed

+36
-0
lines changed

pandas/core/dtypes/dtypes.py

+7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from pandas._libs.tslibs.offsets import BDay
4949
from pandas.compat import pa_version_under10p1
5050
from pandas.errors import PerformanceWarning
51+
from pandas.util._decorators import set_module
5152
from pandas.util._exceptions import find_stack_level
5253

5354
from pandas.core.dtypes.base import (
@@ -155,6 +156,7 @@ class CategoricalDtypeType(type):
155156

156157

157158
@register_extension_dtype
159+
@set_module("pandas")
158160
class CategoricalDtype(PandasExtensionDtype, ExtensionDtype):
159161
"""
160162
Type for categorical data with the categories and orderedness.
@@ -706,6 +708,7 @@ def index_class(self) -> type_t[CategoricalIndex]:
706708

707709

708710
@register_extension_dtype
711+
@set_module("pandas")
709712
class DatetimeTZDtype(PandasExtensionDtype):
710713
"""
711714
An ExtensionDtype for timezone-aware datetime data.
@@ -974,6 +977,7 @@ def index_class(self) -> type_t[DatetimeIndex]:
974977

975978

976979
@register_extension_dtype
980+
@set_module("pandas")
977981
class PeriodDtype(PeriodDtypeBase, PandasExtensionDtype):
978982
"""
979983
An ExtensionDtype for Period data.
@@ -1215,6 +1219,7 @@ def index_class(self) -> type_t[PeriodIndex]:
12151219

12161220

12171221
@register_extension_dtype
1222+
@set_module("pandas")
12181223
class IntervalDtype(PandasExtensionDtype):
12191224
"""
12201225
An ExtensionDtype for Interval data.
@@ -1691,6 +1696,7 @@ def _get_common_dtype(self, dtypes: list[DtypeObj]) -> DtypeObj | None:
16911696

16921697

16931698
@register_extension_dtype
1699+
@set_module("pandas")
16941700
class SparseDtype(ExtensionDtype):
16951701
"""
16961702
Dtype for data stored in :class:`SparseArray`.
@@ -2130,6 +2136,7 @@ def _get_common_dtype(self, dtypes: list[DtypeObj]) -> DtypeObj | None:
21302136

21312137

21322138
@register_extension_dtype
2139+
@set_module("pandas")
21332140
class ArrowDtype(StorageExtensionDtype):
21342141
"""
21352142
An ExtensionDtype for PyArrow data types.

pandas/core/indexes/base.py

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
Appender,
7272
cache_readonly,
7373
doc,
74+
set_module,
7475
)
7576
from pandas.util._exceptions import (
7677
find_stack_level,
@@ -315,6 +316,7 @@ def _new_Index(cls, d):
315316
return cls.__new__(cls, **d)
316317

317318

319+
@set_module("pandas")
318320
class Index(IndexOpsMixin, PandasObject):
319321
"""
320322
Immutable sequence used for indexing and alignment.

pandas/core/indexes/category.py

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from pandas.util._decorators import (
1414
cache_readonly,
1515
doc,
16+
set_module,
1617
)
1718

1819
from pandas.core.dtypes.common import is_scalar
@@ -76,6 +77,7 @@
7677
Categorical,
7778
wrap=True,
7879
)
80+
@set_module("pandas")
7981
class CategoricalIndex(NDArrayBackedExtensionIndex):
8082
"""
8183
Index based on an underlying :class:`Categorical`.

pandas/core/indexes/datetimes.py

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from pandas.util._decorators import (
2727
cache_readonly,
2828
doc,
29+
set_module,
2930
)
3031

3132
from pandas.core.dtypes.common import is_scalar
@@ -126,6 +127,7 @@ def _new_DatetimeIndex(cls, d):
126127
+ DatetimeArray._bool_ops,
127128
DatetimeArray,
128129
)
130+
@set_module("pandas")
129131
class DatetimeIndex(DatetimeTimedeltaMixin):
130132
"""
131133
Immutable ndarray-like of datetime64 data.

pandas/core/indexes/interval.py

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from pandas.util._decorators import (
3333
Appender,
3434
cache_readonly,
35+
set_module,
3536
)
3637
from pandas.util._exceptions import rewrite_exception
3738

@@ -202,6 +203,7 @@ def _new_IntervalIndex(cls, d):
202203
IntervalArray,
203204
)
204205
@inherit_names(["is_non_overlapping_monotonic", "closed"], IntervalArray, cache=True)
206+
@set_module("pandas")
205207
class IntervalIndex(ExtensionIndex):
206208
_typ = "intervalindex"
207209

pandas/core/indexes/multi.py

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
Appender,
5454
cache_readonly,
5555
doc,
56+
set_module,
5657
)
5758
from pandas.util._exceptions import find_stack_level
5859

@@ -195,6 +196,7 @@ def new_meth(self_or_cls, *args, **kwargs):
195196
return cast(F, new_meth)
196197

197198

199+
@set_module("pandas")
198200
class MultiIndex(Index):
199201
"""
200202
A multi-level, or hierarchical, index object for pandas objects.

pandas/core/indexes/period.py

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from pandas.util._decorators import (
2121
cache_readonly,
2222
doc,
23+
set_module,
2324
)
2425

2526
from pandas.core.dtypes.common import is_integer
@@ -81,6 +82,7 @@ def _new_PeriodIndex(cls, **d):
8182
wrap=True,
8283
)
8384
@inherit_names(["is_leap_year"], PeriodArray)
85+
@set_module("pandas")
8486
class PeriodIndex(DatetimeIndexOpsMixin):
8587
"""
8688
Immutable ndarray holding ordinal values indicating regular periods in time.

pandas/core/indexes/range.py

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from pandas.util._decorators import (
2828
cache_readonly,
2929
doc,
30+
set_module,
3031
)
3132

3233
from pandas.core.dtypes.base import ExtensionDtype
@@ -74,6 +75,7 @@ def min_fitting_element(start: int, step: int, lower_limit: int) -> int:
7475
return start + abs(step) * no_steps
7576

7677

78+
@set_module("pandas")
7779
class RangeIndex(Index):
7880
"""
7981
Immutable Index implementing a monotonic integer range.

pandas/core/indexes/timedeltas.py

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Timedelta,
1414
to_offset,
1515
)
16+
from pandas.util._decorators import set_module
1617

1718
from pandas.core.dtypes.common import (
1819
is_scalar,
@@ -50,6 +51,7 @@
5051
],
5152
TimedeltaArray,
5253
)
54+
@set_module("pandas")
5355
class TimedeltaIndex(DatetimeTimedeltaMixin):
5456
"""
5557
Immutable Index of timedelta64 data.

pandas/tests/api/test_api.py

+13
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,19 @@ def test_util_in_top_level(self):
400400

401401
def test_set_module():
402402
assert pd.DataFrame.__module__ == "pandas"
403+
assert pd.CategoricalDtype.__module__ == "pandas"
404+
assert pd.PeriodDtype.__module__ == "pandas"
405+
assert pd.IntervalDtype.__module__ == "pandas"
406+
assert pd.SparseDtype.__module__ == "pandas"
407+
assert pd.ArrowDtype.__module__ == "pandas"
408+
assert pd.Index.__module__ == "pandas"
409+
assert pd.CategoricalIndex.__module__ == "pandas"
410+
assert pd.DatetimeIndex.__module__ == "pandas"
411+
assert pd.IntervalIndex.__module__ == "pandas"
412+
assert pd.MultiIndex.__module__ == "pandas"
413+
assert pd.PeriodIndex.__module__ == "pandas"
414+
assert pd.RangeIndex.__module__ == "pandas"
415+
assert pd.TimedeltaIndex.__module__ == "pandas"
403416
assert pd.Period.__module__ == "pandas"
404417
assert pd.Timestamp.__module__ == "pandas"
405418
assert pd.Timedelta.__module__ == "pandas"

0 commit comments

Comments
 (0)