Skip to content

Commit 0329d24

Browse files
committed
Fix test and warning message
1 parent 6d47e44 commit 0329d24

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

pandas/__init__.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ class Panel:
212212

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

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

239+
239240
else:
240241

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

258259
def __getattr__(self, item):
259260
self.warnings.warn(
260-
"The pandas.datetime module is deprecated and will be removed from pandas in a future version. "
261-
"Import numpy directly instead",
261+
"The pandas.datetime module is deprecated "
262+
"and will be removed from pandas in a future version. "
263+
"Import datetime directly instead.",
262264
FutureWarning,
263265
stacklevel=2,
264266
)

pandas/tests/api/test_api.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,16 @@ def test_api(self):
224224

225225
def test_datetime():
226226
from datetime import datetime
227-
import warnings
228227

229-
with warnings.catch_warnings():
230-
warnings.simplefilter("ignore", FutureWarning)
231-
assert datetime.date(2015, 7, 10) == pd.datetime.date(2015, 7, 10)
228+
msg = (
229+
"The pandas.datetime module is deprecated "
230+
"and will be removed from pandas in a future version. "
231+
"Import datetime directly instead."
232+
)
233+
234+
with tm.assert_produces_warning(FutureWarning) as w:
235+
assert datetime(2015, 1, 2, 0, 0) == pd.datetime(2015, 1, 2, 0, 0)
236+
assert msg in str(w[-1].message)
232237

233238

234239
class TestApi(Base):

0 commit comments

Comments
 (0)