Skip to content

Implement ipython repr methods on Group to prevent expensive lookups #1716

Closed
@dcherian

Description

@dcherian

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 jupyter/notebook#2014

Steps to reproduce

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

Additional output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugPotential issues with the zarr-python library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions