-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: DTI/TDI .insert accepting incorrectly-dtyped NaT #30754
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 all commits
Commits
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 |
---|---|---|
|
@@ -317,7 +317,9 @@ def test_take_fill_value_with_timezone(self): | |
|
||
|
||
class TestDatetimeIndex: | ||
@pytest.mark.parametrize("null", [None, np.nan, pd.NaT]) | ||
@pytest.mark.parametrize( | ||
"null", [None, np.nan, np.datetime64("NaT"), pd.NaT, pd.NA] | ||
) | ||
@pytest.mark.parametrize("tz", [None, "UTC", "US/Eastern"]) | ||
def test_insert_nat(self, tz, null): | ||
# GH#16537, GH#18295 (test missing) | ||
|
@@ -326,6 +328,12 @@ def test_insert_nat(self, tz, null): | |
res = idx.insert(0, null) | ||
tm.assert_index_equal(res, expected) | ||
|
||
@pytest.mark.parametrize("tz", [None, "UTC", "US/Eastern"]) | ||
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. try to fixturize at some point (the tzs) |
||
def test_insert_invalid_na(self, tz): | ||
idx = pd.DatetimeIndex(["2017-01-01"], tz=tz) | ||
with pytest.raises(TypeError, match="incompatible label"): | ||
idx.insert(0, np.timedelta64("NaT")) | ||
|
||
def test_insert(self): | ||
idx = DatetimeIndex(["2000-01-04", "2000-01-01", "2000-01-02"], name="idx") | ||
|
||
|
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 |
---|---|---|
|
@@ -219,11 +219,29 @@ def test_insert(self): | |
assert result.name == expected.name | ||
assert result.freq == expected.freq | ||
|
||
@pytest.mark.parametrize( | ||
"null", [None, np.nan, np.timedelta64("NaT"), pd.NaT, pd.NA] | ||
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. similar to above |
||
) | ||
def test_insert_nat(self, null): | ||
# GH 18295 (test missing) | ||
idx = timedelta_range("1day", "3day") | ||
result = idx.insert(1, null) | ||
expected = TimedeltaIndex(["1day", pd.NaT, "2day", "3day"]) | ||
for na in (np.nan, pd.NaT, None): | ||
result = timedelta_range("1day", "3day").insert(1, na) | ||
tm.assert_index_equal(result, expected) | ||
tm.assert_index_equal(result, expected) | ||
|
||
def test_insert_invalid_na(self): | ||
idx = TimedeltaIndex(["4day", "1day", "2day"], name="idx") | ||
with pytest.raises(TypeError, match="incompatible label"): | ||
idx.insert(0, np.datetime64("NaT")) | ||
|
||
def test_insert_dont_cast_strings(self): | ||
# To match DatetimeIndex and PeriodIndex behavior, dont try to | ||
# parse strings to Timedelta | ||
idx = timedelta_range("1day", "3day") | ||
|
||
result = idx.insert(0, "1 Day") | ||
assert result.dtype == object | ||
assert result[0] == "1 Day" | ||
|
||
def test_delete(self): | ||
idx = timedelta_range(start="1 Days", periods=5, freq="D", 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.
should create a fixture like this (similar to nulls_fixture), but this is more datetime specialized, but for another pass.