Skip to content

DEPR: Deprecate pandas.datetime #30489

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 13 commits into from
Jan 2, 2020
Merged
Prev Previous commit
Next Next commit
Fix test and warning message
  • Loading branch information
ryankarlos committed Dec 26, 2019
commit 0329d2445fa084b10fd4a8a0a1ff08afe8a7bd13
12 changes: 7 additions & 5 deletions pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ class Panel:

elif name == "datetime":
warnings.warn(
"The datetime class is removed from pandas. Accessing it from "
"the top-level namespace will also be removed in the next "
"version",
"The pandas.datetime module is deprecated "
"and will be removed from pandas in a future version. "
"Import datetime directly instead.",
FutureWarning,
stacklevel=2,
)
Expand All @@ -236,6 +236,7 @@ class Panel:

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


else:

class Panel:
Expand All @@ -257,8 +258,9 @@ def __init__(self):

def __getattr__(self, item):
self.warnings.warn(
"The pandas.datetime module is deprecated and will be removed from pandas in a future version. "
"Import numpy directly instead",
"The pandas.datetime module is deprecated "
Copy link
Member

Choose a reason for hiding this comment

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

same as before

"and will be removed from pandas in a future version. "
"Import datetime directly instead.",
FutureWarning,
stacklevel=2,
)
Expand Down
13 changes: 9 additions & 4 deletions pandas/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,16 @@ def test_api(self):

def test_datetime():
from datetime import datetime
import warnings

with warnings.catch_warnings():
warnings.simplefilter("ignore", FutureWarning)
assert datetime.date(2015, 7, 10) == pd.datetime.date(2015, 7, 10)
msg = (
"The pandas.datetime module is deprecated "
"and will be removed from pandas in a future version. "
"Import datetime directly instead."
)

with tm.assert_produces_warning(FutureWarning) as w:
assert datetime(2015, 1, 2, 0, 0) == pd.datetime(2015, 1, 2, 0, 0)
assert msg in str(w[-1].message)


class TestApi(Base):
Expand Down