Skip to content

Commit eb9b703

Browse files
committed
Added M and Y units deprecated test and whats new note
1 parent df3ebe4 commit eb9b703

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

doc/source/whatsnew/v0.24.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,7 @@ Deprecations
10451045
- The ``keep_tz=False`` option (the default) of the ``keep_tz`` keyword of
10461046
:meth:`DatetimeIndex.to_series` is deprecated (:issue:`17832`).
10471047
- Timezone converting a tz-aware ``datetime.datetime`` or :class:`Timestamp` with :class:`Timestamp` and the ``tz`` argument is now deprecated. Instead, use :meth:`Timestamp.tz_convert` (:issue:`23579`)
1048+
- Deprecated the `M` and `Y` `units` parameter of :func: `pandas.to_timedelta`, :func: `pandas.Timedelta` and :func: `pandas.TimedeltaIndex`(:issue:`16344`)
10481049

10491050
.. _whatsnew_0240.deprecations.datetimelike_int_ops:
10501051

pandas/core/tools/timedeltas.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ def to_timedelta(arg, unit='ns', box=True, errors='raise'):
9393
raise ValueError("errors must be one of 'ignore', "
9494
"'raise', or 'coerce'}")
9595

96+
if unit in ['Y', 'y', 'M']:
97+
warnings.warn("M and Y units are deprecated.",
98+
FutureWarning, stacklevel=2)
99+
96100
if arg is None:
97101
return arg
98102
elif isinstance(arg, ABCSeries):

pandas/tests/scalar/timedelta/test_timedelta.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,14 @@ def test_unit_parser(self, units, np_unit, wrapper):
354354
result = Timedelta('2{}'.format(unit))
355355
assert result == expected
356356

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

0 commit comments

Comments
 (0)