@@ -1409,15 +1409,24 @@ def _normalize_tabular_data(tabular_data, headers, showindex="default"):
14091409 except ValueError : # numpy.ndarray, pandas.core.index.Index, ...
14101410 headers = list (headers )
14111411
1412+ err_msg = (
1413+ "\n \n To build a table python-tabulate requires two-dimensional data "
1414+ "like a list of lists or similar."
1415+ "\n Did you forget a pair of extra [] or ',' in ()?"
1416+ )
14121417 index = None
14131418 if hasattr (tabular_data , "keys" ) and hasattr (tabular_data , "values" ):
14141419 # dict-like and pandas.DataFrame?
14151420 if hasattr (tabular_data .values , "__call__" ):
14161421 # likely a conventional dict
14171422 keys = tabular_data .keys ()
1418- rows = list (
1419- izip_longest (* tabular_data .values ())
1420- ) # columns have to be transposed
1423+ try :
1424+ rows = list (
1425+ izip_longest (* tabular_data .values ())
1426+ ) # columns have to be transposed
1427+ except TypeError : # not iterable
1428+ raise TypeError (err_msg )
1429+
14211430 elif hasattr (tabular_data , "index" ):
14221431 # values is a property, has .index => it's likely a pandas.DataFrame (pandas 0.11.0)
14231432 keys = list (tabular_data )
@@ -1440,7 +1449,10 @@ def _normalize_tabular_data(tabular_data, headers, showindex="default"):
14401449 headers = list (map (str , keys )) # headers should be strings
14411450
14421451 else : # it's a usual iterable of iterables, or a NumPy array, or an iterable of dataclasses
1443- rows = list (tabular_data )
1452+ try :
1453+ rows = list (tabular_data )
1454+ except TypeError : # not iterable
1455+ raise TypeError (err_msg )
14441456
14451457 if headers == "keys" and not rows :
14461458 # an empty table (issue #81)
0 commit comments