Skip to content

DEPR: Deprecate core #31377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion doc/source/whatsnew/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
-

.. ---------------------------------------------------------------------------
Expand Down
37 changes: 37 additions & 0 deletions pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this f-string do?

FutureWarning,
stacklevel=2,
)

return _core

raise AttributeError(f"module 'pandas' has no attribute '{name}'")


Expand Down Expand Up @@ -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__ = """
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class TestPDApi(Base):
"api",
"arrays",
"compat",
"core",
"errors",
"pandas",
"plotting",
Expand All @@ -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"]
Expand Down Expand Up @@ -190,6 +189,7 @@ class TestPDApi(Base):
# private modules in pandas namespace
private_modules = [
"_config",
"_core",
"_hashtable",
"_lib",
"_libs",
Expand Down Expand Up @@ -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():
Expand Down