Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pandas/_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,3 +944,11 @@ def is_callable(obj: object) -> bool:
if not callable(obj):
raise ValueError("Value must be a callable")
return True


# import set_module here would cause circular import
get_option.__module__ = "pandas"
set_option.__module__ = "pandas"
describe_option.__module__ = "pandas"
reset_option.__module__ = "pandas"
option_context.__module__ = "pandas"
9 changes: 9 additions & 0 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ from cython cimport (
from pandas._config import using_string_dtype

from pandas._libs.missing import check_na_tuples_nonequal
from pandas.util._decorators import set_module

import_datetime()

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


@set_module("pandas.api.types")
def is_scalar(val: object) -> bool:
"""
Return True if given object is scalar.
Expand Down Expand Up @@ -255,6 +257,7 @@ cdef int64_t get_itemsize(object val):
return -1


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

# core.common import for fast inference checks

@set_module("pandas.api.types")
def is_float(obj: object) -> bool:
"""
Return True if given object is float.
Expand Down Expand Up @@ -1128,6 +1132,7 @@ def is_float(obj: object) -> bool:
return util.is_float_object(obj)


@set_module("pandas.api.types")
def is_integer(obj: object) -> bool:
"""
Return True if given object is integer.
Expand Down Expand Up @@ -1172,6 +1177,7 @@ def is_int_or_none(obj) -> bool:
return obj is None or util.is_integer_object(obj)


@set_module("pandas.api.types")
def is_bool(obj: object) -> bool:
"""
Return True if given object is boolean.
Expand Down Expand Up @@ -1202,6 +1208,7 @@ def is_bool(obj: object) -> bool:
return util.is_bool_object(obj)


@set_module("pandas.api.types")
def is_complex(obj: object) -> bool:
"""
Return True if given object is complex.
Expand Down Expand Up @@ -1237,6 +1244,7 @@ cpdef bint is_decimal(object obj):
return isinstance(obj, Decimal)


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


@set_module("pandas.api.types")
def infer_dtype(value: object, skipna: bool = True) -> str:
"""
Return a string label of the type of the elements in a list-like input.
Expand Down
9 changes: 8 additions & 1 deletion pandas/_testing/asserters.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
import pandas._libs.testing as _testing
from pandas._libs.tslibs.np_datetime import compare_mismatched_resolutions
from pandas.errors import Pandas4Warning
from pandas.util._decorators import deprecate_kwarg
from pandas.util._decorators import (
deprecate_kwarg,
set_module,
)

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


@set_module("pandas.testing")
def assert_index_equal(
left: Index,
right: Index,
Expand Down Expand Up @@ -695,6 +699,7 @@ def _raise(left, right, err_msg) -> NoReturn:
assert_attr_equal("dtype", left, right, obj=obj)


@set_module("pandas.testing")
def assert_extension_array_equal(
left,
right,
Expand Down Expand Up @@ -850,6 +855,7 @@ def assert_extension_array_equal(


# This could be refactored to use the NDFrame.equals method
@set_module("pandas.testing")
@deprecate_kwarg(Pandas4Warning, "check_datetimelike_compat", new_arg_name=None)
def assert_series_equal(
left,
Expand Down Expand Up @@ -1143,6 +1149,7 @@ def assert_series_equal(


# This could be refactored to use the NDFrame.equals method
@set_module("pandas.testing")
@deprecate_kwarg(Pandas4Warning, "check_datetimelike_compat", new_arg_name=None)
def assert_frame_equal(
left,
Expand Down
8 changes: 7 additions & 1 deletion pandas/core/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
)
import warnings

from pandas.util._decorators import doc
from pandas.util._decorators import (
doc,
set_module,
)
from pandas.util._exceptions import find_stack_level

if TYPE_CHECKING:
Expand Down Expand Up @@ -323,6 +326,7 @@ def decorator(accessor: TypeT) -> TypeT:
dtype: int64"""


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


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


@set_module("pandas.api.extensions")
@doc(_register_accessor, klass="Index", examples=_register_index_examples)
def register_index_accessor(name: str) -> Callable[[TypeT], TypeT]:
from pandas import Index
Expand Down
8 changes: 7 additions & 1 deletion pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
TakeIndexer,
npt,
)
from pandas.util._decorators import doc
from pandas.util._decorators import (
doc,
set_module,
)
from pandas.util._exceptions import find_stack_level

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


@set_module("pandas")
def unique(values):
"""
Return unique values based on a hash table.
Expand Down Expand Up @@ -649,6 +653,7 @@ def factorize_array(
return codes, uniques


@set_module("pandas")
@doc(
values=dedent(
"""\
Expand Down Expand Up @@ -1111,6 +1116,7 @@ def rank(
# ---- #


@set_module("pandas.api.extensions")
def take(
arr,
indices: TakeIndexer,
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/col.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
Any,
)

from pandas.util._decorators import set_module

from pandas.core.series import Series

if TYPE_CHECKING:
Expand Down Expand Up @@ -222,6 +224,7 @@ def wrapper(*args: Any, **kwargs: Any) -> Expression:
return wrapper


@set_module("pandas")
def col(col_name: Hashable) -> Expression:
"""
Generate deferred object representing a column of a DataFrame.
Expand Down
2 changes: 2 additions & 0 deletions pandas/core/computation/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
)
import warnings

from pandas.util._decorators import set_module
from pandas.util._exceptions import find_stack_level
from pandas.util._validators import validate_bool_kwarg

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


@set_module("pandas")
def eval(
expr: str | BinOp, # we leave BinOp out of the docstr bc it isn't for users
parser: str = "pandas",
Expand Down
2 changes: 2 additions & 0 deletions pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
get_supported_dtype,
is_supported_dtype,
)
from pandas.util._decorators import set_module

from pandas.core.dtypes.base import ExtensionDtype
from pandas.core.dtypes.cast import (
Expand Down Expand Up @@ -72,6 +73,7 @@
)


@set_module("pandas")
def array(
data: Sequence[object] | AnyArrayLike,
dtype: Dtype | None = None,
Expand Down
2 changes: 2 additions & 0 deletions pandas/core/dtypes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from pandas._libs.hashtable import object_hash
from pandas._libs.properties import cache_readonly
from pandas.errors import AbstractMethodError
from pandas.util._decorators import set_module

from pandas.core.dtypes.generic import (
ABCDataFrame,
Expand Down Expand Up @@ -480,6 +481,7 @@ def na_value(self) -> libmissing.NAType:
return libmissing.NA


@set_module("pandas.api.extensions")
def register_extension_dtype(cls: type_t[ExtensionDtypeT]) -> type_t[ExtensionDtypeT]:
"""
Register an ExtensionType with pandas as class decorator.
Expand Down
Loading
Loading