-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Fix DatetimeIndex.insert(pd.NaT) for tz-aware index #18883
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
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
83e7105
Fix insert NaT into tzaware datetime index
jbrockmendel 5a469d2
Whatsnew note
jbrockmendel 664c800
edit whatsnew, test several null types
jbrockmendel 85ba78c
edits per reviewer requests
jbrockmendel 3d429df
Merge branch 'master' of https://github.com/pandas-dev/pandas into in…
jbrockmendel a1df0f7
Merge branch 'master' of https://github.com/pandas-dev/pandas into in…
jbrockmendel 31e3581
fix typo
jbrockmendel 8934f66
parametrize more
jbrockmendel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,15 @@ def test_where_tz(self): | |
expected = i2 | ||
tm.assert_index_equal(result, expected) | ||
|
||
@pytest.mark.parametrize('tz', [None, 'UTC', 'US/Eastern']) | ||
def test_insert_nat(self, tz): | ||
# GH#16537, GH#18295 (test missing) | ||
idx = pd.DatetimeIndex(['2017-01-01'], tz=tz) | ||
expected = pd.DatetimeIndex(['NaT', '2017-01-01'], tz=tz) | ||
for null in [None, np.nan, pd.NaT]: | ||
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 you pull this null into the paramaterization? 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. Sure, pushing momentarily. |
||
res = idx.insert(0, null) | ||
tm.assert_index_equal(res, expected) | ||
|
||
def test_insert(self): | ||
idx = DatetimeIndex( | ||
['2000-01-04', '2000-01-01', '2000-01-02'], name='idx') | ||
|
@@ -145,13 +154,6 @@ def test_insert(self): | |
assert result.tz == expected.tz | ||
assert result.freq is None | ||
|
||
# GH 18295 (test missing) | ||
expected = DatetimeIndex( | ||
['20170101', pd.NaT, '20170102', '20170103', '20170104']) | ||
for na in (np.nan, pd.NaT, None): | ||
result = date_range('20170101', periods=4).insert(1, na) | ||
tm.assert_index_equal(result, expected) | ||
|
||
def test_delete(self): | ||
idx = date_range(start='2000-01-01', periods=5, freq='M', name='idx') | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You could maybe parametrize over different NA values here, since this should work for inserting
np.nan
andNone
as well (shouldn't require any additional code changes). For example, on a tz-naive DTI: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.
If you do that, I suppose you could delete these lines in
test_insert
below, as to not duplicate things:pandas/pandas/tests/indexes/datetimes/test_indexing.py
Lines 148 to 153 in ac8ac15