@@ -2457,50 +2457,52 @@ def test_split_with_name(self):
2457
2457
tm .assert_index_equal (res , exp )
2458
2458
2459
2459
def test_partition_series (self ):
2460
- values = Series (['a_b_c' , 'c_d_e' , NA , 'f_g_h' ])
2460
+ values = Series (['a_b_c' , 'c_d_e' , NA , 'f_g_h' , None ])
2461
2461
2462
2462
result = values .str .partition ('_' , expand = False )
2463
2463
exp = Series ([('a' , '_' , 'b_c' ), ('c' , '_' , 'd_e' ), NA ,
2464
- ('f' , '_' , 'g_h' )])
2464
+ ('f' , '_' , 'g_h' ), None ])
2465
2465
tm .assert_series_equal (result , exp )
2466
2466
2467
2467
result = values .str .rpartition ('_' , expand = False )
2468
2468
exp = Series ([('a_b' , '_' , 'c' ), ('c_d' , '_' , 'e' ), NA ,
2469
- ('f_g' , '_' , 'h' )])
2469
+ ('f_g' , '_' , 'h' ), None ])
2470
2470
tm .assert_series_equal (result , exp )
2471
2471
2472
2472
# more than one char
2473
- values = Series (['a__b__c' , 'c__d__e' , NA , 'f__g__h' ])
2473
+ values = Series (['a__b__c' , 'c__d__e' , NA , 'f__g__h' , None ])
2474
2474
result = values .str .partition ('__' , expand = False )
2475
2475
exp = Series ([('a' , '__' , 'b__c' ), ('c' , '__' , 'd__e' ), NA ,
2476
- ('f' , '__' , 'g__h' )])
2476
+ ('f' , '__' , 'g__h' ), None ])
2477
2477
tm .assert_series_equal (result , exp )
2478
2478
2479
2479
result = values .str .rpartition ('__' , expand = False )
2480
2480
exp = Series ([('a__b' , '__' , 'c' ), ('c__d' , '__' , 'e' ), NA ,
2481
- ('f__g' , '__' , 'h' )])
2481
+ ('f__g' , '__' , 'h' ), None ])
2482
2482
tm .assert_series_equal (result , exp )
2483
2483
2484
2484
# None
2485
- values = Series (['a b c' , 'c d e' , NA , 'f g h' ])
2485
+ values = Series (['a b c' , 'c d e' , NA , 'f g h' , None ])
2486
2486
result = values .str .partition (expand = False )
2487
2487
exp = Series ([('a' , ' ' , 'b c' ), ('c' , ' ' , 'd e' ), NA ,
2488
- ('f' , ' ' , 'g h' )])
2488
+ ('f' , ' ' , 'g h' ), None ])
2489
2489
tm .assert_series_equal (result , exp )
2490
2490
2491
2491
result = values .str .rpartition (expand = False )
2492
2492
exp = Series ([('a b' , ' ' , 'c' ), ('c d' , ' ' , 'e' ), NA ,
2493
- ('f g' , ' ' , 'h' )])
2493
+ ('f g' , ' ' , 'h' ), None ])
2494
2494
tm .assert_series_equal (result , exp )
2495
2495
2496
2496
# Not split
2497
- values = Series (['abc' , 'cde' , NA , 'fgh' ])
2497
+ values = Series (['abc' , 'cde' , NA , 'fgh' , None ])
2498
2498
result = values .str .partition ('_' , expand = False )
2499
- exp = Series ([('abc' , '' , '' ), ('cde' , '' , '' ), NA , ('fgh' , '' , '' )])
2499
+ exp = Series ([('abc' , '' , '' ), ('cde' , '' , '' ), NA ,
2500
+ ('fgh' , '' , '' ), None ])
2500
2501
tm .assert_series_equal (result , exp )
2501
2502
2502
2503
result = values .str .rpartition ('_' , expand = False )
2503
- exp = Series ([('' , '' , 'abc' ), ('' , '' , 'cde' ), NA , ('' , '' , 'fgh' )])
2504
+ exp = Series ([('' , '' , 'abc' ), ('' , '' , 'cde' ), NA ,
2505
+ ('' , '' , 'fgh' ), None ])
2504
2506
tm .assert_series_equal (result , exp )
2505
2507
2506
2508
# unicode
@@ -2524,59 +2526,61 @@ def test_partition_series(self):
2524
2526
assert result == [v .rpartition ('_' ) for v in values ]
2525
2527
2526
2528
def test_partition_index (self ):
2527
- values = Index (['a_b_c' , 'c_d_e' , 'f_g_h' , np .nan ])
2529
+ values = Index (['a_b_c' , 'c_d_e' , 'f_g_h' , np .nan , None ])
2528
2530
2529
2531
result = values .str .partition ('_' , expand = False )
2530
2532
exp = Index (np .array ([('a' , '_' , 'b_c' ), ('c' , '_' , 'd_e' ),
2531
- ('f' , '_' , 'g_h' ), np .nan ]))
2533
+ ('f' , '_' , 'g_h' ), np .nan , None ]))
2532
2534
tm .assert_index_equal (result , exp )
2533
2535
assert result .nlevels == 1
2534
2536
2535
2537
result = values .str .rpartition ('_' , expand = False )
2536
2538
exp = Index (np .array ([('a_b' , '_' , 'c' ), ('c_d' , '_' , 'e' ),
2537
- ('f_g' , '_' , 'h' ), np .nan ]))
2539
+ ('f_g' , '_' , 'h' ), np .nan , None ]))
2538
2540
tm .assert_index_equal (result , exp )
2539
2541
assert result .nlevels == 1
2540
2542
2541
2543
result = values .str .partition ('_' )
2542
2544
exp = Index ([('a' , '_' , 'b_c' ), ('c' , '_' , 'd_e' ),
2543
- ('f' , '_' , 'g_h' ), (np .nan , np .nan , np .nan )])
2545
+ ('f' , '_' , 'g_h' ), (np .nan , np .nan , np .nan ),
2546
+ (None , None , None )])
2544
2547
tm .assert_index_equal (result , exp )
2545
2548
assert isinstance (result , MultiIndex )
2546
2549
assert result .nlevels == 3
2547
2550
2548
2551
result = values .str .rpartition ('_' )
2549
2552
exp = Index ([('a_b' , '_' , 'c' ), ('c_d' , '_' , 'e' ),
2550
- ('f_g' , '_' , 'h' ), (np .nan , np .nan , np .nan )])
2553
+ ('f_g' , '_' , 'h' ), (np .nan , np .nan , np .nan ),
2554
+ (None , None , None )])
2551
2555
tm .assert_index_equal (result , exp )
2552
2556
assert isinstance (result , MultiIndex )
2553
2557
assert result .nlevels == 3
2554
2558
2555
2559
def test_partition_to_dataframe (self ):
2556
- values = Series (['a_b_c' , 'c_d_e' , NA , 'f_g_h' ])
2560
+ values = Series (['a_b_c' , 'c_d_e' , NA , 'f_g_h' , None ])
2557
2561
result = values .str .partition ('_' )
2558
- exp = DataFrame ({0 : ['a' , 'c' , np .nan , 'f' ],
2559
- 1 : ['_' , '_' , np .nan , '_' ],
2560
- 2 : ['b_c' , 'd_e' , np .nan , 'g_h' ]})
2562
+ exp = DataFrame ({0 : ['a' , 'c' , np .nan , 'f' , None ],
2563
+ 1 : ['_' , '_' , np .nan , '_' , None ],
2564
+ 2 : ['b_c' , 'd_e' , np .nan , 'g_h' , None ]})
2561
2565
tm .assert_frame_equal (result , exp )
2562
2566
2563
2567
result = values .str .rpartition ('_' )
2564
- exp = DataFrame ({0 : ['a_b' , 'c_d' , np .nan , 'f_g' ],
2565
- 1 : ['_' , '_' , np .nan , '_' ],
2566
- 2 : ['c' , 'e' , np .nan , 'h' ]})
2568
+ exp = DataFrame ({0 : ['a_b' , 'c_d' , np .nan , 'f_g' , None ],
2569
+ 1 : ['_' , '_' , np .nan , '_' , None ],
2570
+ 2 : ['c' , 'e' , np .nan , 'h' , None ]})
2567
2571
tm .assert_frame_equal (result , exp )
2568
2572
2569
- values = Series (['a_b_c' , 'c_d_e' , NA , 'f_g_h' ])
2573
+ values = Series (['a_b_c' , 'c_d_e' , NA , 'f_g_h' , None ])
2570
2574
result = values .str .partition ('_' , expand = True )
2571
- exp = DataFrame ({0 : ['a' , 'c' , np .nan , 'f' ],
2572
- 1 : ['_' , '_' , np .nan , '_' ],
2573
- 2 : ['b_c' , 'd_e' , np .nan , 'g_h' ]})
2575
+ exp = DataFrame ({0 : ['a' , 'c' , np .nan , 'f' , None ],
2576
+ 1 : ['_' , '_' , np .nan , '_' , None ],
2577
+ 2 : ['b_c' , 'd_e' , np .nan , 'g_h' , None ]})
2574
2578
tm .assert_frame_equal (result , exp )
2575
2579
2576
2580
result = values .str .rpartition ('_' , expand = True )
2577
- exp = DataFrame ({0 : ['a_b' , 'c_d' , np .nan , 'f_g' ],
2578
- 1 : ['_' , '_' , np .nan , '_' ],
2579
- 2 : ['c' , 'e' , np .nan , 'h' ]})
2581
+ exp = DataFrame ({0 : ['a_b' , 'c_d' , np .nan , 'f_g' , None ],
2582
+ 1 : ['_' , '_' , np .nan , '_' , None ],
2583
+ 2 : ['c' , 'e' , np .nan , 'h' , None ]})
2580
2584
tm .assert_frame_equal (result , exp )
2581
2585
2582
2586
def test_partition_with_name (self ):
0 commit comments