Skip to content

Commit 5b25e33

Browse files
jbrockmendelproost
authored andcommitted
DEPR: Timedelta.__rfloordiv__(int_dtype) (pandas-dev#29797)
1 parent c36ae26 commit 5b25e33

File tree

4 files changed

+11
-24
lines changed

4 files changed

+11
-24
lines changed

doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
401401

402402
**Other removals**
403403

404+
- Floordiv of integer-dtyped array by :class:`Timedelta` now raises ``TypeError`` (:issue:`21036`)
404405
- Removed the previously deprecated :meth:`Index.summary` (:issue:`18217`)
405406
- Removed the previously deprecated :meth:`Series.get_value`, :meth:`Series.set_value`, :meth:`DataFrame.get_value`, :meth:`DataFrame.set_value` (:issue:`17739`)
406407
- Changed the the default value of `inplace` in :meth:`DataFrame.set_index` and :meth:`Series.set_axis`. It now defaults to False (:issue:`27600`)

pandas/_libs/tslibs/timedeltas.pyx

+2-12
Original file line numberDiff line numberDiff line change
@@ -1509,18 +1509,8 @@ class Timedelta(_Timedelta):
15091509
if other.dtype.kind == 'm':
15101510
# also timedelta-like
15111511
return _broadcast_floordiv_td64(self.value, other, _rfloordiv)
1512-
elif other.dtype.kind == 'i':
1513-
# Backwards compatibility
1514-
# GH-19761
1515-
msg = textwrap.dedent("""\
1516-
Floor division between integer array and Timedelta is
1517-
deprecated. Use 'array // timedelta.value' instead.
1518-
If you want to obtain epochs from an array of timestamps,
1519-
you can rather use
1520-
'(array - pd.Timestamp("1970-01-01")) // pd.Timedelta("1s")'.
1521-
""")
1522-
warnings.warn(msg, FutureWarning)
1523-
return other // self.value
1512+
1513+
# Includes integer array // Timedelta, deprecated in GH#19761
15241514
raise TypeError(f'Invalid dtype {other.dtype} for __floordiv__')
15251515

15261516
elif is_float_object(other) and util.is_nan(other):

pandas/tests/scalar/timedelta/test_arithmetic.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ def test_td_rfloordiv_numeric_scalar(self):
463463
td.__rfloordiv__(np.float64(2.0))
464464
with pytest.raises(TypeError):
465465
td.__rfloordiv__(np.uint8(9))
466-
with tm.assert_produces_warning(FutureWarning):
467-
# GH-19761: Change to TypeError.
466+
with pytest.raises(TypeError, match="Invalid dtype"):
467+
# deprecated GH#19761, enforced GH#29797
468468
td.__rfloordiv__(np.int32(2.0))
469469

470470
def test_td_rfloordiv_timedeltalike_array(self):
@@ -490,7 +490,9 @@ def test_td_rfloordiv_numeric_series(self):
490490
ser = pd.Series([1], dtype=np.int64)
491491
res = td.__rfloordiv__(ser)
492492
assert res is NotImplemented
493-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
493+
494+
with pytest.raises(TypeError, match="Invalid dtype"):
495+
# Deprecated GH#19761, enforced GH#29797
494496
# TODO: GH-19761. Change to TypeError.
495497
ser // td
496498

pandas/tests/scalar/timedelta/test_timedelta.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,11 @@ def test_arithmetic_overflow(self):
2121
Timestamp("1700-01-01") + timedelta(days=13 * 19999)
2222

2323
def test_array_timedelta_floordiv(self):
24-
# https://github.com/pandas-dev/pandas/issues/19761
24+
# deprected GH#19761, enforced GH#29797
2525
ints = pd.date_range("2012-10-08", periods=4, freq="D").view("i8")
26-
msg = r"Use 'array // timedelta.value'"
27-
with tm.assert_produces_warning(FutureWarning) as m:
28-
result = ints // Timedelta(1, unit="s")
2926

30-
assert msg in str(m[0].message)
31-
expected = np.array(
32-
[1349654400, 1349740800, 1349827200, 1349913600], dtype="i8"
33-
)
34-
tm.assert_numpy_array_equal(result, expected)
27+
with pytest.raises(TypeError, match="Invalid dtype"):
28+
ints // Timedelta(1, unit="s")
3529

3630
def test_ops_error_str(self):
3731
# GH 13624

0 commit comments

Comments
 (0)