Skip to content

Commit d1d26ff

Browse files
committed
catch ValueErrors in now invalid test cases.
1 parent 6593c26 commit d1d26ff

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
@@ -1443,9 +1443,11 @@ def test_str_attribute(self):
14431443
tm.assert_index_equal(idx.str.split(), expected)
14441444
tm.assert_index_equal(idx.str.split(expand=False), expected)
14451445

1446-
expected = MultiIndex.from_tuples([('a', 'b', 'c'), ('d', 'e', np.nan),
1447-
('f', np.nan, np.nan)])
1448-
tm.assert_index_equal(idx.str.split(expand=True), expected)
1446+
# This is invalid behavior
1447+
with self.assertRaises(ValueError):
1448+
expected = MultiIndex.from_tuples([('a', 'b', 'c'), ('d', 'e', np.nan),
1449+
('f', np.nan, np.nan)])
1450+
tm.assert_index_equal(idx.str.split(expand=True), expected)
14491451

14501452
# test boolean case, should return np.array instead of boolean Index
14511453
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
@@ -1984,13 +1984,14 @@ def test_split_to_multiindex_expand(self):
19841984
tm.assert_index_equal(result, exp)
19851985
self.assertEqual(result.nlevels, 3)
19861986

1987-
idx = Index(['some_unequal_splits', 'one_of_these_things_is_not'])
1988-
result = idx.str.split('_', expand=True)
1989-
exp = MultiIndex.from_tuples([('some', 'unequal', 'splits', NA, NA, NA
1990-
), ('one', 'of', 'these', 'things',
1991-
'is', 'not')])
1992-
tm.assert_index_equal(result, exp)
1993-
self.assertEqual(result.nlevels, 6)
1987+
with self.assertRaises(ValueError):
1988+
idx = Index(['some_unequal_splits', 'one_of_these_things_is_not'])
1989+
result = idx.str.split('_', expand=True)
1990+
exp = MultiIndex.from_tuples([('some', 'unequal', 'splits', NA, NA, NA
1991+
), ('one', 'of', 'these', 'things',
1992+
'is', 'not')])
1993+
tm.assert_index_equal(result, exp)
1994+
self.assertEqual(result.nlevels, 6)
19941995

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

0 commit comments

Comments
 (0)