Skip to content

can't print embedded ndarray #490

Closed
Closed
@nbecker

Description

@nbecker

Just playing with pandas. I was using structured array. I tried converting my structured array to pandas. It was OK, until I tried with a field that was itself a (variable length) ndarray.

arr = np.empty ((len(results),), dtype=[(... various fields ommitted,

                ('err', object),
                                    ('bursts', int),
                ('per', float), ...
                ])

Next the array is filled with data.
The field 'err' is then filled in with a ndarray (vector) whose size is variable per instance.

Now convert to df:

from pandas import *
df = DataFrame (arr)

Any attempt to print anything with 'err' field gives an exception

/home/nbecker/hn-8psk/ in ()
----> 1 df['err']

/usr/lib/python2.7/site-packages/IPython/core/displayhook.pyc in call(self, result)
300 self.start_displayhook()
301 self.write_output_prompt()
--> 302 format_dict = self.compute_format_data(result)
303 self.write_format_data(format_dict)
304 self.update_user_ns(result)

/usr/lib/python2.7/site-packages/IPython/core/displayhook.pyc in compute_format_data(self, result)
213 MIME type representation of the object.
214 """
--> 215 return self.shell.display_formatter.format(result)
216
217 def write_format_data(self, format_dict):

/usr/lib/python2.7/site-packages/IPython/core/formatters.pyc in format(self, obj, include, exclude)
120 continue
121 try:
--> 122 data = formatter(obj)
123 except:
124 # FIXME: log the exception

/usr/lib/python2.7/site-packages/IPython/core/formatters.pyc in call(self, obj)
441 type_pprinters=self.type_printers,
442 deferred_pprinters=self.deferred_printers)
--> 443 printer.pretty(obj)
444 printer.flush()
445 return stream.getvalue()

/usr/lib/python2.7/site-packages/IPython/lib/pretty.pyc in pretty(self, obj)
349 if hasattr(obj_class, 'repr_pretty'):
350 return obj_class.repr_pretty(obj, self, cycle)
--> 351 return _default_pprint(obj, self, cycle)
352 finally:
353 self.end_group()

/usr/lib/python2.7/site-packages/IPython/lib/pretty.pyc in _default_pprint(obj, p, cycle)
467 if getattr(klass, 'repr', None) not in _baseclass_reprs:
468 # A user-provided repr.

--> 469 p.text(repr(obj))
470 return
471 p.begin_group(1, '<')

/usr/lib64/python2.7/site-packages/pandas/core/series.pyc in repr(self)
435 result = self._get_repr(print_header=True,
436 length=len(self) > 50,
--> 437 name=True)
438 else:
439 result = '%s' % ndarray.repr(self)

/usr/lib64/python2.7/site-packages/pandas/core/series.pyc in _get_repr(self, name, print_header, length, na_rep, float_format)
494 return '%s %s' % (str(k).ljust(padSpace), v)
495
--> 496 it = [_format(idx, v) for idx, v in izip(string_index, vals)]
497
498 if print_header and have_header:

/usr/lib64/python2.7/site-packages/pandas/core/series.pyc in _format(k, v)
488
489 def _format(k, v):
--> 490 if isnull(v):
491 v = na_rep
492 if isinstance(v, (float, np.floating)):

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

In [82]:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions