@@ -2330,24 +2330,33 @@ def test_split_to_dataframe(self):
2330
2330
s .str .split ('_' , expand = "not_a_boolean" )
2331
2331
2332
2332
def test_split_to_multiindex_expand (self ):
2333
- idx = Index (['nosplit' , 'alsonosplit' ])
2333
+ idx = Index (['nosplit' , 'alsonosplit' , np . nan ])
2334
2334
result = idx .str .split ('_' , expand = True )
2335
2335
exp = idx
2336
2336
tm .assert_index_equal (result , exp )
2337
2337
assert result .nlevels == 1
2338
2338
2339
- idx = Index (['some_equal_splits' , 'with_no_nans' ])
2339
+ idx = Index (['some_equal_splits' , 'with_no_nans' , np . nan , None ])
2340
2340
result = idx .str .split ('_' , expand = True )
2341
- exp = MultiIndex .from_tuples ([('some' , 'equal' , 'splits' ), (
2342
- 'with' , 'no' , 'nans' )])
2341
+ exp = MultiIndex .from_tuples ([('some' , 'equal' , 'splits' ),
2342
+ ('with' , 'no' , 'nans' ),
2343
+ [np .nan , np .nan , np .nan ],
2344
+ [None , None , None ]])
2343
2345
tm .assert_index_equal (result , exp )
2344
2346
assert result .nlevels == 3
2345
2347
2346
- idx = Index (['some_unequal_splits' , 'one_of_these_things_is_not' ])
2348
+ idx = Index (['some_unequal_splits' ,
2349
+ 'one_of_these_things_is_not' ,
2350
+ np .nan , None ])
2347
2351
result = idx .str .split ('_' , expand = True )
2348
- exp = MultiIndex .from_tuples ([('some' , 'unequal' , 'splits' , NA , NA , NA
2349
- ), ('one' , 'of' , 'these' , 'things' ,
2350
- 'is' , 'not' )])
2352
+ exp = MultiIndex .from_tuples ([('some' , 'unequal' , 'splits' ,
2353
+ NA , NA , NA ),
2354
+ ('one' , 'of' , 'these' ,
2355
+ 'things' , 'is' , 'not' ),
2356
+ (np .nan , np .nan , np .nan ,
2357
+ np .nan , np .nan , np .nan ),
2358
+ (None , None , None ,
2359
+ None , None , None )])
2351
2360
tm .assert_index_equal (result , exp )
2352
2361
assert result .nlevels == 6
2353
2362
@@ -2480,12 +2489,12 @@ def test_partition_series(self):
2480
2489
# Not split
2481
2490
values = Series (['abc' , 'cde' , NA , 'fgh' , None ])
2482
2491
result = values .str .partition ('_' , expand = False )
2483
- exp = Series ([('abc' , '' , '' ), ('cde' , '' , '' ), NA ,
2492
+ exp = Series ([('abc' , '' , '' ), ('cde' , '' , '' ), NA ,
2484
2493
('fgh' , '' , '' ), None ])
2485
2494
tm .assert_series_equal (result , exp )
2486
2495
2487
2496
result = values .str .rpartition ('_' , expand = False )
2488
- exp = Series ([('' , '' , 'abc' ), ('' , '' , 'cde' ), NA ,
2497
+ exp = Series ([('' , '' , 'abc' ), ('' , '' , 'cde' ), NA ,
2489
2498
('' , '' , 'fgh' ), None ])
2490
2499
tm .assert_series_equal (result , exp )
2491
2500
0 commit comments