Assigning array of >1 dim to index produces inconsistent index · Issue #13601 · pandas-dev/pandas (original) (raw)
In [3]: s = pd.Series(0, range(4))
In [4]: s.index = np.array([[2,3]]*4)
In [5]: s
Out[5]: ---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/nobackup/repo/ipython/IPython/core/formatters.py in __call__(self, obj)
683 type_pprinters=self.type_printers,
684 deferred_pprinters=self.deferred_printers)
--> 685 printer.pretty(obj)
686 printer.flush()
687 return stream.getvalue()
/home/nobackup/repo/ipython/IPython/lib/pretty.py in pretty(self, obj)
381 if callable(meth):
382 return meth(obj, self, cycle)
--> 383 return _default_pprint(obj, self, cycle)
384 finally:
385 self.end_group()
/home/nobackup/repo/ipython/IPython/lib/pretty.py in _default_pprint(obj, p, cycle)
501 if _safe_getattr(klass, '__repr__', None) not in _baseclass_reprs:
502 # A user-provided repr. Find newlines and replace them with p.break_()
--> 503 _repr_pprint(obj, p, cycle)
504 return
505 p.begin_group(1, '<')
/home/nobackup/repo/ipython/IPython/lib/pretty.py in _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_()
--> 694 output = repr(obj)
695 for idx,output_line in enumerate(output.splitlines()):
696 if idx:
/home/nobackup/repo/pandas/pandas/core/base.py in __repr__(self)
65 Yields Bytestring in Py2, Unicode String in py3.
66 """
---> 67 return str(self)
68
69
/home/nobackup/repo/pandas/pandas/core/base.py in __str__(self)
44
45 if compat.PY3:
---> 46 return self.__unicode__()
47 return self.__bytes__()
48
/home/nobackup/repo/pandas/pandas/core/series.py in __unicode__(self)
979
980 self.to_string(buf=buf, name=self.name, dtype=self.dtype,
--> 981 max_rows=max_rows)
982 result = buf.getvalue()
983
/home/nobackup/repo/pandas/pandas/core/series.py in to_string(self, buf, na_rep, float_format, header, index, length, dtype, name, max_rows)
1020 the_repr = self._get_repr(float_format=float_format, na_rep=na_rep,
1021 header=header, index=index, length=length,
-> 1022 dtype=dtype, name=name, max_rows=max_rows)
1023
1024 # catch contract violations
/home/nobackup/repo/pandas/pandas/core/series.py in _get_repr(self, name, header, index, length, dtype, na_rep, float_format, max_rows)
1048 float_format=float_format,
1049 max_rows=max_rows)
-> 1050 result = formatter.to_string()
1051
1052 # TODO: following check prob. not neces.
/home/nobackup/repo/pandas/pandas/formats/format.py in to_string(self)
227 return 'Series([], ' + footer + ')'
228
--> 229 fmt_index, have_header = self._get_formatted_index()
230 fmt_values = self._get_formatted_values()
231
/home/nobackup/repo/pandas/pandas/formats/format.py in _get_formatted_index(self)
213 else:
214 have_header = index.name is not None
--> 215 fmt_index = index.format(name=True)
216 return fmt_index, have_header
217
/home/nobackup/repo/pandas/pandas/indexes/base.py in format(self, name, formatter, **kwargs)
1525 return header + list(self.map(formatter))
1526
-> 1527 return self._format_with_header(header, **kwargs)
1528
1529 def _format_with_header(self, header, na_rep='NaN', **kwargs):
/home/nobackup/repo/pandas/pandas/indexes/base.py in _format_with_header(self, header, na_rep, **kwargs)
1549
1550 else:
-> 1551 result = _trim_front(format_array(values, None, justify='left'))
1552 return header + result
1553
/home/nobackup/repo/pandas/pandas/formats/format.py in format_array(values, formatter, float_format, na_rep, digits, space, justify, decimal)
2021 space=space, justify=justify, decimal=decimal)
2022
-> 2023 return fmt_obj.get_result()
2024
2025
/home/nobackup/repo/pandas/pandas/formats/format.py in get_result(self)
2040
2041 def get_result(self):
-> 2042 fmt_values = self._format_strings()
2043 return _make_fixed_width(fmt_values, self.justify)
2044
/home/nobackup/repo/pandas/pandas/formats/format.py in _format_strings(self)
2226 def _format_strings(self):
2227 formatter = self.formatter or (lambda x: '% d' % x)
-> 2228 fmt_values = [formatter(x) for x in self.values]
2229 return fmt_values
2230
/home/nobackup/repo/pandas/pandas/formats/format.py in <listcomp>(.0)
2226 def _format_strings(self):
2227 formatter = self.formatter or (lambda x: '% d' % x)
-> 2228 fmt_values = [formatter(x) for x in self.values]
2229 return fmt_values
2230
/home/nobackup/repo/pandas/pandas/formats/format.py in <lambda>(x)
2225 class IntArrayFormatter(GenericArrayFormatter):
2226 def _format_strings(self):
-> 2227 formatter = self.formatter or (lambda x: '% d' % x)
2228 fmt_values = [formatter(x) for x in self.values]
2229 return fmt_values
TypeError: %d format: a number is required, not numpy.ndarray
It would be cool if this became a MultiIndex
automatically, but otherwise it should just raise an error (or maybe it's just the string representation which is broken?)
In [6]: pd.show_versions()
INSTALLED VERSIONS
------------------
commit: a63bd12529ff309d957d714825b1753d0e02b7fa
python: 3.5.1.final.0
python-bits: 64
OS: Linux
OS-release: 4.5.0-2-amd64
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: it_IT.utf8
LOCALE: it_IT.UTF-8
pandas: 0.18.1+174.ga63bd12
nose: 1.3.7
pip: 1.5.6
setuptools: 18.4
Cython: 0.23.4
numpy: 1.10.4
scipy: 0.16.0
statsmodels: 0.8.0.dev0+111ddc0
xarray: None
IPython: 5.0.0.dev
sphinx: 1.3.1
patsy: 0.3.0-dev
dateutil: 2.2
pytz: 2012c
blosc: None
bottleneck: 1.1.0dev
tables: 3.2.2
numexpr: 2.5
matplotlib: 1.5.1
openpyxl: None
xlrd: 0.9.4
xlwt: 1.1.2
xlsxwriter: 0.7.3
lxml: None
bs4: 4.4.0
html5lib: 0.999
httplib2: 0.9.1
apiclient: 1.5.0
sqlalchemy: 1.0.11
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.38.0
pandas_datareader: 0.2.1