Skip to content
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

empty_like for object array raises warning #257

Open
jeromekelleher opened this issue Apr 25, 2018 · 8 comments
Open

empty_like for object array raises warning #257

jeromekelleher opened this issue Apr 25, 2018 · 8 comments

Comments

@jeromekelleher
Copy link
Member

    import zarr
    z = zarr.empty(shape=(2,), dtype="array:u1")
    z[0] = [0, 1, 2]
    z[1] = [0, 0]
    print(z, z[:])
    y = zarr.empty_like(z) # Emits warning
    y[0] = [0, 1, 2]
    y[1] = [0, 0]
    print(y, y[:])

Gives:

<zarr.core.Array (2,) object> [array([0, 1, 2], dtype=uint8) array([0, 0], dtype=uint8)]
/home/jk/.local/lib/python3.5/site-packages/zarr/storage.py:372: FutureWarning: missing object_codec for object array; this will raise a ValueError in version 3.0
  'ValueError in version 3.0', FutureWarning)
<zarr.core.Array (2,) object> [array([0, 1, 2], dtype=uint8) array([0, 0], dtype=uint8)]

Problem description

It seems that empty_like is somehow not copying the codec? However, the array seems to behave perfectly well as a object array, so I'm not sure what's happening.

Version and installation information

Please provide the following:

  • Value of zarr.__version__: 2.2.0
  • Value of numcodecs.__version__: 0.5.3
  • Version of Python interpreter: 3.5.2
  • Operating system (Linux/Windows/Mac): Linux
  • How Zarr was installed (e.g., "using pip into virtual environment", or "using conda"):pip
@alimanfoo
Copy link
Member

alimanfoo commented Apr 25, 2018

Thanks Jerome, this looks like just an API inconsistency, I didn't properly consider the ..._like creation functions when writing the logic for how the object_codec keyword argument is handled. We should fix this so that no warning is emitted. For now you can ignore the warning, the array should be fine.

@hyanwong
Copy link

@alimanfoo FWIW I also see this when running copy_all (zarr-2.3.2), Max OS X

  File "/Users/yan/Documents/Research/BDI/tsinfer-hyanwong/tsinfer/formats.py", line 358, in copy
    zarr.copy_all(source=self.data, dest=other.data)
  File "/usr/local/lib/python3.7/site-packages/zarr/convenience.py", line 1069, in copy_all
    dry_run=dry_run, **create_kws)
  File "/usr/local/lib/python3.7/site-packages/zarr/convenience.py", line 962, in _copy
    dry_run=dry_run, **create_kws)
  File "/usr/local/lib/python3.7/site-packages/zarr/convenience.py", line 891, in _copy
    dtype=source.dtype, **kws)
  File "/usr/local/lib/python3.7/site-packages/zarr/hierarchy.py", line 770, in create_dataset
    return self._write_op(self._create_dataset_nosync, name, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/zarr/hierarchy.py", line 628, in _write_op
    return f(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/zarr/hierarchy.py", line 783, in _create_dataset_nosync
    **kwargs)
  File "/usr/local/lib/python3.7/site-packages/zarr/creation.py", line 120, in create
    chunk_store=chunk_store, filters=filters, object_codec=object_codec)
  File "/usr/local/lib/python3.7/site-packages/zarr/storage.py", line 323, in init_array
    object_codec=object_codec)
  File "/usr/local/lib/python3.7/site-packages/zarr/storage.py", line 383, in _init_array_metadata
    'ValueError in version 3.0', FutureWarning)
FutureWarning: missing object_codec for object array; this will raise a ValueError in version 3.0

@alimanfoo
Copy link
Member

Thanks @hyanwong, very useful to know. I think you can ignore the warning but we should fix this so it doesn't get emitted.

@hyanwong
Copy link

Yep thanks. Was ignoring it anyway :)

@hyanwong
Copy link

It would be great to fix this if possible, @alimanfoo ! But I guess you are pretty busy at the moment?

@jakirkham
Copy link
Member

Contributions welcome :)

@hyanwong
Copy link

Happy to have a go, but not sure if I should just hack around it (i.e. omit this FutureWarning in this case), or if it's more complex than that. I imagine it's the latter!

@hyanwong
Copy link

Here's the warning (turned into an error for debugging) that I'm getting with the current master GitHub branch:

Any clues as to where/how to fix this welcome, and I can try to implement it @jakirkham

  File "/usr/local/anaconda3/lib/python3.8/site-packages/tsinfer/formats.py", line 497, in copy
    zarr.copy_all(source=self.data, dest=other.data)
  File "/usr/local/anaconda3/lib/python3.8/site-packages/zarr/convenience.py", line 1058, in copy_all
    c, s, b = _copy(
  File "/usr/local/anaconda3/lib/python3.8/site-packages/zarr/convenience.py", line 951, in _copy
    c, s, b = _copy(
  File "/usr/local/anaconda3/lib/python3.8/site-packages/zarr/convenience.py", line 882, in _copy
    ds = dest.create_dataset(name, shape=source.shape,
  File "/usr/local/anaconda3/lib/python3.8/site-packages/zarr/hierarchy.py", line 806, in create_dataset
    return self._write_op(self._create_dataset_nosync, name, **kwargs)
  File "/usr/local/anaconda3/lib/python3.8/site-packages/zarr/hierarchy.py", line 661, in _write_op
    return f(*args, **kwargs)
  File "/usr/local/anaconda3/lib/python3.8/site-packages/zarr/hierarchy.py", line 818, in _create_dataset_nosync
    a = create(store=self._store, path=path, chunk_store=self._chunk_store,
  File "/usr/local/anaconda3/lib/python3.8/site-packages/zarr/creation.py", line 121, in create
    init_array(store, shape=shape, chunks=chunks, dtype=dtype, compressor=compressor,
  File "/usr/local/anaconda3/lib/python3.8/site-packages/zarr/storage.py", line 344, in init_array
    _init_array_metadata(store, shape=shape, chunks=chunks, dtype=dtype,
  File "/usr/local/anaconda3/lib/python3.8/site-packages/zarr/storage.py", line 418, in _init_array_metadata
    warnings.warn('missing object_codec for object array; this will raise a '
FutureWarning: missing object_codec for object array; this will raise a ValueError in version 3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants