Skip to content

Commit

Permalink
CLN/TST: clean logic of old datetime test_indexing test (#55523)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche authored Oct 15, 2023
1 parent 0021d24 commit 10cf330
Showing 1 changed file with 10 additions and 8 deletions.
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])

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)

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

with pytest.raises(KeyError, match="2001"):
df["2001"]
tm.assert_frame_equal(df, expected)


def test_getitem_str_month_with_datetimeindex():
Expand Down

0 comments on commit 10cf330

Please sign in to comment.