diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 920919755dc23..10dd73d811b5e 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -69,7 +69,8 @@ Backwards incompatible API changes Deprecations ~~~~~~~~~~~~ -- +- Access to the ``pandas.core`` submodule is now deprecated, and the module will be moving to ``pandas._core`` in the future. + Please import all classes/methods from the top level pandas namespace instead. - .. --------------------------------------------------------------------------- diff --git a/pandas/__init__.py b/pandas/__init__.py index d526531b159b2..6d16ec77237af 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -190,6 +190,10 @@ # TODO: remove Panel compat in 1.0 if pandas.compat.PY37: + import pandas.core as _core + + del pandas.core + def __getattr__(name): import warnings @@ -256,6 +260,18 @@ class Panel: return _SparseArray + elif name == "core": + + warnings.warn( + "The pandas.core module is private and access " + "will be moved to pandas._core in a future version. " + f"You should import directly from the pandas namespace instead", + FutureWarning, + stacklevel=2, + ) + + return _core + raise AttributeError(f"module 'pandas' has no attribute '{name}'") @@ -360,6 +376,27 @@ def __new__(cls, *args, **kwargs): SparseArray = __SparseArraySub + class __core: + def __init__(self): + import pandas.core as core + import warnings + + self._core = core + self._warnings = warnings + + def __getattr__(self, item): + attr = getattr(self._core, item) + self._warnings.warn( + "The pandas.core module is private and access " + "will be moved to pandas._core in a future version. " + f"You should import pandas.{item} directly instead", + FutureWarning, + stacklevel=2, + ) + return attr + + _core: __core = __core() # type: ignore + core: __core = __core() # module level doc-string __doc__ = """ diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py index 406d5f055797d..42b9f8bcbc04c 100644 --- a/pandas/tests/api/test_api.py +++ b/pandas/tests/api/test_api.py @@ -33,7 +33,6 @@ class TestPDApi(Base): "api", "arrays", "compat", - "core", "errors", "pandas", "plotting", @@ -46,7 +45,7 @@ class TestPDApi(Base): ] # these are already deprecated; awaiting removal - deprecated_modules: List[str] = ["np", "datetime"] + deprecated_modules: List[str] = ["np", "datetime", "core"] # misc misc = ["IndexSlice", "NaT", "NA"] @@ -190,6 +189,7 @@ class TestPDApi(Base): # private modules in pandas namespace private_modules = [ "_config", + "_core", "_hashtable", "_lib", "_libs", @@ -241,11 +241,11 @@ def test_depr(self): deprecated = getattr(pd, depr) if not compat.PY37: if depr == "datetime": - deprecated.__getattr__(dir(pd.datetime.datetime)[-1]) + deprecated.__getattr__(dir(pd.datetime.datetime)[0]) elif depr == "SparseArray": deprecated([]) else: - deprecated.__getattr__(dir(deprecated)[-1]) + deprecated.__getattr__(dir(deprecated)[0]) def test_datetime():