diff --git a/pandas/core/api.py b/pandas/core/api.py index c8a4e9d8a23b2..d7f40af5ef0fe 100644 --- a/pandas/core/api.py +++ b/pandas/core/api.py @@ -67,7 +67,7 @@ ) from pandas.core.indexes.period import period_range from pandas.core.indexes.timedeltas import timedelta_range -from pandas.core.indexing import IndexSlice +from pandas.core.indexing import IndexSlice as _IndexSlice from pandas.core.series import Series from pandas.core.tools.datetimes import to_datetime from pandas.core.tools.numeric import to_numeric @@ -79,6 +79,8 @@ # DataFrame needs to be imported after NamedAgg to avoid a circular import from pandas.core.frame import DataFrame # isort:skip +IndexSlice = _IndexSlice() + __all__ = [ "array", "ArrowDtype", diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 0d6d7e68f58a4..4003eb0e5f1cb 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -24,7 +24,10 @@ LossySetitemError, ) from pandas.errors.cow import _chained_assignment_msg -from pandas.util._decorators import doc +from pandas.util._decorators import ( + doc, + set_module, +) from pandas.core.dtypes.cast import ( can_hold_element, @@ -98,7 +101,8 @@ # the public IndexSlicerMaker -class _IndexSlice: +@set_module("pandas") +class IndexSlice: """ Create an object to more easily perform multi-index slicing. @@ -145,9 +149,6 @@ def __getitem__(self, arg): return arg -IndexSlice = _IndexSlice() - - class IndexingMixin: """ Mixin for adding .loc/.iloc/.at/.iat to Dataframes and Series. diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py index 75f9958b16286..3f659a15b97c9 100644 --- a/pandas/tests/api/test_api.py +++ b/pandas/tests/api/test_api.py @@ -417,6 +417,7 @@ def test_set_module(): assert pd.Period.__module__ == "pandas" assert pd.Timestamp.__module__ == "pandas" assert pd.Timedelta.__module__ == "pandas" + assert pd.IndexSlice.__module__ == "pandas" assert pd.isna.__module__ == "pandas" assert pd.notna.__module__ == "pandas" assert pd.merge.__module__ == "pandas"