-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
BUG: Fix IntervalIndex.insert to allow inserting NaN #18300
Changes from all commits
e103ae0
2c4bf16
12bcfed
a951f27
3e336e1
e401032
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 |
---|---|---|
|
@@ -697,3 +697,11 @@ def test_join_self(self, how): | |
index = period_range('1/1/2000', periods=10) | ||
joined = index.join(index, how=how) | ||
assert index is joined | ||
|
||
def test_insert(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in another PR, can come back and move test_insert to datetimelike.py where this can be tested generically (instead of having code inside each datetimelike index type) |
||
# GH 18295 (test missing) | ||
expected = PeriodIndex( | ||
['2017Q1', pd.NaT, '2017Q2', '2017Q3', '2017Q4'], freq='Q') | ||
for na in (np.nan, pd.NaT, None): | ||
result = period_range('2017Q1', periods=4, freq='Q').insert(1, na) | ||
tm.assert_index_equal(result, expected) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -457,6 +457,12 @@ def test_insert(self): | |
null_index = Index([]) | ||
tm.assert_index_equal(Index(['a']), null_index.insert(0, 'a')) | ||
|
||
# GH 18295 (test missing) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can also be done generically |
||
expected = Index(['a', np.nan, 'b', 'c']) | ||
for na in (np.nan, pd.NaT, None): | ||
result = Index(list('abc')).insert(1, na) | ||
tm.assert_index_equal(result, expected) | ||
|
||
def test_delete(self): | ||
idx = Index(['a', 'b', 'c', 'd'], name='idx') | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,12 @@ def test_insert(self): | |
assert result.name == expected.name | ||
assert result.freq == expected.freq | ||
|
||
# GH 18295 (test missing) | ||
expected = TimedeltaIndex(['1day', pd.NaT, '2day', '3day']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. side issue, we have lots of duplication on these test_insert/delete and such in the hierarchy and most can simply be tested via fixture / in superclass (but will require some refactoring in the tests). I think we have an issue about this. |
||
for na in (np.nan, pd.NaT, None): | ||
result = timedelta_range('1day', '3day').insert(1, na) | ||
tm.assert_index_equal(result, expected) | ||
|
||
def test_delete(self): | ||
idx = timedelta_range(start='1 Days', periods=5, freq='D', name='idx') | ||
|
||
|
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.
yes u need to use a nan compat with left iow this could be a 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.
i think we have a left.na_value iirc (might be spelled differently)
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.
or maybe the underlying already handles this in the insert
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.
Updated. Procedure I'm following is "check if any type of NA value is passed -> raise if the wrong type of NA is passed". I suppose I could just bypass this and only check if the right type of NA is passed, if that would be preferred.