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
Python version: 3.9.16 (main, Dec 7 2022, 01:11:51) [GCC 9.4.0]
Operating System: uname_result(system='Linux', node='73b98b6d221c', release='5.10.147+', version='# 1 SMP Sat Dec 10 16:00:40 UTC 2022', machine='x86_64')
Description
I use dataclasses with numpy array fields and noticed that prettyprinting fails when the typing for init values is e.g. Optional[np.ndarray] or Union[np.ndarray, None] and additionally None is specified as default.
The same did not happen e.g. for Optional[List] = None.
This did not happen for Union[np.ndarray, str] = 'test'
The system I use this on is a Google Colab (see info above), which currently still runs Python 3.9 and might have additional specifics I don't know about.
Test1(
another_array=numpy.ndarray([1, 2, 3, 4]),
maybe_array=numpy.ndarray([1, 2, 3, 4])
)
---
Test2(another_array=array([1, 2, 3, 4]), maybe_array=array([1, 2, 3, 4]))
/usr/local/lib/python3.9/dist-packages/prettyprinter/prettyprinter.py:340: UserWarning: The pretty printer for Test2, prettyprinter.prettyprinter._repr_pretty, raised an exception. Falling back to default repr.
Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/prettyprinter/prettyprinter.py", line 387, in _run_pretty
doc = pretty_fn(value, ctx)
File "/usr/local/lib/python3.9/dist-packages/prettyprinter/prettyprinter.py", line 424, in _repr_pretty
return fn(value, ctx)
File "/usr/local/lib/python3.9/dist-packages/prettyprinter/extras/dataclasses.py", line 40, in pretty_dataclass_instance
if field_def.default != getattr(value, field_def.name):
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
warnings.warn(
The text was updated successfully, but these errors were encountered:
Description
I use dataclasses with numpy array fields and noticed that prettyprinting fails when the typing for init values is e.g.
Optional[np.ndarray]
orUnion[np.ndarray, None]
and additionallyNone
is specified as default.Optional[List] = None
.Union[np.ndarray, str] = 'test'
What I Did
Input:
Output:
The text was updated successfully, but these errors were encountered: