Skip to content

Commit

Permalink
Changed info to user-friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
Xbar committed Nov 24, 2017
1 parent 5f2e74d commit b084cd4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ def from_arrays(cls, arrays, sortorder=None, names=None):
of iterables
"""
if not is_list_like(arrays):
raise TypeError("Inappropriate input for list of arrays.")
raise TypeError("Input must be a list / sequence of array-likes.")
elif is_iterator(arrays):
arrays = list(arrays)

Expand Down Expand Up @@ -1212,7 +1212,7 @@ def from_tuples(cls, tuples, sortorder=None, names=None):
of iterables
"""
if not is_list_like(tuples):
raise TypeError('Inappropriate input for tuples.')
raise TypeError('Input must be a list /sequence of tuple-likes.')
elif is_iterator(tuples):
tuples = list(tuples)

Expand Down Expand Up @@ -1271,7 +1271,7 @@ def from_product(cls, iterables, sortorder=None, names=None):
from pandas.core.reshape.util import cartesian_product

if not is_list_like(iterables):
raise TypeError("Inappropriate input for iterables.")
raise TypeError("Input must be a list / sequence of iterables.")
elif is_iterator(iterables):
iterables = list(iterables)

Expand Down
16 changes: 11 additions & 5 deletions pandas/tests/indexes/test_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,12 +675,14 @@ def test_from_arrays(self):
# list of arrays as input
result = MultiIndex.from_arrays(arrays)
assert list(result) == list(self.index)

# iterator as input
result2 = MultiIndex.from_arrays(iter(arrays))
assert list(result2) == list(self.index)

# invlide iterator input
with tm.assert_raises_regex(
TypeError, "Inappropriate input for list of arrays."):
TypeError, "Input must be a list / sequence of array-likes."):
MultiIndex.from_arrays(0)

# infer correctly
Expand Down Expand Up @@ -839,9 +841,10 @@ def test_from_product(self):
result2 = MultiIndex.from_product(iter([first, second]), names=names)
assert result2.equals(expected)
assert result2.names == names

# Invalid non-iterable input
with tm.assert_raises_regex(TypeError,
"Inappropriate input for iterables."):
with tm.assert_raises_regex(
TypeError, "Input must be a list / sequence of iterables."):
MultiIndex.from_product(0)

def test_from_product_empty(self):
Expand Down Expand Up @@ -1745,17 +1748,20 @@ def test_from_tuples(self):
expected = MultiIndex(levels=[[1, 3], [2, 4]],
labels=[[0, 1], [0, 1]],
names=['a', 'b'])

# input tuples
res1 = MultiIndex.from_tuples(((1, 2), (3, 4)), names=['a', 'b'])
assert expected.names == res1.names
assert res1.equals(expected)

# input iterator for tuples
res2 = MultiIndex.from_tuples(zip([1, 3], [2, 4]), names=['a', 'b'])
assert expected.names == res2.names
assert res2.equals(expected)

# input non-iterables
with tm.assert_raises_regex(TypeError,
'Inappropriate input for tuples.'):
with tm.assert_raises_regex(
TypeError, 'Input must be a list /sequence of tuple-likes.'):
MultiIndex.from_tuples(0)

def test_from_tuples_empty(self):
Expand Down

0 comments on commit b084cd4

Please sign in to comment.