Skip to content

Commit c2a93c3

Browse files
committed
Deprecate pandas.datetime and add whats new
1 parent cde73af commit c2a93c3

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ Other enhancements
207207
- The ``partition_cols`` argument in :meth:`DataFrame.to_parquet` now accepts a string (:issue:`27117`)
208208
- :func:`to_parquet` now appropriately handles the ``schema`` argument for user defined schemas in the pyarrow engine. (:issue: `30270`)
209209
- DataFrame constructor preserve `ExtensionArray` dtype with `ExtensionArray` (:issue:`11363`)
210+
- The pandas.datetime submodule is now deprecated. Import datetime directly instead(:issue:`30296`)
210211

211212

212213
Build Changes

pandas/__init__.py

+36-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
"the C extensions first.".format(module)
4040
)
4141

42-
from datetime import datetime
43-
4442
from pandas._config import (
4543
get_option,
4644
set_option,
@@ -211,6 +209,20 @@ class Panel:
211209
pass
212210

213211
return Panel
212+
213+
elif name == "datetime":
214+
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",
218+
FutureWarning,
219+
stacklevel=2,
220+
)
221+
222+
from datetime import datetime
223+
224+
return datetime
225+
214226
elif name in {"SparseSeries", "SparseDataFrame"}:
215227
warnings.warn(
216228
"The {} class is removed from pandas. Accessing it from "
@@ -224,7 +236,6 @@ class Panel:
224236

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

227-
228239
else:
229240

230241
class Panel:
@@ -236,6 +247,28 @@ class SparseDataFrame:
236247
class SparseSeries:
237248
pass
238249

250+
class Datetime:
251+
def __init__(self):
252+
from datetime import datetime
253+
import warnings
254+
255+
self.datetime = datetime
256+
self.warnings = warnings
257+
258+
def __getattr__(self, item):
259+
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",
262+
FutureWarning,
263+
stacklevel=2,
264+
)
265+
try:
266+
return getattr(self.datetime, item)
267+
except AttributeError:
268+
raise AttributeError(f"module datetime has no attribute {item}")
269+
270+
datetime = Datetime()
271+
239272

240273
# module level doc-string
241274
__doc__ = """

0 commit comments

Comments
 (0)