Skip to content

Fix rfloordiv return type, un-xfail Timedelta tests #19820

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
Feb 22, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/v0.23.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ Timedelta
- Bug in :func:`Timedelta.__floordiv__`, :func:`Timedelta.__rfloordiv__` where operating with a ``Tick`` object would raise a ``TypeError`` instead of returning a numeric value (:issue:`19738`)
- Bug in :func:`Period.asfreq` where periods near ``datetime(1, 1, 1)`` could be converted incorrectly (:issue:`19643`)
- Bug in :func:`Timedelta.total_seconds()` causing precision errors i.e. ``Timedelta('30S').total_seconds()==30.000000000000004`` (:issue:`19458`)
- Bug in :func: `Timedelta.__rmod__` where operating with a ``numpy.timedelta64`` returned a ``timedelta64`` object instead of a ``Timedelta`` (:issue:`19378`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not the correct reference, can you update?

-

Timezones
Expand Down
12 changes: 10 additions & 2 deletions pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,11 @@ class Timedelta(_Timedelta):
return self // other.delta
return NotImplemented

if hasattr(other, 'dtype'):
elif is_timedelta64_object(other):
# convert to Timedelta below
pass

elif hasattr(other, 'dtype'):
if other.dtype.kind == 'm':
# also timedelta-like
return _broadcast_floordiv_td64(self.value, other, _floordiv)
Expand Down Expand Up @@ -1144,7 +1148,11 @@ class Timedelta(_Timedelta):
return other.delta // self
return NotImplemented

if hasattr(other, 'dtype'):
elif is_timedelta64_object(other):
# convert to Timedelta below
pass

elif hasattr(other, 'dtype'):
if other.dtype.kind == 'm':
# also timedelta-like
return _broadcast_floordiv_td64(self.value, other, _rfloordiv)
Expand Down
6 changes: 0 additions & 6 deletions pandas/tests/scalar/timedelta/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,13 @@ def test_mod_timedeltalike(self):
result = td % NaT
assert result is NaT

@pytest.mark.xfail(reason='GH#19378 floordiv td64 returns td64')
def test_mod_timedelta64_nat(self):
# GH#19365
td = Timedelta(hours=37)

result = td % np.timedelta64('NaT', 'ns')
assert result is NaT

@pytest.mark.xfail(reason='GH#19378 floordiv td64 returns td64')
def test_mod_timedelta64(self):
# GH#19365
td = Timedelta(hours=37)
Expand All @@ -458,7 +456,6 @@ def test_mod_timedelta64(self):
assert isinstance(result, Timedelta)
assert result == Timedelta(hours=1)

@pytest.mark.xfail(reason='GH#19378 floordiv by Tick not implemented')
def test_mod_offset(self):
# GH#19365
td = Timedelta(hours=37)
Expand Down Expand Up @@ -505,7 +502,6 @@ def test_rmod_pytimedelta(self):
assert isinstance(result, Timedelta)
assert result == Timedelta(minutes=1)

@pytest.mark.xfail(reason='GH#19378 floordiv by Tick not implemented')
def test_rmod_timedelta64(self):
# GH#19365
td = Timedelta(minutes=3)
Expand Down Expand Up @@ -564,7 +560,6 @@ def test_divmod(self):
assert np.isnan(result[0])
assert result[1] is pd.NaT

@pytest.mark.xfail(reason='GH#19378 floordiv by Tick not implemented')
def test_divmod_offset(self):
# GH#19365
td = Timedelta(days=2, hours=6)
Expand All @@ -588,7 +583,6 @@ def test_rdivmod_pytimedelta(self):
assert isinstance(result[1], Timedelta)
assert result[1] == Timedelta(hours=6)

@pytest.mark.xfail(reason='GH#19378 floordiv by Tick not implemented')
def test_rdivmod_offset(self):
result = divmod(pd.offsets.Hour(54), Timedelta(hours=-4))
assert result[0] == -14
Expand Down