-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
158 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: Zarr v3 Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- "main" | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: Tests-${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
test: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: ["ubuntu-latest"] | ||
python-version: ["3.10"] | ||
|
||
steps: | ||
- name: Checkout source | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
architecture: x64 | ||
|
||
- name: Setup Graphviz | ||
uses: ts-graphviz/setup-graphviz@v2 | ||
with: | ||
macos-skip-brew-update: 'true' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
- name: Install | ||
run: | | ||
python -m pip install -e .[test] | ||
python -m pip install -U git+https://github.com/zarr-developers/zarr-python.git@v3 | ||
- name: Run tests | ||
env: | ||
COVERAGE_CORE: sysmon | ||
run: | | ||
if [ "$RUNNER_OS" == "Windows" ]; then | ||
pytest -v | ||
else | ||
pytest -v --cov=cubed --cov-report=term-missing --cov-fail-under=90 | ||
fi | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from typing import Optional | ||
|
||
import zarr | ||
|
||
from cubed.types import T_DType, T_RegularChunks, T_Shape, T_Store | ||
from cubed.utils import join_path | ||
|
||
|
||
class ZarrV3ArrayGroup(dict): | ||
def __init__( | ||
self, | ||
shape: Optional[T_Shape] = None, | ||
dtype: Optional[T_DType] = None, | ||
chunks: Optional[T_RegularChunks] = None, | ||
): | ||
dict.__init__(self) | ||
self.shape = shape | ||
self.dtype = dtype | ||
self.chunks = chunks | ||
|
||
def __getitem__(self, key): | ||
if isinstance(key, str): | ||
return super().__getitem__(key) | ||
return {field: zarray[key] for field, zarray in self.items()} | ||
|
||
def set_basic_selection(self, selection, value, fields=None): | ||
self[fields][selection] = value | ||
|
||
|
||
def open_zarr_v3_array( | ||
store: T_Store, | ||
mode: str, | ||
*, | ||
shape: Optional[T_Shape] = None, | ||
dtype: Optional[T_DType] = None, | ||
chunks: Optional[T_RegularChunks] = None, | ||
path: Optional[str] = None, | ||
**kwargs, | ||
): | ||
if isinstance(chunks, int): | ||
chunks = (chunks,) | ||
|
||
if mode in ("r", "r+"): | ||
# TODO: remove when https://github.com/zarr-developers/zarr-python/issues/1978 is fixed | ||
if mode == "r+": | ||
mode = "w" | ||
if dtype is None or not hasattr(dtype, "fields") or dtype.fields is None: | ||
return zarr.open(store=store, mode=mode, path=path) | ||
else: | ||
ret = ZarrV3ArrayGroup(shape=shape, dtype=dtype, chunks=chunks) | ||
for field in dtype.fields: | ||
field_dtype, _ = dtype.fields[field] | ||
field_path = field if path is None else join_path(path, field) | ||
ret[field] = zarr.open(store=store, mode=mode, path=field_path) | ||
return ret | ||
else: | ||
overwrite = True if mode == "a" else False | ||
if dtype is None or not hasattr(dtype, "fields") or dtype.fields is None: | ||
return zarr.create( | ||
shape=shape, | ||
dtype=dtype, | ||
chunk_shape=chunks, | ||
store=store, | ||
overwrite=overwrite, | ||
path=path, | ||
) | ||
else: | ||
ret = ZarrV3ArrayGroup(shape=shape, dtype=dtype, chunks=chunks) | ||
for field in dtype.fields: | ||
field_dtype, _ = dtype.fields[field] | ||
field_path = field if path is None else join_path(path, field) | ||
ret[field] = zarr.create( | ||
shape=shape, | ||
dtype=field_dtype, | ||
chunk_shape=chunks, | ||
store=store, | ||
overwrite=overwrite, | ||
path=field_path, | ||
) | ||
return ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters