Skip to content

Commit

Permalink
DEPR: Timedelta.__rfloordiv__(int_dtype) (pandas-dev#29797)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and proost committed Dec 19, 2019
1 parent 5760244 commit 592ea62
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 24 deletions.
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 @@ -401,6 +401,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

0 comments on commit 592ea62

Please sign in to comment.