diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index f231c2b31abb1..6ce48b18b3fa1 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -376,6 +376,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more. **Other removals** +- Floordiv of integer-dtyped array by :class:`Timedelta` now raises ``TypeError`` (:issue:`21036`) - Removed the previously deprecated :meth:`Index.summary` (:issue:`18217`) - Removed the previously deprecated :meth:`Series.get_value`, :meth:`Series.set_value`, :meth:`DataFrame.get_value`, :meth:`DataFrame.set_value` (:issue:`17739`) - Changed the the default value of `inplace` in :meth:`DataFrame.set_index` and :meth:`Series.set_axis`. It now defaults to False (:issue:`27600`) diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index 8e5b719749857..48a2a05011ab5 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -1509,18 +1509,8 @@ class Timedelta(_Timedelta): if other.dtype.kind == 'm': # also timedelta-like return _broadcast_floordiv_td64(self.value, other, _rfloordiv) - elif other.dtype.kind == 'i': - # Backwards compatibility - # GH-19761 - msg = textwrap.dedent("""\ - Floor division between integer array and Timedelta is - deprecated. Use 'array // timedelta.value' instead. - If you want to obtain epochs from an array of timestamps, - you can rather use - '(array - pd.Timestamp("1970-01-01")) // pd.Timedelta("1s")'. - """) - warnings.warn(msg, FutureWarning) - return other // self.value + + # Includes integer array // Timedelta, deprecated in GH#19761 raise TypeError(f'Invalid dtype {other.dtype} for __floordiv__') elif is_float_object(other) and util.is_nan(other): diff --git a/pandas/tests/scalar/timedelta/test_arithmetic.py b/pandas/tests/scalar/timedelta/test_arithmetic.py index 2ba55b22a7c54..57e0b1d743984 100644 --- a/pandas/tests/scalar/timedelta/test_arithmetic.py +++ b/pandas/tests/scalar/timedelta/test_arithmetic.py @@ -463,8 +463,8 @@ def test_td_rfloordiv_numeric_scalar(self): td.__rfloordiv__(np.float64(2.0)) with pytest.raises(TypeError): td.__rfloordiv__(np.uint8(9)) - with tm.assert_produces_warning(FutureWarning): - # GH-19761: Change to TypeError. + with pytest.raises(TypeError, match="Invalid dtype"): + # deprecated GH#19761, enforced GH#29797 td.__rfloordiv__(np.int32(2.0)) def test_td_rfloordiv_timedeltalike_array(self): @@ -490,7 +490,9 @@ def test_td_rfloordiv_numeric_series(self): ser = pd.Series([1], dtype=np.int64) res = td.__rfloordiv__(ser) assert res is NotImplemented - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + + with pytest.raises(TypeError, match="Invalid dtype"): + # Deprecated GH#19761, enforced GH#29797 # TODO: GH-19761. Change to TypeError. ser // td diff --git a/pandas/tests/scalar/timedelta/test_timedelta.py b/pandas/tests/scalar/timedelta/test_timedelta.py index 9bb6c991a930a..d4881ff0e1747 100644 --- a/pandas/tests/scalar/timedelta/test_timedelta.py +++ b/pandas/tests/scalar/timedelta/test_timedelta.py @@ -21,17 +21,11 @@ def test_arithmetic_overflow(self): Timestamp("1700-01-01") + timedelta(days=13 * 19999) def test_array_timedelta_floordiv(self): - # https://github.com/pandas-dev/pandas/issues/19761 + # deprected GH#19761, enforced GH#29797 ints = pd.date_range("2012-10-08", periods=4, freq="D").view("i8") - msg = r"Use 'array // timedelta.value'" - with tm.assert_produces_warning(FutureWarning) as m: - result = ints // Timedelta(1, unit="s") - assert msg in str(m[0].message) - expected = np.array( - [1349654400, 1349740800, 1349827200, 1349913600], dtype="i8" - ) - tm.assert_numpy_array_equal(result, expected) + with pytest.raises(TypeError, match="Invalid dtype"): + ints // Timedelta(1, unit="s") def test_ops_error_str(self): # GH 13624