Skip to content

Commit ae440e8

Browse files
committed
Merge branch 'main' into use-cached-attrs
* 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)
2 parents 0df8761 + aa9a0d5 commit ae440e8

File tree

8 files changed

+17
-16
lines changed

8 files changed

+17
-16
lines changed

.github/workflows/releases.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
submodules: true
1717
fetch-depth: 0
1818

19-
- uses: actions/setup-python@v5.0.0
19+
- uses: actions/setup-python@v5.1.0
2020
name: Install Python
2121
with:
2222
python-version: '3.9'

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ default_language_version:
88
repos:
99
- repo: https://github.com/astral-sh/ruff-pre-commit
1010
# Ruff version.
11-
rev: 'v0.3.4'
11+
rev: 'v0.3.5'
1212
hooks:
1313
- id: ruff
1414
- repo: https://github.com/psf/black

docs/release.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Unreleased
2121
Enhancements
2222
~~~~~~~~~~~~
2323

24+
* Optimize ``Array.info`` so that it calls `getsize` only once.
25+
By :user:`Deepak Cherian <dcherian>`.
2426
* Override IPython ``_repr_*_`` methods to avoid expensive lookups against object stores.
2527
By :user:`Deepak Cherian <dcherian>` :issue:`1716`.
2628

zarr/_storage/store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def inner_store(self) -> Union["StorageTransformer", StoreV3]:
462462

463463
def __eq__(self, other):
464464
return (
465-
type(self) == type(other)
465+
type(self) is type(other)
466466
and self._inner_store == other._inner_store
467467
and self.get_config() == other.get_config()
468468
)

zarr/core.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ def __init__(
181181
)
182182

183183
# initialize info reporter
184-
self._info_reporter = InfoReporter(self)
185184

186185
# initialize indexing helpers
187186
self._oindex = OIndex(self)
@@ -2434,7 +2433,7 @@ def info(self):
24342433
Chunks initialized : 0/10
24352434
24362435
"""
2437-
return self._info_reporter
2436+
return InfoReporter(self)
24382437

24392438
def info_items(self):
24402439
return self._synchronized_op(self._info_items_nosync)
@@ -2476,14 +2475,16 @@ def bytestr(n):
24762475
items += [("Synchronizer type", typestr(self._synchronizer))]
24772476

24782477
# storage info
2478+
nbytes = self.nbytes
2479+
nbytes_stored = self.nbytes_stored
24792480
items += [("Store type", typestr(self._store))]
24802481
if self._chunk_store is not None:
24812482
items += [("Chunk store type", typestr(self._chunk_store))]
2482-
items += [("No. bytes", bytestr(self.nbytes))]
2483-
if self.nbytes_stored > 0:
2483+
items += [("No. bytes", bytestr(nbytes))]
2484+
if nbytes_stored > 0:
24842485
items += [
2485-
("No. bytes stored", bytestr(self.nbytes_stored)),
2486-
("Storage ratio", f"{self.nbytes / self.nbytes_stored:.1f}"),
2486+
("No. bytes stored", bytestr(nbytes_stored)),
2487+
("Storage ratio", f"{nbytes / nbytes_stored:.1f}"),
24872488
]
24882489
items += [("Chunks initialized", f"{self.nchunks_initialized}/{self.nchunks}")]
24892490

zarr/hierarchy.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ def __init__(
216216
)
217217

218218
# setup info
219-
self._info = InfoReporter(self)
220219

221220
@property
222221
def store(self):
@@ -271,7 +270,7 @@ def attrs(self):
271270
@property
272271
def info(self):
273272
"""Return diagnostic information about the group."""
274-
return self._info
273+
return InfoReporter(self)
275274

276275
@property
277276
def meta_array(self):

zarr/tests/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def create_array(self, shape: Union[int, Tuple[int, ...]], **kwargs):
123123
"compressor": kwargs.pop("compressor", self.compressor),
124124
"chunk_store": chunk_store,
125125
"storage_transformers": self.create_storage_transformers(shape),
126-
"filters": kwargs.pop("filters", self.create_filters(kwargs.get("dtype", None))),
126+
"filters": kwargs.pop("filters", self.create_filters(kwargs.get("dtype"))),
127127
}
128128

129129
# keyword arguments for array instantiation

zarr/util.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,14 +408,13 @@ def info_html_report(items) -> str:
408408
class InfoReporter:
409409
def __init__(self, obj):
410410
self.obj = obj
411+
self.items = self.obj.info_items()
411412

412413
def __repr__(self):
413-
items = self.obj.info_items()
414-
return info_text_report(items)
414+
return info_text_report(self.items)
415415

416416
def _repr_html_(self):
417-
items = self.obj.info_items()
418-
return info_html_report(items)
417+
return info_html_report(self.items)
419418

420419

421420
class TreeNode:

0 commit comments

Comments
 (0)