8000 Implement+Test Tick.__rtruediv__ by jbrockmendel · Pull Request #24832 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

Implement+Test Tick.__rtruediv__ #24832

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 14 commits into from
Feb 1, 2019
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
Prev Previous commit
Next Next commit
implement+test tick rdiv
  • Loading branch information
jbrockmendel committed Jan 18, 2019
commit 2f02ae1016ed1af9840dfb044846af627f17ce8b
8 changes: 8 additions & 0 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,20 @@ class _Tick(object):
can do isinstance checks on _Tick and avoid importing tseries.offsets
"""

# ensure that reversed-ops with numpy scalars return NotImplemented
__array_priority__ = 1000

def __truediv__(self, other):
result = self.delta.__truediv__(other)
return _wrap_timedelta_result(result)

def __rtruediv__(self, other):
result = self.delta.__rtruediv__(other)
return _wrap_timedelta_result(result)

if PY2:
__div__ = __truediv__
__rdiv__ = __rtruediv__


# ----------------------------------------------------------------------
Expand Down
24 changes: 24 additions & 0 deletions pandas/tests/tseries/offsets/test_ticks.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from pandas.tseries import offsets
from pandas.tseries.offsets import Hour, Micro, Milli, Minute, Nano, Second

import pandas.util.testing as tm

from .common import assert_offset_equal

# ---------------------------------------------------------------------
Expand Down Expand Up @@ -262,6 +264,28 @@ def test_tick_division(cls):
assert result.delta == off.delta / .001


@pytest.mark.parametrize('cls', tick_classes)
def test_tick_rdiv(cls):
off = cls(10)
delta = off.delta
td64 = delta.to_timedelta64()

with pytest.raises(TypeError):
2 / off
with pytest.raises(TypeError):
2.0 / off

assert (td64 * 2.5) / off == 2.5

if cls is not Nano:
# skip pytimedelta for Nano since it gets dropped
assert (delta.to_pytimedelta() * 2) / off == 2

result = np.array([2 * td64, td64]) / off
expected = np.array([2., 1.])
tm.assert_numpy_array_equal(result, expected)


@pytest.mark.parametrize('cls1', tick_classes)
@pytest.mark.parametrize('cls2', tick_classes)
def test_tick_zero(cls1, cls2):
Expand Down
0