Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ae46324

Browse files
TST: add regression test for GH#54409 (tz-aware NaT indexing with loc)
1 parent b9da662 commit ae46324

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

‎pandas/tests/indexing/test_loc.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,31 @@ def test_loc_setitem_numpy_frame_categorical_value(self):
16291629
expected = DataFrame({"a": [1, 2, 2, 1, 1], "b": ["a", "a", "a", "a", "a"]})
16301630
tm.assert_frame_equal(df, expected)
16311631

1632+
def test_loc_with_nat_in_tzaware_index(self):
1633+
# GH#54409
1634+
timestamp = to_datetime("2023年01月01日", utc=True)
1635+
df = DataFrame(
1636+
{
1637+
"index": Series([pd.NaT, timestamp]),
1638+
"value": Series([0, 1]),
1639+
}
1640+
).set_index("index")
1641+
1642+
# Works fine when mixing NaT and valid values
1643+
result = df.loc[
1644+
Series([pd.NaT, timestamp, timestamp], dtype=df.index.dtype),
1645+
"value",
1646+
]
1647+
expected = [0, 1, 1]
1648+
assert result.tolist() == expected
1649+
1650+
# Regression check: all-NaT lookup should return [0], not raise
1651+
result = df.loc[
1652+
Series([pd.NaT], dtype=df.index.dtype),
1653+
"value",
1654+
]
1655+
assert result.tolist() == [0]
1656+
16321657

16331658
class TestLocWithEllipsis:
16341659
@pytest.fixture

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /