-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Fix inserting of wrong-dtyped NaT, closes #27297 #27311
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
Show all changes
19 commits
Select commit
Hold shift + click to select a range
ee426ab
BUG: fix+test setitem datetime64(NaT) into Series[timedelta64]
jbrockmendel 511650c
BUG: fix+test setting datetime64(NaT) in TimedeltaArray
jbrockmendel 3c916c1
TST: inserting timedelta64(NaT) into DatetimeArray, fixed in previous…
jbrockmendel d39503d
BUG: fix+test assigning timedelta64(NaT) to datetime series
jbrockmendel b047cce
BUG: fix+test assignment of wrong nat to DataFrame
jbrockmendel 7399ef0
Merge branch 'master' of https://github.com/pandas-dev/pandas into wr…
jbrockmendel 5e0004c
Merge branch 'master' of https://github.com/pandas-dev/pandas into wr…
jbrockmendel 7721404
Merge branch 'master' of https://github.com/pandas-dev/pandas into wr…
jbrockmendel 217ce63
pre-rebase
jbrockmendel bca4e2a
Merge branch 'master' of https://github.com/pandas-dev/pandas into wr…
jbrockmendel d32c1bf
typo
jbrockmendel 715002f
Merge branch 'master' of https://github.com/pandas-dev/pandas into wr…
jbrockmendel c001aca
update test for datetime series
jbrockmendel 49eec2e
fixups
jbrockmendel 96bda53
Merge branch 'master' of https://github.com/pandas-dev/pandas into wr…
jbrockmendel 42183e9
Merge branch 'master' of https://github.com/pandas-dev/pandas into wr…
jbrockmendel 7c260d5
remove apparently unnecessary reshape
jbrockmendel b035e4e
Merge branch 'master' of https://github.com/pandas-dev/pandas into wr…
jbrockmendel fbc1836
whatsnew
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
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 |
---|---|---|
|
@@ -654,6 +654,38 @@ def test_timedelta_assignment(): | |
tm.assert_series_equal(s, expected) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"nat_val,should_cast", | ||
[ | ||
(pd.NaT, True), | ||
(np.timedelta64("NaT", "ns"), False), | ||
(np.datetime64("NaT", "ns"), True), | ||
], | ||
) | ||
@pytest.mark.parametrize("tz", [None, "UTC"]) | ||
def test_dt64_series_assign_nat(nat_val, should_cast, tz): | ||
# some nat-like values should be cast to datetime64 when inserting | ||
# into a datetime64 series. Others should coerce to object | ||
# and retain their dtypes. | ||
dti = pd.date_range("2016-01-01", periods=3, tz=tz) | ||
base = pd.Series(dti) | ||
expected = pd.Series([pd.NaT] + list(dti[1:]), dtype=dti.dtype) | ||
if not should_cast: | ||
expected = expected.astype(object) | ||
|
||
ser = base.copy(deep=True) | ||
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. do these need to be deep? (no big deal though) 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. yes |
||
ser[0] = nat_val | ||
tm.assert_series_equal(ser, expected) | ||
|
||
ser = base.copy(deep=True) | ||
ser.loc[0] = nat_val | ||
tm.assert_series_equal(ser, expected) | ||
|
||
ser = base.copy(deep=True) | ||
ser.iloc[0] = nat_val | ||
tm.assert_series_equal(ser, expected) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"nat_val,should_cast", | ||
[ | ||
|
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.
do you really need to do this?
if you actually do, then .reshape(1, -1) should just work (or use np.atleast_2d)
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, this really is needed.
reshape(1, -1) is what is already here
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.
can you give an example that specific needs this 2d reshape?
this just is a completely different pattern than anywhere else. Why for example would the ObjectBlock construct not simply reshape (if needed); it already knows the dim & the values shape?