Skip to content

CLN/TST: clean logic of old datetime test_indexing test #55523

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 1 commit into from
Oct 15, 2023
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
18 changes: 10 additions & 8 deletions pandas/tests/series/indexing/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,25 +427,27 @@ def test_indexing():
# getting

# GH 3070, make sure semantics work on Series/Frame
expected = ts["2001"]
expected.name = "A"
result = ts["2001"]
tm.assert_series_equal(result, ts.iloc[:12])
Comment on lines -430 to +431
Copy link
Member Author

Choose a reason for hiding this comment

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

This expected wasn't actually being used right now, and it's the result of the "getting" operation (with a timeseries partial indexing), so asserting the result instead.


df = DataFrame({"A": ts})
df = DataFrame({"A": ts.copy()})

# GH#36179 pre-2.0 df["2001"] operated as slicing on rows. in 2.0 it behaves
# like any other key, so raises
with pytest.raises(KeyError, match="2001"):
df["2001"]

# setting
ts = Series(np.random.default_rng(2).random(len(idx)), index=idx)
expected = ts.copy()
expected.iloc[:12] = 1
ts["2001"] = 1
expected = ts["2001"]
expected.name = "A"
tm.assert_series_equal(ts, expected)
Comment on lines 444 to +445
Copy link
Member Author

Choose a reason for hiding this comment

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

Similarly here, the result of setting ts["2001"] = 1 was no longer tested, and expected wasn't actually used


expected = df.copy()
expected.iloc[:12, 0] = 1
df.loc["2001", "A"] = 1

with pytest.raises(KeyError, match="2001"):
df["2001"]
Comment on lines -447 to -448
Copy link
Member Author

Choose a reason for hiding this comment

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

Duplicated with 10 lines above

tm.assert_frame_equal(df, expected)


def test_getitem_str_month_with_datetimeindex():
Expand Down