12
12
Series ,
13
13
_testing as tm ,
14
14
)
15
+ from pandas .tests .strings import _convert_na_value
15
16
16
17
17
18
@pytest .mark .parametrize ("method" , ["split" , "rsplit" ])
@@ -20,9 +21,7 @@ def test_split(any_string_dtype, method):
20
21
21
22
result = getattr (values .str , method )("_" )
22
23
exp = Series ([["a" , "b" , "c" ], ["c" , "d" , "e" ], np .nan , ["f" , "g" , "h" ]])
23
- if values .dtype != object :
24
- # GH#18463
25
- exp = exp .fillna (pd .NA )
24
+ exp = _convert_na_value (values , exp )
26
25
tm .assert_series_equal (result , exp )
27
26
28
27
@@ -32,9 +31,7 @@ def test_split_more_than_one_char(any_string_dtype, method):
32
31
values = Series (["a__b__c" , "c__d__e" , np .nan , "f__g__h" ], dtype = any_string_dtype )
33
32
result = getattr (values .str , method )("__" )
34
33
exp = Series ([["a" , "b" , "c" ], ["c" , "d" , "e" ], np .nan , ["f" , "g" , "h" ]])
35
- if values .dtype != object :
36
- # GH#18463
37
- exp = exp .fillna (pd .NA )
34
+ exp = _convert_na_value (values , exp )
38
35
tm .assert_series_equal (result , exp )
39
36
40
37
result = getattr (values .str , method )("__" , expand = False )
@@ -46,9 +43,7 @@ def test_split_more_regex_split(any_string_dtype):
46
43
values = Series (["a,b_c" , "c_d,e" , np .nan , "f,g,h" ], dtype = any_string_dtype )
47
44
result = values .str .split ("[,_]" )
48
45
exp = Series ([["a" , "b" , "c" ], ["c" , "d" , "e" ], np .nan , ["f" , "g" , "h" ]])
49
- if values .dtype != object :
50
- # GH#18463
51
- exp = exp .fillna (pd .NA )
46
+ exp = _convert_na_value (values , exp )
52
47
tm .assert_series_equal (result , exp )
53
48
54
49
@@ -128,9 +123,7 @@ def test_rsplit(any_string_dtype):
128
123
values = Series (["a,b_c" , "c_d,e" , np .nan , "f,g,h" ], dtype = any_string_dtype )
129
124
result = values .str .rsplit ("[,_]" )
130
125
exp = Series ([["a,b_c" ], ["c_d,e" ], np .nan , ["f,g,h" ]])
131
- if values .dtype != object :
132
- # GH#18463
133
- exp = exp .fillna (pd .NA )
126
+ exp = _convert_na_value (values , exp )
134
127
tm .assert_series_equal (result , exp )
135
128
136
129
@@ -139,9 +132,7 @@ def test_rsplit_max_number(any_string_dtype):
139
132
values = Series (["a_b_c" , "c_d_e" , np .nan , "f_g_h" ], dtype = any_string_dtype )
140
133
result = values .str .rsplit ("_" , n = 1 )
141
134
exp = Series ([["a_b" , "c" ], ["c_d" , "e" ], np .nan , ["f_g" , "h" ]])
142
- if values .dtype != object :
143
- # GH#18463
144
- exp = exp .fillna (pd .NA )
135
+ exp = _convert_na_value (values , exp )
145
136
tm .assert_series_equal (result , exp )
146
137
147
138
@@ -455,9 +446,7 @@ def test_partition_series_more_than_one_char(method, exp, any_string_dtype):
455
446
s = Series (["a__b__c" , "c__d__e" , np .nan , "f__g__h" , None ], dtype = any_string_dtype )
456
447
result = getattr (s .str , method )("__" , expand = False )
457
448
expected = Series (exp )
458
- if s .dtype != object :
459
- # GH#18463
460
- expected = expected .fillna (pd .NA )
449
+ expected = _convert_na_value (s , expected )
461
450
tm .assert_series_equal (result , expected )
462
451
463
452
@@ -480,9 +469,7 @@ def test_partition_series_none(any_string_dtype, method, exp):
480
469
s = Series (["a b c" , "c d e" , np .nan , "f g h" , None ], dtype = any_string_dtype )
481
470
result = getattr (s .str , method )(expand = False )
482
471
expected = Series (exp )
483
- if s .dtype != object :
484
- # GH#18463
485
- expected = expected .fillna (pd .NA )
472
+ expected = _convert_na_value (s , expected )
486
473
tm .assert_series_equal (result , expected )
487
474
488
475
@@ -505,9 +492,7 @@ def test_partition_series_not_split(any_string_dtype, method, exp):
505
492
s = Series (["abc" , "cde" , np .nan , "fgh" , None ], dtype = any_string_dtype )
506
493
result = getattr (s .str , method )("_" , expand = False )
507
494
expected = Series (exp )
508
- if s .dtype != object :
509
- # GH#18463
510
- expected = expected .fillna (pd .NA )
495
+ expected = _convert_na_value (s , expected )
511
496
tm .assert_series_equal (result , expected )
512
497
513
498
@@ -531,9 +516,7 @@ def test_partition_series_unicode(any_string_dtype, method, exp):
531
516
532
517
result = getattr (s .str , method )("_" , expand = False )
533
518
expected = Series (exp )
534
- if s .dtype != object :
535
- # GH#18463
536
- expected = expected .fillna (pd .NA )
519
+ expected = _convert_na_value (s , expected )
537
520
tm .assert_series_equal (result , expected )
538
521
539
522
0 commit comments