Skip to content

Correct default fill_value for creation.create #966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion zarr/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


def create(shape, chunks=True, dtype=None, compressor='default',
fill_value=0, order='C', store=None, synchronizer=None,
fill_value=None, order='C', store=None, synchronizer=None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any other effects from changing this from 0 to None?

Should we be updating fill_values elsewhere to match?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only other use of fill_value=0 I can see is creation.open_array. I assume this should probably be None too, but I'm not too familiar with all the effects here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

open_array just calls init_array if needed, which already has fill_value=None. So making it None in open_array seems more consistent with the underlying function.

overwrite=False, path=None, chunk_store=None, filters=None,
cache_metadata=True, cache_attrs=True, read_only=False,
object_codec=None, dimension_separator=None,
Expand Down
9 changes: 9 additions & 0 deletions zarr/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from pkg_resources import parse_version

from zarr.core import Array
from zarr.creation import create
from zarr.meta import json_loads
from zarr.n5 import N5Store, N5FSStore, n5_keywords
from zarr.storage import (
Expand Down Expand Up @@ -1249,6 +1250,14 @@ def test_object_arrays_vlen_bytes(self):
assert_array_equal(data, z[:])
z.store.close()

# Zero-length bytes
z = create(shape=(1,), dtype=bytes)
assert z.dtype == object
assert isinstance(z.filters[0], VLenBytes)
z[0] = b''
assert z[0] == b''
z.store.close()

z = self.create_array(shape=data.shape, dtype=object, object_codec=Pickle())
z[:] = data
assert_array_equal(data, z[:])
Expand Down
2 changes: 1 addition & 1 deletion zarr/tests/test_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def test_create():
assert (100,) == z.chunks # auto-chunks
assert np.dtype(None) == z.dtype
assert 'blosc' == z.compressor.codec_id
assert 0 == z.fill_value
assert None == z.fill_value

# all specified
z = create(100, chunks=10, dtype='i4', compressor=Zlib(1),
Expand Down
2 changes: 1 addition & 1 deletion zarr/tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2207,7 +2207,7 @@ def test_read_write(self):


def test_fill_value_change():
a = zarr.create((10, 10), dtype=int)
a = zarr.create((10, 10), dtype=int, fill_value=0)

assert a[0, 0] == 0

Expand Down