File tree 1 file changed +10
-8
lines changed
pandas/tests/series/indexing
1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -427,25 +427,27 @@ def test_indexing():
427
427
# getting
428
428
429
429
# 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 ])
432
432
433
- df = DataFrame ({"A" : ts })
433
+ df = DataFrame ({"A" : ts . copy () })
434
434
435
435
# GH#36179 pre-2.0 df["2001"] operated as slicing on rows. in 2.0 it behaves
436
436
# like any other key, so raises
437
437
with pytest .raises (KeyError , match = "2001" ):
438
438
df ["2001" ]
439
439
440
440
# setting
441
+ ts = Series (np .random .default_rng (2 ).random (len (idx )), index = idx )
442
+ expected = ts .copy ()
443
+ expected .iloc [:12 ] = 1
441
444
ts ["2001" ] = 1
442
- expected = ts ["2001" ]
443
- expected .name = "A"
445
+ tm .assert_series_equal (ts , expected )
444
446
447
+ expected = df .copy ()
448
+ expected .iloc [:12 , 0 ] = 1
445
449
df .loc ["2001" , "A" ] = 1
446
-
447
- with pytest .raises (KeyError , match = "2001" ):
448
- df ["2001" ]
450
+ tm .assert_frame_equal (df , expected )
449
451
450
452
451
453
def test_getitem_str_month_with_datetimeindex ():
You can’t perform that action at this time.
0 commit comments