Skip to content

Commit 59f66a8

Browse files
committed
ENH: set __module__ for objects in pandas Scalars API
1 parent e51039a commit 59f66a8

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

pandas/_libs/interval.pyx

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ from pandas._libs.tslibs.util cimport (
4040
is_float_object,
4141
is_integer_object,
4242
)
43+
from pandas.util._decorators import set_module
4344

4445
VALID_CLOSED = frozenset(["left", "right", "both", "neither"])
4546

@@ -281,6 +282,7 @@ cdef bint _interval_like(other):
281282
and hasattr(other, "closed"))
282283

283284

285+
@set_module("pandas")
284286
cdef class Interval(IntervalMixin):
285287
"""
286288
Immutable object implementing an Interval, a bounded slice-like interval.

pandas/_libs/tslibs/period.pyx

+3-1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ from pandas._libs.tslibs.offsets import (
115115
BDay,
116116
)
117117

118+
from pandas.util._decorators import set_module
119+
118120
cdef:
119121
enum:
120122
INT32_MIN = -2_147_483_648LL
@@ -2661,7 +2663,7 @@ cdef class _Period(PeriodMixin):
26612663
base = self._dtype._dtype_code
26622664
return period_format(self.ordinal, base, fmt)
26632665

2664-
2666+
@set_module("pandas")
26652667
class Period(_Period):
26662668
"""
26672669
Represents a period of time.

pandas/_libs/tslibs/timedeltas.pyx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import collections
22
import warnings
33

4+
from pandas.util._decorators import set_module
45
from pandas.util._exceptions import find_stack_level
56

67
cimport cython
@@ -1771,7 +1772,7 @@ cdef class _Timedelta(timedelta):
17711772

17721773
# Python front end to C extension type _Timedelta
17731774
# This serves as the box for timedelta64
1774-
1775+
@set_module("pandas")
17751776
class Timedelta(_Timedelta):
17761777
"""
17771778
Represents a duration, the difference between two dates or times.

pandas/_libs/tslibs/timestamps.pyx

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import datetime as dt
5050
from pandas._libs.tslibs cimport ccalendar
5151
from pandas._libs.tslibs.base cimport ABCTimestamp
5252

53+
from pandas.util._decorators import set_module
5354
from pandas.util._exceptions import find_stack_level
5455

5556
from pandas._libs.tslibs.conversion cimport (
@@ -1263,7 +1264,7 @@ cdef class _Timestamp(ABCTimestamp):
12631264
# Python front end to C extension type _Timestamp
12641265
# This serves as the box for datetime64
12651266

1266-
1267+
@set_module("pandas")
12671268
class Timestamp(_Timestamp):
12681269
"""
12691270
Pandas replacement for python datetime.datetime object.

pandas/tests/api/test_api.py

+4
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,7 @@ def test_pandas_array_alias():
405405

406406
def test_set_module():
407407
assert pd.DataFrame.__module__ == "pandas"
408+
assert pd.Interval.__module__ == "pandas"
409+
assert pd.Period.__module__ == "pandas"
410+
assert pd.Timestamp.__module__ == "pandas"
411+
assert pd.Timedelta.__module__ == "pandas"

0 commit comments

Comments
 (0)