Skip to content

Commit ec23a8a

Browse files
committed
catch ValueErrors in now invalid test cases.
1 parent 8da4627 commit ec23a8a

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

pandas/tests/indexes/test_base.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,9 +1412,11 @@ def test_str_attribute(self):
14121412
tm.assert_index_equal(idx.str.split(), expected)
14131413
tm.assert_index_equal(idx.str.split(expand=False), expected)
14141414

1415-
expected = MultiIndex.from_tuples([('a', 'b', 'c'), ('d', 'e', np.nan),
1416-
('f', np.nan, np.nan)])
1417-
tm.assert_index_equal(idx.str.split(expand=True), expected)
1415+
# This is invalid behavior
1416+
with self.assertRaises(ValueError):
1417+
expected = MultiIndex.from_tuples([('a', 'b', 'c'), ('d', 'e', np.nan),
1418+
('f', np.nan, np.nan)])
1419+
tm.assert_index_equal(idx.str.split(expand=True), expected)
14181420

14191421
# test boolean case, should return np.array instead of boolean Index
14201422
idx = Index(['a1', 'a2', 'b1', 'b2'])

pandas/tests/test_strings.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,13 +1951,14 @@ def test_split_to_multiindex_expand(self):
19511951
tm.assert_index_equal(result, exp)
19521952
self.assertEqual(result.nlevels, 3)
19531953

1954-
idx = Index(['some_unequal_splits', 'one_of_these_things_is_not'])
1955-
result = idx.str.split('_', expand=True)
1956-
exp = MultiIndex.from_tuples([('some', 'unequal', 'splits', NA, NA, NA
1957-
), ('one', 'of', 'these', 'things',
1958-
'is', 'not')])
1959-
tm.assert_index_equal(result, exp)
1960-
self.assertEqual(result.nlevels, 6)
1954+
with self.assertRaises(ValueError):
1955+
idx = Index(['some_unequal_splits', 'one_of_these_things_is_not'])
1956+
result = idx.str.split('_', expand=True)
1957+
exp = MultiIndex.from_tuples([('some', 'unequal', 'splits', NA, NA, NA
1958+
), ('one', 'of', 'these', 'things',
1959+
'is', 'not')])
1960+
tm.assert_index_equal(result, exp)
1961+
self.assertEqual(result.nlevels, 6)
19611962

19621963
with tm.assertRaisesRegexp(ValueError, "expand must be"):
19631964
idx.str.split('_', expand="not_a_boolean")

0 commit comments

Comments
 (0)