8000 DEPR: Deprecate pandas.np module by lithomas1 · Pull Request #30386 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

DEPR: Deprecate pandas.np module #30386

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

Merged
merged 14 commits into from
Dec 27, 2019
Merged
Prev Previous commit
Next Next commit
Rewrite tests and numpy wrapper
  • Loading branch information
lithomas1 committed Dec 22, 2019
commit 1da5ba8a0c47baf7fc7c860740b8ed473ca7bd1d
12 changes: 7 additions & 5 deletions pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,24 +247,26 @@ class SparseDataFrame:
class SparseSeries:
pass

class numpy:
class __numpy:
def __init__(self):
import numpy as np
import warnings

self.np = np
self.warnings = warnings

def __getattr__(self, item):
self.warnings.warn(
def __getattribute__(self, item):
np = object.__getattribute__(self, "np")
warnings = object.__getattribute__(self, "warnings")
warnings.warn(
"The pandas.np module is deprecated and will be removed from pandas in a future version. "
"Import numpy directly instead",
FutureWarning,
stacklevel=2,
)
return getattr(self.np, item)
return object.__getattribute__(np, item)

np = numpy()
np = __numpy()

# module level doc-string
__doc__ = """
Expand Down
8 changes: 6 additions & 2 deletions pandas/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class TestPDApi(Base):
]
if not compat.PY37:
classes.extend(["Panel", "SparseSeries", "SparseDataFrame"])
deprecated_modules.extend("np")
deprecated_modules.append("np")

# these are already deprecated; awaiting removal
deprecated_classes: List[str] = []
Expand Down Expand Up @@ -231,7 +231,11 @@ def test_depr(self):
)
for depr in deprecated:
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
getattr(pd, depr)
if compat.PY37:
getattr(pd, depr)
else:
deprecated = getattr(pd, depr)
getattr(deprecated, dir(deprecated)[-1])


class TestApi(Base):
Expand Down
0