8000 WIP: NaTD by jbrockmendel · Pull Request #24645 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

WIP: NaTD #24645

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

Closed
wants to merge 5 commits into from
Closed
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
handle+test TDA.__rfloordiv__
  • Loading branch information
jbrockmendel committed Jan 5, 2019
commit d0efc5f8ed85f2682c0386f3120939b39be7f4a5
7 changes: 2 additions & 5 deletions pandas/core/arrays/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,8 @@ def __rfloordiv__(self, other):
if is_scalar(other):
if isinstance(other, (timedelta, np.timedelta64, Tick)):
other = Timedelta(other)
if other is NaT: # TODO: use NaTD
# treat this specifically as timedelta-NaT
result = np.empty(self.shape, dtype=np.float64)
result.fill(np.nan)
return result
if other is NaT:
other = NaTD

# dispatch to Timedelta implementation
result = other.__floordiv__(self._data)
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/arithmetic/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ class TestTimedeltaNaTArithmetic(object):
# Tests for arithmetic with np.timedelta64('NaT') which has some tough
# corner cases

def test_tdarr_rfloordiv_nat(self):
# TODO: test belongs elsewhere, mostly just putting this here because
# it is the only TDA method patched for the proof of concept
td = np.timedelta64('NaT')

arr = np.arange(3) * 10**9
tda = pd.TimedeltaIndex(arr)._data

result = td // tda

expected = np.array([np.nan, np.nan, np.nan])
tm.assert_numpy_array_equal(result, expected)

def test_numeric_with_timedelta_nat(self, box):
arr = np.array([1, 2, 3, 4], dtype=np.int64)
obj = tm.box_expected(arr, box)
Expand Down
0