keller-mark / pizzarr

Slice into Zarr arrays in R 🍕
https://keller-mark.github.io/pizzarr/
MIT License
25 stars 2 forks source link

Unit tests for Indexer classes #14

Closed keller-mark closed 10 months ago

keller-mark commented 10 months ago

User story

The logic in the _Indexer classes was largely copied from Python. It is a bit complex so it would be great to tests, but there do not seem to be unit tests in python for these so the "correct" behavior is a bit hard to figure out.

Preferred solution

Check the outputs of the python classes for specific inputs. Write unit tests here to ensure the implementations match.

SliceDimIndexer: https://github.com/zarr-developers/zarr-python/blob/5dd4a0e6cdc04c6413e14f57f61d389972ea937c/zarr/indexing.py#L163

BasicIndexer: https://github.com/zarr-developers/zarr-python/blob/5dd4a0e6cdc04c6413e14f57f61d389972ea937c/zarr/indexing.py#L326

IntDimIndexer: https://github.com/zarr-developers/zarr-python/blob/5dd4a0e6cdc04c6413e14f57f61d389972ea937c/zarr/indexing.py#L138

keller-mark commented 10 months ago

To throw a small wrench into this, I just made some small off-by-one changes for R (one-based vs. zero-based indexing) quirks, but I added comments in all of those places like https://github.com/keller-mark/pizzarr/blob/c65fd05a41bd9e692832533a7a574f66c6f32df8/R/indexing.R#L246

keller-mark commented 10 months ago
git clone git@github.com:zarr-developers/zarr-python.git
cd zarr-python
git checkout 5dd4a0e6cdc04c6413e14f57f61d389972ea937c
conda create -n zarr-python-env python=3.10
conda activate zarr-python-env
pip install -e .
conda install jupyterlab
jupyter lab

Then add more exports to init.py: BasicIndexer, SliceDimIndexer, and IntDimIndexer so they can be imported into notebooks.