Skip to content

Commit

Permalink
Merge branch 'main' into dep/stores
Browse files Browse the repository at this point in the history
  • Loading branch information
jhamman authored Apr 22, 2024
2 parents 9e78847 + 9d046ea commit 9a7e5b8
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 16 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,8 @@ jobs:
mkdir ~/blob_emulator
azurite -l ~/blob_emulator --debug debug.log 2>&1 > stdouterr.log &
pytest --cov=zarr --cov-config=pyproject.toml --doctest-plus --cov-report xml --cov=./ --timeout=300
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
#files: ./coverage1.xml,./coverage2.xml # optional
#flags: unittests # optional
#name: codecov-umbrella # optional
#fail_ci_if_error: true # optional (default = false)
verbose: true # optional (default = false)
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ default_language_version:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: 'v0.3.5'
rev: 'v0.4.1'
hooks:
- id: ruff
- repo: https://github.com/psf/black
rev: 24.3.0
rev: 24.4.0
hooks:
- id: black
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-yaml
- repo: https://github.com/pre-commit/mirrors-mypy
Expand Down
31 changes: 27 additions & 4 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Unreleased

Enhancements
~~~~~~~~~~~~
* Performance improvement for reading and writing chunks if any of the dimensions is size 1. :issue:`1730`
By :user:`Deepak Cherian <dcherian>`.


Docs
Expand All @@ -37,22 +39,38 @@ Maintenance

Enhancements
~~~~~~~~~~~~

* [v3] Dramatically reduce number of ``__contains__`` requests in favor of optimistically calling `__getitem__`
and handling any error that may arise.
By :user:`Deepak Cherian <dcherian>`.
By :user:`Deepak Cherian <dcherian>` :issue:`1741`.

* [v3] Reuse the downloaded array metadata when creating an ``Array``.
By :user:`Deepak Cherian <dcherian>`.
By :user:`Deepak Cherian <dcherian>` :issue:`1734`.

* Optimize ``Array.info`` so that it calls `getsize` only once.
By :user:`Deepak Cherian <dcherian>`.
By :user:`Deepak Cherian <dcherian>` :issue:`1733`.

* Override IPython ``_repr_*_`` methods to avoid expensive lookups against object stores.
By :user:`Deepak Cherian <dcherian>` :issue:`1716`.

* FSStore now raises rather than return bad data.
By :user:`Martin Durant <martindurant>` and :user:`Ian Carroll <itcarroll>` :issue:`1604`.

* Avoid redundant ``__contains__``.
By :user:`Deepak Cherian <dcherian>` :issue:`1739`.

Docs
~~~~

* Fix link to GCSMap in ``tutorial.rst``.
By :user:`Daniel Jahn <dahnj>` :issue:`1689`.

* Endorse `SPEC0000 <https://scientific-python.org/specs/spec-0000/>`_ and state version support policy in ``installation.rst``.
By :user:`Sanket Verma <msankeys963>` :issue:`1665`.

* Migrate v1 and v2 specification to `Zarr-Specs <https://zarr-specs.readthedocs.io/en/latest/specs.html>`_.
By :user:`Sanket Verma <msankeys963>` :issue:`1582`.

Maintenance
~~~~~~~~~~~

Expand All @@ -61,7 +79,12 @@ Maintenance

* Bump minimum supported NumPy version to 1.23 (per spec 0000)
By :user:`Joe Hamman <jhamman>` :issue:`1719`.


* Minor fixes: Using ``is`` instead of ``type`` and removing unnecessary ``None``.
By :user:`Dimitri Papadopoulos Orfanos <DimitriPapadopoulos>` :issue:`1737`.

* Fix tests failure related to Pytest 8.
By :user:`David Stansby <dstansby>` :issue:`1714`.

.. _release_2.17.1:

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ filterwarnings = [
"ignore:PY_SSIZE_T_CLEAN will be required.*:DeprecationWarning",
"ignore:The loop argument is deprecated since Python 3.8.*:DeprecationWarning",
"ignore:The .* is deprecated and will be removed in a Zarr-Python version 3*:FutureWarning",
"ignore:The experimental Zarr V3 implementation in this version .*:FutureWarning",
]


Expand Down
13 changes: 13 additions & 0 deletions zarr/_storage/store.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import abc
import os
import warnings
from collections import defaultdict
from collections.abc import MutableMapping
from copy import copy
Expand All @@ -23,6 +24,7 @@
DEFAULT_ZARR_VERSION: ZARR_VERSION = 2

v3_api_available = os.environ.get("ZARR_V3_EXPERIMENTAL_API", "0").lower() not in ["0", "false"]
_has_warned_about_v3 = False # to avoid printing the warning multiple times

V3_DEPRECATION_MESSAGE = (
"The {store} is deprecated and will be removed in a Zarr-Python version 3, see "
Expand All @@ -31,6 +33,17 @@


def assert_zarr_v3_api_available():
# we issue a warning about the experimental v3 implementation when it is first used
global _has_warned_about_v3
if v3_api_available and not _has_warned_about_v3:
warnings.warn(
"The experimental Zarr V3 implementation in this version of Zarr-Python is not "
"in alignment with the final V3 specification. This version will be removed in "
"Zarr-Python 3 in favor of a spec compliant version.",
FutureWarning,
stacklevel=1,
)
_has_warned_about_v3 = True
if not v3_api_available:
raise NotImplementedError(
"# V3 reading and writing is experimental! To enable support, set:\n"
Expand Down
20 changes: 19 additions & 1 deletion zarr/tests/test_storage_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
import inspect
import os
import tempfile
import warnings

import numpy as np
import pytest

import zarr
from zarr._storage.store import _get_hierarchy_metadata, v3_api_available, StorageTransformer
from zarr._storage.store import (
_get_hierarchy_metadata,
assert_zarr_v3_api_available,
v3_api_available,
StorageTransformer,
)
from zarr._storage.v3_storage_transformers import ShardingStorageTransformer, v3_sharding_available
from zarr.core import Array
from zarr.meta import _default_entry_point_metadata_v3
Expand Down Expand Up @@ -668,6 +674,18 @@ def test_top_level_imports():
assert not hasattr(zarr, store_name) # pragma: no cover


def test_assert_zarr_v3_api_available_warns_once():
import zarr._storage.store

zarr._storage.store._has_warned_about_v3 = False
warnings.resetwarnings()
with pytest.warns() as record:
assert_zarr_v3_api_available()
assert_zarr_v3_api_available()
assert len(record) == 1
assert "The experimental Zarr V3 implementation" in str(record[0].message)


def _get_public_and_dunder_methods(some_class):
return set(
name
Expand Down
9 changes: 9 additions & 0 deletions zarr/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ def test_is_total_slice():
assert not is_total_slice((slice(0, 50), slice(0, 50)), (100, 100))
assert not is_total_slice((slice(0, 100, 2), slice(0, 100)), (100, 100))

# size-1 dimension edge-case
# https://github.com/zarr-developers/zarr-python/issues/1730
assert is_total_slice((slice(0, 1),), (1,))
# this is an equivalent selection (without a slice)
assert is_total_slice((0,), (1,))
# same for multidimensional selection
assert is_total_slice((slice(0, 1), slice(0, 10)), (1, 10))
assert is_total_slice((0, slice(0, 10)), (1, 10))

with pytest.raises(TypeError):
is_total_slice("foo", (100,))

Expand Down
13 changes: 11 additions & 2 deletions zarr/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,17 @@ def is_total_slice(item, shape: Tuple[int]) -> bool:
if isinstance(item, tuple):
return all(
(
isinstance(it, slice)
and ((it == slice(None)) or ((it.stop - it.start == sh) and (it.step in [1, None])))
(
isinstance(it, slice)
and (
(it == slice(None))
or ((it.stop - it.start == sh) and (it.step in [1, None]))
)
)
# The only scalar edge case, indexing with int 0 along a size-1 dimension
# is identical to a total slice
# https://github.com/zarr-developers/zarr-python/issues/1730
or (isinstance(it, int) and it == 0 and sh == 1)
)
for it, sh in zip(item, shape)
)
Expand Down

0 comments on commit 9a7e5b8

Please sign in to comment.