Skip to content

DEPR: Timedelta.__rfloordiv__(int_dtype) #29797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
14 changes: 2 additions & 12 deletions pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 5 additions & 3 deletions pandas/tests/scalar/timedelta/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Expand Down
12 changes: 3 additions & 9 deletions pandas/tests/scalar/timedelta/test_timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down