Skip to content

Commit 10cf330

Browse files
CLN/TST: clean logic of old datetime test_indexing test (#55523)
1 parent 0021d24 commit 10cf330

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

pandas/tests/series/indexing/test_datetime.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -427,25 +427,27 @@ def test_indexing():
427427
# getting
428428

429429
# GH 3070, make sure semantics work on Series/Frame
430-
expected = ts["2001"]
431-
expected.name = "A"
430+
result = ts["2001"]
431+
tm.assert_series_equal(result, ts.iloc[:12])
432432

433-
df = DataFrame({"A": ts})
433+
df = DataFrame({"A": ts.copy()})
434434

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

440440
# setting
441+
ts = Series(np.random.default_rng(2).random(len(idx)), index=idx)
442+
expected = ts.copy()
443+
expected.iloc[:12] = 1
441444
ts["2001"] = 1
442-
expected = ts["2001"]
443-
expected.name = "A"
445+
tm.assert_series_equal(ts, expected)
444446

447+
expected = df.copy()
448+
expected.iloc[:12, 0] = 1
445449
df.loc["2001", "A"] = 1
446-
447-
with pytest.raises(KeyError, match="2001"):
448-
df["2001"]
450+
tm.assert_frame_equal(df, expected)
449451

450452

451453
def test_getitem_str_month_with_datetimeindex():

0 commit comments

Comments
 (0)