zarr-python icon indicating copy to clipboard operation
zarr-python copied to clipboard

Implement ipython repr methods on Group to prevent expensive lookups

Open dcherian opened this issue 1 year ago • 1 comments

Zarr version

2.16.1

Numcodecs version

...

Python Version

...

Operating System

...

Installation

conda

Description

ipython will look for 11 custom repr methods (https://ipython.readthedocs.io/en/stable/config/integrating.html#custom-methods) in a zarr group.

Zarr chooses to map any hasattr query to a __getitem__ call so sach of these queries becomes a __getitem__ call for (e.g.) _repr_mimebundle_.array.json and _repr_mimebundle_.array.json and is interleaved with a request for _ipython_canary_method_should_not_exist_.[array|group].json.

I count 44 useless requests for a simple zarr.open_group.

I think a good solution would be to implement _ipython_display_ or _repr_mimebundle_.

It would also be nice to raise AttributeError for _ipython_canary_method_should_not_exist_.

xref https://github.com/jupyter/notebook/issues/2014

Steps to reproduce

  1. Create a zarr group
  2. Open it with some way of recording getitem requests.

Additional output

No response

dcherian avatar Mar 18 '24 22:03 dcherian

Zarr chooses to map any hasattr query to a getitem call

I'm not a fan of this behavior!

d-v-b avatar Mar 18 '24 22:03 d-v-b