From b1e25d99ab3bcea0e680a5970e7987c3b8badefc Mon Sep 17 00:00:00 2001 From: Thomas Li Date: Mon, 27 Jan 2020 19:42:34 -0800 Subject: [PATCH 1/4] Deprecate core --- pandas/__init__.py | 38 ++++++++++++++++++++++++++++++++++++ pandas/tests/api/test_api.py | 7 ++++--- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/pandas/__init__.py b/pandas/__init__.py index d526531b159b2..8e100b45dd2ef 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,28 @@ 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: __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..8b870df0a0959 100644 --- a/pandas/tests/api/test_api.py +++ b/pandas/tests/api/test_api.py @@ -46,7 +46,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 +190,7 @@ class TestPDApi(Base): # private modules in pandas namespace private_modules = [ "_config", + "_core", "_hashtable", "_lib", "_libs", @@ -241,11 +242,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(): From 2c29df13d708eb38ef3b1d591ac32a87ef5b9ae8 Mon Sep 17 00:00:00 2001 From: Thomas Li Date: Mon, 27 Jan 2020 19:45:24 -0800 Subject: [PATCH 2/4] Fix api test --- pandas/tests/api/test_api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py index 8b870df0a0959..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", From 6e229f0416fa248b9742d34d49d7cd9e1f7e6da6 Mon Sep 17 00:00:00 2001 From: Thomas Li Date: Mon, 27 Jan 2020 19:49:08 -0800 Subject: [PATCH 3/4] Whatsnew --- doc/source/whatsnew/v1.1.0.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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. - .. --------------------------------------------------------------------------- From 70f0146f3c9da96251dbde107d9b20c32b202b3b Mon Sep 17 00:00:00 2001 From: Thomas Li Date: Mon, 27 Jan 2020 20:32:22 -0800 Subject: [PATCH 4/4] Docstring and mypy fixes --- pandas/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/__init__.py b/pandas/__init__.py index 8e100b45dd2ef..6d16ec77237af 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -395,10 +395,9 @@ def __getattr__(self, item): ) return attr - _core = __core() + _core: __core = __core() # type: ignore core: __core = __core() - # module level doc-string __doc__ = """ pandas - a powerful data analysis and manipulation library for Python