Skip to content

Commit d81171b

Browse files
DOC: set __module__ on remaining top-level functions (#62758)
Co-authored-by: Richard Shadrach <[email protected]>
1 parent 9234ed5 commit d81171b

File tree

22 files changed

+145
-96
lines changed

22 files changed

+145
-96
lines changed

pandas/_config/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,3 +944,11 @@ def is_callable(obj: object) -> bool:
944944
if not callable(obj):
945945
raise ValueError("Value must be a callable")
946946
return True
947+
948+
949+
# import set_module here would cause circular import
950+
get_option.__module__ = "pandas"
951+
set_option.__module__ = "pandas"
952+
describe_option.__module__ = "pandas"
953+
reset_option.__module__ = "pandas"
954+
option_context.__module__ = "pandas"

pandas/_libs/lib.pyx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ from cython cimport (
4141
from pandas._config import using_string_dtype
4242

4343
from pandas._libs.missing import check_na_tuples_nonequal
44+
from pandas.util._decorators import set_module
4445

4546
import_datetime()
4647

@@ -154,6 +155,7 @@ def memory_usage_of_objects(arr: object[:]) -> int64_t:
154155
# ----------------------------------------------------------------------
155156

156157

158+
@set_module("pandas.api.types")
157159
def is_scalar(val: object) -> bool:
158160
"""
159161
Return True if given object is scalar.
@@ -255,6 +257,7 @@ cdef int64_t get_itemsize(object val):
255257
return -1
256258

257259

260+
@set_module("pandas.api.types")
258261
def is_iterator(obj: object) -> bool:
259262
"""
260263
Check if the object is an iterator.
@@ -1095,6 +1098,7 @@ def indices_fast(ndarray[intp_t, ndim=1] index, const int64_t[:] labels, list ke
10951098

10961099
# core.common import for fast inference checks
10971100

1101+
@set_module("pandas.api.types")
10981102
def is_float(obj: object) -> bool:
10991103
"""
11001104
Return True if given object is float.
@@ -1128,6 +1132,7 @@ def is_float(obj: object) -> bool:
11281132
return util.is_float_object(obj)
11291133

11301134

1135+
@set_module("pandas.api.types")
11311136
def is_integer(obj: object) -> bool:
11321137
"""
11331138
Return True if given object is integer.
@@ -1172,6 +1177,7 @@ def is_int_or_none(obj) -> bool:
11721177
return obj is None or util.is_integer_object(obj)
11731178

11741179

1180+
@set_module("pandas.api.types")
11751181
def is_bool(obj: object) -> bool:
11761182
"""
11771183
Return True if given object is boolean.
@@ -1202,6 +1208,7 @@ def is_bool(obj: object) -> bool:
12021208
return util.is_bool_object(obj)
12031209

12041210

1211+
@set_module("pandas.api.types")
12051212
def is_complex(obj: object) -> bool:
12061213
"""
12071214
Return True if given object is complex.
@@ -1237,6 +1244,7 @@ cpdef bint is_decimal(object obj):
12371244
return isinstance(obj, Decimal)
12381245

12391246

1247+
@set_module("pandas.api.types")
12401248
def is_list_like(obj: object, allow_sets: bool = True) -> bool:
12411249
"""
12421250
Check if the object is list-like.
@@ -1520,6 +1528,7 @@ cdef object _try_infer_map(object dtype):
15201528
return None
15211529

15221530

1531+
@set_module("pandas.api.types")
15231532
def infer_dtype(value: object, skipna: bool = True) -> str:
15241533
"""
15251534
Return a string label of the type of the elements in a list-like input.

pandas/_testing/asserters.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
import pandas._libs.testing as _testing
1818
from pandas._libs.tslibs.np_datetime import compare_mismatched_resolutions
1919
from pandas.errors import Pandas4Warning
20-
from pandas.util._decorators import deprecate_kwarg
20+
from pandas.util._decorators import (
21+
deprecate_kwarg,
22+
set_module,
23+
)
2124

2225
from pandas.core.dtypes.common import (
2326
is_bool,
@@ -181,6 +184,7 @@ def assert_dict_equal(left, right, compare_keys: bool = True) -> None:
181184
_testing.assert_dict_equal(left, right, compare_keys=compare_keys)
182185

183186

187+
@set_module("pandas.testing")
184188
def assert_index_equal(
185189
left: Index,
186190
right: Index,
@@ -695,6 +699,7 @@ def _raise(left, right, err_msg) -> NoReturn:
695699
assert_attr_equal("dtype", left, right, obj=obj)
696700

697701

702+
@set_module("pandas.testing")
698703
def assert_extension_array_equal(
699704
left,
700705
right,
@@ -850,6 +855,7 @@ def assert_extension_array_equal(
850855

851856

852857
# This could be refactored to use the NDFrame.equals method
858+
@set_module("pandas.testing")
853859
@deprecate_kwarg(Pandas4Warning, "check_datetimelike_compat", new_arg_name=None)
854860
def assert_series_equal(
855861
left,
@@ -1143,6 +1149,7 @@ def assert_series_equal(
11431149

11441150

11451151
# This could be refactored to use the NDFrame.equals method
1152+
@set_module("pandas.testing")
11461153
@deprecate_kwarg(Pandas4Warning, "check_datetimelike_compat", new_arg_name=None)
11471154
def assert_frame_equal(
11481155
left,

pandas/core/accessor.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
)
1515
import warnings
1616

17-
from pandas.util._decorators import doc
17+
from pandas.util._decorators import (
18+
doc,
19+
set_module,
20+
)
1821
from pandas.util._exceptions import find_stack_level
1922

2023
if TYPE_CHECKING:
@@ -323,6 +326,7 @@ def decorator(accessor: TypeT) -> TypeT:
323326
dtype: int64"""
324327

325328

329+
@set_module("pandas.api.extensions")
326330
@doc(_register_accessor, klass="DataFrame", examples=_register_df_examples)
327331
def register_dataframe_accessor(name: str) -> Callable[[TypeT], TypeT]:
328332
from pandas import DataFrame
@@ -354,6 +358,7 @@ def register_dataframe_accessor(name: str) -> Callable[[TypeT], TypeT]:
354358
np.int64(6)"""
355359

356360

361+
@set_module("pandas.api.extensions")
357362
@doc(_register_accessor, klass="Series", examples=_register_series_examples)
358363
def register_series_accessor(name: str) -> Callable[[TypeT], TypeT]:
359364
from pandas import Series
@@ -388,6 +393,7 @@ def register_series_accessor(name: str) -> Callable[[TypeT], TypeT]:
388393
[2, 8]"""
389394

390395

396+
@set_module("pandas.api.extensions")
391397
@doc(_register_accessor, klass="Index", examples=_register_index_examples)
392398
def register_index_accessor(name: str) -> Callable[[TypeT], TypeT]:
393399
from pandas import Index

pandas/core/algorithms.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
TakeIndexer,
3636
npt,
3737
)
38-
from pandas.util._decorators import doc
38+
from pandas.util._decorators import (
39+
doc,
40+
set_module,
41+
)
3942
from pandas.util._exceptions import find_stack_level
4043

4144
from pandas.core.dtypes.cast import (
@@ -325,6 +328,7 @@ def unique(values: T) -> T: ...
325328
def unique(values: np.ndarray | Series) -> np.ndarray: ...
326329

327330

331+
@set_module("pandas")
328332
def unique(values):
329333
"""
330334
Return unique values based on a hash table.
@@ -649,6 +653,7 @@ def factorize_array(
649653
return codes, uniques
650654

651655

656+
@set_module("pandas")
652657
@doc(
653658
values=dedent(
654659
"""\
@@ -1111,6 +1116,7 @@ def rank(
11111116
# ---- #
11121117

11131118

1119+
@set_module("pandas.api.extensions")
11141120
def take(
11151121
arr,
11161122
indices: TakeIndexer,

pandas/core/col.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
Any,
1010
)
1111

12+
from pandas.util._decorators import set_module
13+
1214
from pandas.core.series import Series
1315

1416
if TYPE_CHECKING:
@@ -222,6 +224,7 @@ def wrapper(*args: Any, **kwargs: Any) -> Expression:
222224
return wrapper
223225

224226

227+
@set_module("pandas")
225228
def col(col_name: Hashable) -> Expression:
226229
"""
227230
Generate deferred object representing a column of a DataFrame.

pandas/core/computation/eval.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
)
1212
import warnings
1313

14+
from pandas.util._decorators import set_module
1415
from pandas.util._exceptions import find_stack_level
1516
from pandas.util._validators import validate_bool_kwarg
1617

@@ -174,6 +175,7 @@ def _check_for_locals(expr: str, stack_level: int, parser: str) -> None:
174175
raise SyntaxError(msg)
175176

176177

178+
@set_module("pandas")
177179
def eval(
178180
expr: str | BinOp, # we leave BinOp out of the docstr bc it isn't for users
179181
parser: str = "pandas",

pandas/core/construction.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
get_supported_dtype,
2424
is_supported_dtype,
2525
)
26+
from pandas.util._decorators import set_module
2627

2728
from pandas.core.dtypes.base import ExtensionDtype
2829
from pandas.core.dtypes.cast import (
@@ -72,6 +73,7 @@
7273
)
7374

7475

76+
@set_module("pandas")
7577
def array(
7678
data: Sequence[object] | AnyArrayLike,
7779
dtype: Dtype | None = None,

pandas/core/dtypes/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from pandas._libs.hashtable import object_hash
2020
from pandas._libs.properties import cache_readonly
2121
from pandas.errors import AbstractMethodError
22+
from pandas.util._decorators import set_module
2223

2324
from pandas.core.dtypes.generic import (
2425
ABCDataFrame,
@@ -480,6 +481,7 @@ def na_value(self) -> libmissing.NAType:
480481
return libmissing.NA
481482

482483

484+
@set_module("pandas.api.extensions")
483485
def register_extension_dtype(cls: type_t[ExtensionDtypeT]) -> type_t[ExtensionDtypeT]:
484486
"""
485487
Register an ExtensionType with pandas as class decorator.

0 commit comments

Comments
 (0)