-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
Masking and overflow checks for datetimeindex and timedeltaindex ops #18020
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
Changes from 12 commits
e9dd35b
36aea69
dd1eddd
92afc80
de663a1
183e8d0
75a403c
ff72d98
ac246b1
05254e2
7214823
f048ffa
7be5984
95f801f
586d872
24dd75b
4dbdfd7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -447,6 +447,40 @@ def f(): | |
t - offset | ||
pytest.raises(OverflowError, f) | ||
|
||
def test_datetimeindex_sub_timestamp_overflow(self): | ||
dtimax = pd.to_datetime(['now', pd.Timestamp.max]) | ||
dtimin = pd.to_datetime(['now', pd.Timestamp.min]) | ||
|
||
tsneg = Timestamp('1950-01-01') | ||
ts_neg_variants = [tsneg, | ||
tsneg.to_pydatetime(), | ||
tsneg.to_datetime64().astype('datetime64[ns]'), | ||
tsneg.to_datetime64().astype('datetime64[D]')] | ||
|
||
tspos = Timestamp('1980-01-01') | ||
ts_pos_variants = [tspos, | ||
tspos.to_pydatetime(), | ||
tspos.to_datetime64().astype('datetime64[ns]'), | ||
tspos.to_datetime64().astype('datetime64[D]')] | ||
|
||
for variant in ts_neg_variants: | ||
with pytest.raises(OverflowError): | ||
dtimax - variant | ||
|
||
expected = pd.Timestamp.max.value - tspos.value | ||
for variant in ts_pos_variants: | ||
res = dtimax - variant | ||
assert res[1].value == expected | ||
|
||
expected = pd.Timestamp.min.value - tsneg.value | ||
for variant in ts_neg_variants: | ||
res = dtimin - variant | ||
|
||
assert res[1].value == expected | ||
|
||
for variant in ts_pos_variants: | ||
with pytest.raises(OverflowError): | ||
dtimin - variant | ||
|
||
def test_get_duplicates(self): | ||
idx = DatetimeIndex(['2000-01-01', '2000-01-02', '2000-01-02', | ||
'2000-01-03', '2000-01-03', '2000-01-04']) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1282,3 +1282,23 @@ def test_add_overflow(self): | |
result = (to_timedelta([pd.NaT, '5 days', '1 hours']) + | ||
to_timedelta(['7 seconds', pd.NaT, '4 hours'])) | ||
tm.assert_index_equal(result, exp) | ||
|
||
def test_timedeltaindex_add_timestamp_nat_masking(self): | ||
# GH17991 checking for overflow-masking with NaT | ||
tdinat = pd.to_timedelta(['24658 days 11:15:00', 'NaT']) | ||
|
||
tsneg = Timestamp('1950-01-01') | ||
ts_neg_variants = [tsneg, | ||
tsneg.to_pydatetime(), | ||
tsneg.to_datetime64().astype('datetime64[ns]'), | ||
tsneg.to_datetime64().astype('datetime64[D]')] | ||
|
||
tspos = Timestamp('1980-01-01') | ||
ts_pos_variants = [tspos, | ||
tspos.to_pydatetime(), | ||
tspos.to_datetime64().astype('datetime64[ns]'), | ||
tspos.to_datetime64().astype('datetime64[D]')] | ||
|
||
for variant in ts_neg_variants + ts_pos_variants: | ||
res = tdinat + variant | ||
assert res[1] is pd.NaT | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the issue for these
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no issue for this; I noticed it when tracking down the TimedeltaIndex bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure there is, the PR number!