Open
Description
I thought about this, and calculating the repr is indeed a hard problem, but it becomes easy if we exclude distributed/chunked arrays.
What I propose is:
- every meta array have a
__array_meta__(): duck_array
which returns the inner array (as one can see for distributed arrays, this could require materialising the array). - In addition, there should be an
__array_attrs__(html: bool): Dict[str, Union[int, bool, float, np.generic, str]]
which should be on ALL arrays that want to be included into meta-arrays. This method returns adict
containing the elements it would like displayed. One can then use an implementation like the following:
def __repr__(self):
attrs = {}
type_names = []
current_arr = self
while current_arr is not None:
# This formulation guards against duplicate attrs
attrs = dict(**attrs, **current_arr.__array_attrs__(false))
class_names.append(type(current_arr).__name__)
current_arr = getattr(current_array, "__array_meta__", lambda: None)()
return "<{super_type_name}: {attrs_repr}>".format(
super_type_name=".".join(type_names),
attrs_repr=", ".join(f"{k}: {v!r}" for k, v in attrs.items())
)
Metadata
Metadata
Assignees
Labels
No labels