-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: fix+test assigning invalid NAT-like to DTA/TDA/PA #27331
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 5 commits
4a862dd
74a4254
24db8a7
20eca07
a81b9ad
3137cfb
d55c508
2281749
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 |
---|---|---|
|
@@ -651,3 +651,38 @@ def test_array_interface(self, period_index): | |
result = np.asarray(arr, dtype="S20") | ||
expected = np.asarray(arr).astype("S20") | ||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
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. are there other setitem tests? put near those |
||
|
||
@pytest.mark.parametrize( | ||
"array", | ||
[ | ||
pd.TimedeltaIndex(["1 Day", "3 Hours", "NaT"])._data, | ||
pd.date_range("2000-01-01", periods=3, freq="D")._data, | ||
pd.period_range("2000-01-01", periods=3, freq="D")._data, | ||
], | ||
ids=lambda x: type(x).__name__, | ||
) | ||
def test_nat_assignment_array(array): | ||
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. assignment -> setitem 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. changed |
||
expected = type(array)._from_sequence([pd.NaT, array[1], array[2]]) | ||
|
||
casting_nats = { | ||
TimedeltaArray: [pd.NaT, np.timedelta64("NaT", "ns")], | ||
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. this is too complicated, just provide the expected alongside the values above |
||
DatetimeArray: [pd.NaT, np.datetime64("NaT", "ns")], | ||
PeriodArray: [pd.NaT], | ||
}[type(array)] | ||
non_casting_nats = { | ||
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. this would be better to parameterize over the non_casting_nats and the casting_nats in a separate test. too much going on here. 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. changed |
||
TimedeltaArray: [np.datetime64("NaT", "ns")], | ||
DatetimeArray: [np.timedelta64("NaT", "ns")], | ||
PeriodArray: [np.timedelta64("NaT", "ns"), np.datetime64("NaT", "ns")], | ||
}[type(array)] | ||
|
||
for nat in casting_nats: | ||
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 make another level of parameterization to make these truly separate tests? 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. I don't think so; the I've been looking at pytest extensions that might make this kind of thing possible |
||
arr = array.copy() | ||
arr[0] = nat | ||
|
||
tm.assert_equal(arr, expected) | ||
|
||
for nat in non_casting_nats: | ||
arr = array.copy() | ||
with pytest.raises(TypeError): | ||
arr[0] = 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.
can you type these(followup ok)