@@ -443,6 +443,25 @@ def test_reorder_levels(using_copy_on_write):
443
443
tm .assert_frame_equal (df , df_orig )
444
444
445
445
446
+ def test_series_reorder_levels (using_copy_on_write ):
447
+ index = MultiIndex .from_tuples (
448
+ [(1 , 1 ), (1 , 2 ), (2 , 1 ), (2 , 2 )], names = ["one" , "two" ]
449
+ )
450
+ ser = Series ([1 , 2 , 3 , 4 ], index = index )
451
+ ser_orig = ser .copy ()
452
+ ser2 = ser .reorder_levels (order = ["two" , "one" ])
453
+
454
+ if using_copy_on_write :
455
+ assert np .shares_memory (ser2 .values , ser .values )
456
+ else :
457
+ assert not np .shares_memory (ser2 .values , ser .values )
458
+
459
+ ser2 .iloc [0 ] = 0
460
+ if using_copy_on_write :
461
+ assert not np .shares_memory (ser2 .values , ser .values )
462
+ tm .assert_series_equal (ser , ser_orig )
463
+
464
+
446
465
@pytest .mark .parametrize ("obj" , [Series ([1 , 2 , 3 ]), DataFrame ({"a" : [1 , 2 , 3 ]})])
447
466
def test_swaplevel (using_copy_on_write , obj ):
448
467
index = MultiIndex .from_tuples ([(1 , 1 ), (1 , 2 ), (2 , 1 )], names = ["one" , "two" ])
@@ -478,28 +497,6 @@ def test_frame_set_axis(using_copy_on_write):
478
497
tm .assert_frame_equal (df , df_orig )
479
498
480
499
481
- @pytest .mark .parametrize (
482
- "func, tz" , [("tz_convert" , "Europe/Berlin" ), ("tz_localize" , None )]
483
- )
484
- def test_tz_convert_localize (using_copy_on_write , func , tz ):
485
- # GH 49473
486
- ser = Series (
487
- [1 , 2 ], index = date_range (start = "2014-08-01 09:00" , freq = "H" , periods = 2 , tz = tz )
488
- )
489
- ser_orig = ser .copy ()
490
- ser2 = getattr (ser , func )("US/Central" )
491
-
492
- if using_copy_on_write :
493
- assert np .shares_memory (ser .values , ser2 .values )
494
- else :
495
- assert not np .shares_memory (ser .values , ser2 .values )
496
-
497
- # mutating ser triggers a copy-on-write for the column / block
498
- ser2 .iloc [0 ] = 0
499
- assert not np .shares_memory (ser2 .values , ser .values )
500
- tm .assert_series_equal (ser , ser_orig )
501
-
502
-
503
500
def test_series_set_axis (using_copy_on_write ):
504
501
# GH 49473
505
502
ser = Series ([1 , 2 , 3 ])
@@ -533,3 +530,25 @@ def test_rename_axis(using_copy_on_write, kwargs, copy_kwargs):
533
530
if using_copy_on_write :
534
531
assert not np .shares_memory (get_array (df2 , "a" ), get_array (df , "a" ))
535
532
tm .assert_frame_equal (df , df_orig )
533
+
534
+
535
+ @pytest .mark .parametrize (
536
+ "func, tz" , [("tz_convert" , "Europe/Berlin" ), ("tz_localize" , None )]
537
+ )
538
+ def test_tz_convert_localize (using_copy_on_write , func , tz ):
539
+ # GH 49473
540
+ ser = Series (
541
+ [1 , 2 ], index = date_range (start = "2014-08-01 09:00" , freq = "H" , periods = 2 , tz = tz )
542
+ )
543
+ ser_orig = ser .copy ()
544
+ ser2 = getattr (ser , func )("US/Central" )
545
+
546
+ if using_copy_on_write :
547
+ assert np .shares_memory (ser .values , ser2 .values )
548
+ else :
549
+ assert not np .shares_memory (ser .values , ser2 .values )
550
+
551
+ # mutating ser triggers a copy-on-write for the column / block
552
+ ser2 .iloc [0 ] = 0
553
+ assert not np .shares_memory (ser2 .values , ser .values )
554
+ tm .assert_series_equal (ser , ser_orig )
0 commit comments