Skip to content

Commit 09eb209

Browse files
committed
Added M and Y units deprecated test and whats new note
1 parent 894f9bb commit 09eb209

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

doc/source/whatsnew/v0.24.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,7 @@ Deprecations
972972
`use_threads` to reflect the changes in pyarrow 0.11.0. (:issue:`23053`)
973973
- :func:`pandas.read_excel` has deprecated accepting ``usecols`` as an integer. Please pass in a list of ints from 0 to ``usecols`` inclusive instead (:issue:`23527`)
974974
- Constructing a :class:`TimedeltaIndex` from data with ``datetime64``-dtyped data is deprecated, will raise ``TypeError`` in a future version (:issue:`23539`)
975+
- Deprecated the `M` and `Y` `units` parameter of :func: `pandas.to_timedelta`, :func: `pandas.Timedelta` and :func: `pandas.TimedeltaIndex`
975976

976977
.. _whatsnew_0240.deprecations.datetimelike_int_ops:
977978

pandas/core/tools/timedeltas.py

+4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ def to_timedelta(arg, unit='ns', box=True, errors='raise'):
8080
raise ValueError("errors must be one of 'ignore', "
8181
"'raise', or 'coerce'}")
8282

83+
if unit in ['Y', 'y', 'M']:
84+
warnings.warn("M and Y units are deprecated.",
85+
FutureWarning, stacklevel=2)
86+
8387
if arg is None:
8488
return arg
8589
elif isinstance(arg, ABCSeries):

pandas/tests/scalar/timedelta/test_timedelta.py

+8
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,14 @@ def test_unit_parser(self, units, np_unit, wrapper):
352352
result = Timedelta('2{}'.format(unit))
353353
assert result == expected
354354

355+
@pytest.mark.parametrize('units', ['Y', 'y', 'M'])
356+
def test_unit_M_Y_deprecated(self, units):
357+
for unit in units:
358+
with tm.assert_produces_warning(FutureWarning):
359+
to_timedelta(10, unit)
360+
TimedeltaIndex([1, 1, 1], unit)
361+
Timedelta(10, unit)
362+
355363
def test_numeric_conversions(self):
356364
assert ct(0) == np.timedelta64(0, 'ns')
357365
assert ct(10) == np.timedelta64(10, 'ns')

0 commit comments

Comments
 (0)