`concatenate_arrays` with (slightly) different array shapes
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 366
- Forks
- 96
- Avg merge
- 24m
- Merged PRs (30d)
- 1
Description
I would like to be able to concatenate arrays with different shapes. They should have the size in each dimension except for the one we are concatenating along (e.g. numpy concatenation rules).
Why doesn't concatenate_arrays work in this case right now, and what would it take to work?
The current restriction of "same size" doesn't seem to be working (#304), but also the current documented restrictions don't seem accurate. For example, these arrays have the same size and chunking:
import fsspec
import numpy as np
import zarr
import kerchunk.combine
import kerchunk.zarr
fn1 = f"tmp/out1.zarr"
fn2 = f"tmp/out2.zarr"
x1 = np.arange(10)
x2 = np.arange(10, 20)
g1 = zarr.open(fn1, "w")
g1.create_dataset("x", data=x1, chunks=(3,))
g2 = zarr.open(fn2, "w")
g2.create_dataset("x", data=x2, chunks=(3,))
However concatenate_arrays produces invalid results:
ref1 = kerchunk.zarr.single_zarr(fn1, inline=0)
ref2 = kerchunk.zarr.single_zarr(fn2, inline=0)
out = kerchunk.combine.concatenate_arrays([ref1, ref2], path="x",)
mapper = fsspec.get_mapper("reference://", fo=out)
g = zarr.open(mapper)
np.all(g["x"][:], np.concatenate([x1, x2]))
# False
g["x"][:]
# array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0])
This broadly makes sense to me, due to a chunk boundary not aligning with the end of the first array. Is that resolvable without ZEP 3?
And otherwise, should an additional restriction on concatenate_arrays be: (shape % chunks) == 0 for dimensions being concatenated along?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the concatenate_arrays entry point and reproduce the example using fsspec, numpy, zarr, and the two generated arrays. Trace how chunk boundaries and array shapes are combined; done means the concatenated mapper returns the expected array and the accepted shape and chunking restrictions are documented accurately.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data-engineering
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100