Skip to content

BUG: DTA/TDA incorrectly accepting iNaT for setitem #27699

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 2 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,6 @@ def __setitem__(
value = self._unbox_scalar(value)
elif is_valid_nat_for_dtype(value, self.dtype):
value = iNaT
elif not isna(value) and lib.is_integer(value) and value == iNaT:
# exclude misc e.g. object() and any NAs not allowed above
value = iNaT
else:
msg = (
"'value' should be a '{scalar}', 'NaT', or array of those. "
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/arrays/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,15 +682,15 @@ def test_casting_nat_setitem_array(array, casting_nats):
[
(
pd.TimedeltaIndex(["1 Day", "3 Hours", "NaT"])._data,
(np.datetime64("NaT", "ns"),),
(np.datetime64("NaT", "ns"), pd.NaT.value),
),
(
pd.date_range("2000-01-01", periods=3, freq="D")._data,
(np.timedelta64("NaT", "ns"),),
(np.timedelta64("NaT", "ns"), pd.NaT.value),
),
(
pd.period_range("2000-01-01", periods=3, freq="D")._data,
(np.datetime64("NaT", "ns"), np.timedelta64("NaT", "ns")),
(np.datetime64("NaT", "ns"), np.timedelta64("NaT", "ns"), pd.NaT.value),
),
],
ids=lambda x: type(x).__name__,
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def test_value_counts_unique_nunique_null(self, null_obj):
values = o._shallow_copy(v)
else:
o = o.copy()
o[0:2] = iNaT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same questions as #27704 (comment) (happy to do on either PR)

o[0:2] = pd.NaT
values = o._values

elif needs_i8_conversion(o):
Expand Down