stringdtype: problem displaying a structured array containing a StringDType
WarrenWeckesser opened this issue · 2 comments
WarrenWeckesser commented
I ran into this exception when I tried to use a StringDType in a structured array:
In [47]: dt = np.dtype([('id', int), ('value', float), ('key', StringDType())])
In [48]: dt
Out[48]: ---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
File ~/py3.11.5/lib/python3.11/site-packages/IPython/core/formatters.py:708, in PlainTextFormatter.__call__(self, obj)
701 stream = StringIO()
702 printer = pretty.RepresentationPrinter(stream, self.verbose,
703 self.max_width, self.newline,
704 max_seq_length=self.max_seq_length,
705 singleton_pprinters=self.singleton_printers,
706 type_pprinters=self.type_printers,
707 deferred_pprinters=self.deferred_printers)
--> 708 printer.pretty(obj)
709 printer.flush()
710 return stream.getvalue()
File ~/py3.11.5/lib/python3.11/site-packages/IPython/lib/pretty.py:410, in RepresentationPrinter.pretty(self, obj)
407 return meth(obj, self, cycle)
408 if cls is not object \
409 and callable(cls.__dict__.get('__repr__')):
--> 410 return _repr_pprint(obj, self, cycle)
412 return _default_pprint(obj, self, cycle)
413 finally:
File ~/py3.11.5/lib/python3.11/site-packages/IPython/lib/pretty.py:778, in _repr_pprint(obj, p, cycle)
776 """A pprint that just redirects to the normal repr function."""
777 # Find newlines and replace them with p.break_()
--> 778 output = repr(obj)
779 lines = output.splitlines()
780 with p.group():
File ~/py3.11.5/lib/python3.11/site-packages/numpy/core/_dtype.py:46, in __repr__(dtype)
45 def __repr__(dtype):
---> 46 arg_str = _construction_repr(dtype, include_align=False)
47 if dtype.isalignedstruct:
48 arg_str = arg_str + ", align=True"
File ~/py3.11.5/lib/python3.11/site-packages/numpy/core/_dtype.py:96, in _construction_repr(dtype, include_align, short)
69 """
70 Creates a string repr of the dtype, excluding the 'dtype()' part
71 surrounding the object. This object may be a string, a list, or
(...)
93 provided as the second parameter.
94 """
95 if dtype.fields is not None:
---> 96 return _struct_str(dtype, include_align=include_align)
97 elif dtype.subdtype:
98 return _subarray_str(dtype)
File ~/py3.11.5/lib/python3.11/site-packages/numpy/core/_dtype.py:310, in _struct_str(dtype, include_align)
305 def _struct_str(dtype, include_align):
306 # The list str representation can't include the 'align=' flag,
307 # so if it is requested and the struct has the aligned flag set,
308 # we must use the dict str instead.
309 if not (include_align and dtype.isalignedstruct) and _is_packed(dtype):
--> 310 sub = _struct_list_str(dtype)
312 else:
313 sub = _struct_dict_str(dtype, include_align)
File ~/py3.11.5/lib/python3.11/site-packages/numpy/core/_dtype.py:297, in _struct_list_str(dtype)
292 item += "{}, {}".format(
293 _construction_repr(base, short=True),
294 shape
295 )
296 else:
--> 297 item += _construction_repr(fld_dtype, short=True)
299 item += ")"
300 items.append(item)
File ~/py3.11.5/lib/python3.11/site-packages/numpy/core/_dtype.py:100, in _construction_repr(dtype, include_align, short)
98 return _subarray_str(dtype)
99 else:
--> 100 return _scalar_str(dtype, short=short)
File ~/py3.11.5/lib/python3.11/site-packages/numpy/core/_dtype.py:156, in _scalar_str(dtype, short)
153 return dtype.type.__name__
155 else:
--> 156 raise RuntimeError(
157 "Internal error: NumPy dtype unrecognized type number")
RuntimeError: Internal error: NumPy dtype unrecognized type number
ngoldbaum commented
Probably needs an upstream numpy issue, you'd hit the same error with any user-defined dtype using the new dtype API.
ngoldbaum commented
I opened numpy/numpy#24758