Skip to content

Commit a9a9588

Browse files
committed
updates
1 parent 346f71c commit a9a9588

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

doc/source/whatsnew/v0.24.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ Deprecations
12601260
- :meth:`Series.nonzero` is deprecated and will be removed in a future version (:issue:`18262`)
12611261
- Passing an integer to :meth:`Series.fillna` and :meth:`DataFrame.fillna` with ``timedelta64[ns]`` dtypes is deprecated, will raise ``TypeError`` in a future version. Use ``obj.fillna(pd.Timedelta(...))`` instead (:issue:`24694`)
12621262
- ``Series.cat.categorical``, ``Series.cat.name`` and ``Sersies.cat.index`` have been deprecated. Use the attributes on ``Series.cat`` or ``Series`` directly. (:issue:`24751`).
1263-
- Passing a dtype without a precision like ``np.dtype('datetime64')`` or ``timedelta64`` to :class:`DatetimeIndex` and :class:`TimedeltaIndex` is now deprecated. Use the nanosecond-precision dtype instead (:issue:`24753`).
1263+
- Passing a dtype without a precision like ``np.dtype('datetime64')`` or ``timedelta64`` to :class:`Index`, :class:`DatetimeIndex` and :class:`TimedeltaIndex` is now deprecated. Use the nanosecond-precision dtype instead (:issue:`24753`).
12641264

12651265
.. _whatsnew_0240.deprecations.datetimelike_int_ops:
12661266

pandas/core/arrays/datetimes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,8 +1987,7 @@ def _validate_dt64_dtype(dtype):
19871987
"""
19881988
if dtype is not None:
19891989
dtype = pandas_dtype(dtype)
1990-
1991-
if isinstance(dtype, np.dtype) and dtype == np.dtype("M8"):
1990+
if is_dtype_equal(dtype, np.dtype("M8")):
19921991
# no precision, warn
19931992
dtype = _NS_DTYPE
19941993
msg = textwrap.dedent("""\

pandas/core/arrays/timedeltas.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
from pandas.util._decorators import Appender
1717

1818
from pandas.core.dtypes.common import (
19-
_NS_DTYPE, _TD_DTYPE, ensure_int64, is_datetime64_dtype, is_float_dtype,
20-
is_integer_dtype, is_list_like, is_object_dtype, is_scalar,
19+
_NS_DTYPE, _TD_DTYPE, ensure_int64, is_datetime64_dtype, is_dtype_equal,
20+
is_float_dtype, is_integer_dtype, is_list_like, is_object_dtype, is_scalar,
2121
is_string_dtype, is_timedelta64_dtype, is_timedelta64_ns_dtype,
2222
pandas_dtype)
2323
from pandas.core.dtypes.dtypes import DatetimeTZDtype
@@ -990,25 +990,17 @@ def objects_to_td64ns(data, unit="ns", errors="raise"):
990990

991991

992992
def _validate_td64_dtype(dtype):
993-
try:
994-
if dtype == np.dtype("timedelta64"):
995-
dtype = _TD_DTYPE
996-
msg = textwrap.dedent("""\
997-
Passing in 'timedelta' dtype with no precision is deprecated
998-
and will raise in a future version. Please pass in
999-
'timedelta64[ns]' instead.""")
1000-
warnings.warn(msg, FutureWarning, stacklevel=4)
1001-
except TypeError:
1002-
# extension dtype
1003-
pass
1004-
1005-
try:
1006-
dtype_mismatch = dtype != _TD_DTYPE
1007-
except TypeError:
993+
dtype = pandas_dtype(dtype)
994+
if is_dtype_equal(dtype, np.dtype("timedelta64")):
995+
dtype = _TD_DTYPE
996+
msg = textwrap.dedent("""\
997+
Passing in 'timedelta' dtype with no precision is deprecated
998+
and will raise in a future version. Please pass in
999+
'timedelta64[ns]' instead.""")
1000+
warnings.warn(msg, FutureWarning, stacklevel=4)
1001+
1002+
if not is_dtype_equal(dtype, _TD_DTYPE):
10081003
raise ValueError(_BAD_DTYPE.format(dtype=dtype))
1009-
else:
1010-
if dtype_mismatch:
1011-
raise ValueError(_BAD_DTYPE.format(dtype=dtype))
10121004

10131005
return dtype
10141006

0 commit comments

Comments
 (0)