Skip to content
Merged
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
25 changes: 25 additions & 0 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,31 @@ def test_loc_setitem_numpy_frame_categorical_value(self):
expected = DataFrame({"a": [1, 2, 2, 1, 1], "b": ["a", "a", "a", "a", "a"]})
tm.assert_frame_equal(df, expected)

def test_loc_with_nat_in_tzaware_index(self):
# GH#54409
timestamp = to_datetime("2023-01-01", utc=True)
df = DataFrame(
{
"index": Series([pd.NaT, timestamp]),
"value": Series([0, 1]),
}
).set_index("index")

# Works fine when mixing NaT and valid values
result = df.loc[
Series([pd.NaT, timestamp, timestamp], dtype=df.index.dtype),
"value",
]
expected = [0, 1, 1]
assert result.tolist() == expected

# Regression check: all-NaT lookup should return [0], not raise
result = df.loc[
Series([pd.NaT], dtype=df.index.dtype),
"value",
]
assert result.tolist() == [0]


class TestLocWithEllipsis:
@pytest.fixture
Expand Down
Loading