You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into this when I accidentally passed my codes to the ordered argument
Code Sample, a copy-pastable example if possible
In [2]: pd.Categorical.from_codes([0, 0, 1], categories=['a', 'b', 'c'], ordered=np.array([0, 1, 2]))
Out[2]: ---------------------------------------------------------------------------ValueErrorTraceback (mostrecentcalllast)
/Users/tom.augspurger/Envs/py3/lib/python3.5/site-packages/IPython/core/formatters.pyin__call__(self, obj)
668type_pprinters=self.type_printers,
669deferred_pprinters=self.deferred_printers)
-->670printer.pretty(obj)
671printer.flush()
672returnstream.getvalue()
/Users/tom.augspurger/Envs/py3/lib/python3.5/site-packages/IPython/lib/pretty.pyinpretty(self, obj)
381ifcallable(meth):
382returnmeth(obj, self, cycle)
-->383return_default_pprint(obj, self, cycle)
384finally:
385self.end_group()
/Users/tom.augspurger/Envs/py3/lib/python3.5/site-packages/IPython/lib/pretty.pyin_default_pprint(obj, p, cycle)
501if_safe_getattr(klass, '__repr__', None) notin_baseclass_reprs:
502# A user-provided repr. Find newlines and replace them with p.break_()-->503_repr_pprint(obj, p, cycle)
504return505p.begin_group(1, '<')
/Users/tom.augspurger/Envs/py3/lib/python3.5/site-packages/IPython/lib/pretty.pyin_repr_pprint(obj, p, cycle)
692"""A pprint that just redirects to the normal repr function."""693# Find newlines and replace them with p.break_()-->694output=repr(obj)
695foridx,output_lineinenumerate(output.splitlines()):
696ifidx:
/Users/tom.augspurger/Envs/py3/lib/python3.5/site-packages/pandas/pandas/core/base.pyin__repr__(self)
70YieldsBytestringinPy2, UnicodeStringinpy3.
71 """
---> 72 return str(self)
73
74
/Users/tom.augspurger/Envs/py3/lib/python3.5/site-packages/pandas/pandas/core/base.py in __str__(self)
49
50 if compat.PY3:
---> 51 return self.__unicode__()
52 return self.__bytes__()
53
/Users/tom.augspurger/Envs/py3/lib/python3.5/site-packages/pandas/pandas/core/categorical.py in __unicode__(self)
1571 result = self._tidy_repr(_maxlen)
1572 elif len(self._codes) > 0:
-> 1573 result = self._get_repr(length=len(self) > _maxlen)
1574 else:
1575 result = ('[], %s' %
/Users/tom.augspurger/Envs/py3/lib/python3.5/site-packages/pandas/pandas/core/categorical.py in _get_repr(self, length, na_rep, footer)
1562 formatter = fmt.CategoricalFormatter(self, length=length,
1563 na_rep=na_rep, footer=footer)
-> 1564 result = formatter.to_string()
1565 return compat.text_type(result)
1566
/Users/tom.augspurger/Envs/py3/lib/python3.5/site-packages/pandas/pandas/formats/format.py in to_string(self)
134 result = [u('[') + result + u(']')]
135 if self.footer:
--> 136 footer = self._get_footer()
137 if footer:
138 result.append(footer)
/Users/tom.augspurger/Envs/py3/lib/python3.5/site-packages/pandas/pandas/formats/format.py in _get_footer(self)
105 footer += "Length: %d" % len(self.categorical)
106
--> 107 level_info = self.categorical._repr_categories_info()
108
109 # Levels are added in a newline
/Users/tom.augspurger/Envs/py3/lib/python3.5/site-packages/pandas/pandas/core/categorical.py in _repr_categories_info(self)
1540 start = True
1541 cur_col_len = len(levheader) # header
-> 1542 sep_len, sep = (3, " < ") if self.ordered else (2, ", ")
1543 linesep = sep.rstrip() + "\n" # remove whitespace
1544 for val in category_strs:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
If you look through the traceback, the error happens in the repr, not at construction time.
The regular Categorical constructor does catch this (error message could be improved though).
Expected Output
TypeError("orderedmust be a boolean, got {!r} instead")
output of pd.show_versions()
master
The text was updated successfully, but these errors were encountered:
I ran into this when I accidentally passed my codes to the
ordered
argumentCode Sample, a copy-pastable example if possible
If you look through the traceback, the error happens in the
repr
, not at construction time.The regular
Categorical
constructor does catch this (error message could be improved though).Expected Output
TypeError("
orderedmust be a boolean, got {!r} instead")
output of
pd.show_versions()
master
The text was updated successfully, but these errors were encountered: