Skip to content

Commit 46b7e7c

Browse files
committed
TST: tests for bug Index.str.split(expand=True) not nan-safe (pandas-dev#23677)
1 parent fa347bb commit 46b7e7c

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

doc/source/whatsnew/v0.24.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ Numeric
12611261
Strings
12621262
^^^^^^^
12631263

1264-
- BUG in :func:`Index.str.partition` is not nan-safe (:issue:`23558`)
1264+
- BUG in :meth:`Index.str.partition` was not nan-safe (:issue:`23558`).
12651265
-
12661266
-
12671267

pandas/tests/test_strings.py

+19-10
Original file line numberDiff line numberDiff line change
@@ -2330,24 +2330,33 @@ def test_split_to_dataframe(self):
23302330
s.str.split('_', expand="not_a_boolean")
23312331

23322332
def test_split_to_multiindex_expand(self):
2333-
idx = Index(['nosplit', 'alsonosplit'])
2333+
idx = Index(['nosplit', 'alsonosplit', np.nan])
23342334
result = idx.str.split('_', expand=True)
23352335
exp = idx
23362336
tm.assert_index_equal(result, exp)
23372337
assert result.nlevels == 1
23382338

2339-
idx = Index(['some_equal_splits', 'with_no_nans'])
2339+
idx = Index(['some_equal_splits', 'with_no_nans', np.nan, None])
23402340
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]])
23432345
tm.assert_index_equal(result, exp)
23442346
assert result.nlevels == 3
23452347

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])
23472351
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)])
23512360
tm.assert_index_equal(result, exp)
23522361
assert result.nlevels == 6
23532362

@@ -2480,12 +2489,12 @@ def test_partition_series(self):
24802489
# Not split
24812490
values = Series(['abc', 'cde', NA, 'fgh', None])
24822491
result = values.str.partition('_', expand=False)
2483-
exp = Series([('abc', '', ''), ('cde', '', ''), NA,
2492+
exp = Series([('abc', '', ''), ('cde', '', ''), NA,
24842493
('fgh', '', ''), None])
24852494
tm.assert_series_equal(result, exp)
24862495

24872496
result = values.str.rpartition('_', expand=False)
2488-
exp = Series([('', '', 'abc'), ('', '', 'cde'), NA,
2497+
exp = Series([('', '', 'abc'), ('', '', 'cde'), NA,
24892498
('', '', 'fgh'), None])
24902499
tm.assert_series_equal(result, exp)
24912500

0 commit comments

Comments
 (0)