Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Array.info and Group.info #1733

Merged
merged 4 commits into from
Apr 2, 2024

Conversation

dcherian
Copy link

@dcherian dcherian commented Mar 29, 2024

Avoid repeated computes of the same value getsize

From 6 getsize requests to 1.

TODO:

  • Add unit tests and/or doctests in docstrings
  • Changes documented in docs/release.rst
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

Avoid repeated computes of the same value (getsize)
Apparently IPython will run both __repr__ and _repr_html_
so we were calling `getsize` twice.

def __repr__(self):
items = self.obj.info_items()
return info_text_report(items)
return info_text_report(self.items)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous version called info_items twice per repr in a notebook.

Copy link

codecov bot commented Mar 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.99%. Comparing base (cb5b77a) to head (4e22036).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1733   +/-   ##
=======================================
  Coverage   99.99%   99.99%           
=======================================
  Files          38       38           
  Lines       14611    14610    -1     
=======================================
- Hits        14610    14609    -1     
  Misses          1        1           
Files Coverage Δ
zarr/core.py 100.00% <100.00%> (ø)
zarr/hierarchy.py 100.00% <100.00%> (ø)
zarr/util.py 100.00% <100.00%> (ø)

Copy link
Member

@jhamman jhamman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dcherian - brilliant!

Makes me wonder how many of these patterns exist in our zarr-Python today! ☠️

zarr/core.py Outdated Show resolved Hide resolved
zarr/hierarchy.py Outdated Show resolved Hide resolved
@dcherian dcherian changed the title Optimize Array.info. Optimize Array.info and Group.info Mar 30, 2024
docs/release.rst Outdated Show resolved Hide resolved
Co-authored-by: Joe Hamman <jhamman1@gmail.com>
@jhamman jhamman merged commit 6ef6714 into zarr-developers:main Apr 2, 2024
18 checks passed
@dcherian dcherian deleted the optimize-array-info branch April 2, 2024 12:52
dcherian added a commit to dcherian/zarr-python that referenced this pull request Apr 2, 2024
* main:
  Couple fixes (zarr-developers#1737)
  Bump actions/setup-python from 5.0.0 to 5.1.0 (zarr-developers#1736)
  Optimize Array.info and Group.info (zarr-developers#1733)
  chore: update pre-commit hooks (zarr-developers#1738)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants