Skip to content

resize(): Improve docs & control of what is modified #1017

Open
@hailiangzhang

Description

@hailiangzhang

Problem description

For a zarr array with shape of (4,6) and chunksize of (2,3), I did the following:

  1. reduce its shape to be (1,1)
  2. increase its shape back to be (4,6)

I found that the final array after step-2 brought back the original values in the first whole chunk.
However, as an end user, I am expecting only the first element to be preserved (since I had already shrunk the shape to be (1,1), and the chunksize should be transparent to the end user).

Minimal, reproducible code sample

import zarr
import numpy as np

z = zarr.open('data', mode='w', shape=(4, 6), chunks=(2, 3), dtype='i4')
z[:] = 1

print("Original zarr array with shape (4,6):")
print(z[:])

print("\nAfter resizing shape to (1,1):")
z.resize((1,1))
print(z[:])

print("\nAfter resizing shape back to (4,6):")
z.resize((4,6))
print(z[:])

print("\nBut I was expecting it to be:")
arr_expected = np.zeros((4,6), dtype='i4')
arr_expected[0,0] = 1
print(arr_expected[:])

Output

Original zarr array with shape (4,6):
[[1 1 1 1 1 1]
 [1 1 1 1 1 1]
 [1 1 1 1 1 1]
 [1 1 1 1 1 1]]

After resizing shape to (1,1):
[[1]]

After resizing shape back to (4,6):
[[1 1 1 0 0 0]
 [1 1 1 0 0 0]
 [0 0 0 0 0 0]
 [0 0 0 0 0 0]]

But I was expecting it to be:
[[1 0 0 0 0 0]
 [0 0 0 0 0 0]
 [0 0 0 0 0 0]
 [0 0 0 0 0 0]]

Version information

  • zarr.version: 2.11.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements to the documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions