Skip to content

Comparison of non-trivial, uncompressed, in-memory Zarr Arrays fails #348

Closed
@jakirkham

Description

@jakirkham

Comparing two in-memory Zarr arrays that do not use compressors errors out for anything other than the trivial case.

The issue being that NumPy arrays are being placed in the store (dict in this case). Even though NumPy arrays can be compared, the comparison is vectorized, which does not return a single bool that can be used in conditional expressions.

This usually works fine for other compressors as they often return bytes, which are placed in the store and can be compared to return a single bool. However this is not the case when no compressors are used or when some combination of filters and/or compressors are used that do return a NumPy array.

Minimal, reproducible code sample, a copy-pastable example if possible

In [1]: import zarr                                                             

In [2]: z1 = zarr.zeros((100,), chunks=(10,), dtype='i4', compressor=None)      

In [3]: z2 = zarr.zeros((100,), chunks=(10,), dtype='i4', compressor=None)      

In [4]: z1 == z2                                                                
Out[4]: True

In [5]: z1[0] = 5                                                               

In [6]: z2[0] = 5                                                               

In [7]: z1 == z2                                                                
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-4176b4e1c607> in <module>
----> 1 z1 == z2

/zopt/conda3/envs/test_zarr/lib/python3.6/site-packages/zarr/core.py in __eq__(self, other)
    410         return (
    411             isinstance(other, Array) and
--> 412             self.store == other.store and
    413             self.read_only == other.read_only and
    414             self.path == other.path and

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Problem description

Ideally comparison here would return True or False instead of erroring out.

Version and installation information

Please provide the following:

  • Value of zarr.__version__: 2.2.0
  • Value of numcodecs.__version__: 0.5.5
  • Version of Python interpreter: 3.6.7
  • Operating system (Linux/Windows/Mac): macOS
  • How Zarr was installed (e.g., "using pip into virtual environment", or "using conda"): Using Conda

Also, if you think it might be relevant, please provide the output from pip freeze or
conda env export depending on which was used to install Zarr.

name: test_zarr
channels:
  - conda-forge
  - defaults
dependencies:
  - appnope=0.1.0=py36_1000
  - asciitree=0.3.3=py_2
  - backcall=0.1.0=py_0
  - blas=1.1=openblas
  - ca-certificates=2018.11.29=ha4d7672_0
  - certifi=2018.11.29=py36_1000
  - decorator=4.3.0=py_0
  - fasteners=0.14.1=py_3
  - ipython=7.2.0=py36h24bf2e0_1000
  - ipython_genutils=0.2.0=py_1
  - jedi=0.13.1=py36_1000
  - libffi=3.2.1=hfc679d8_5
  - libgfortran=3.0.0=1
  - monotonic=1.5=py_0
  - msgpack-python=0.6.0=py36h2d50403_0
  - ncurses=6.1=hfc679d8_1
  - numcodecs=0.5.5=py36hfc679d8_1
  - numpy=1.15.4=py36_blas_openblashb06ca3d_0
  - openblas=0.3.3=ha44fe06_1
  - openssl=1.0.2p=h470a237_1
  - parso=0.3.1=py_0
  - pexpect=4.6.0=py36_1000
  - pickleshare=0.7.5=py36_1000
  - prompt_toolkit=2.0.7=py_0
  - ptyprocess=0.6.0=py36_1000
  - pygments=2.3.0=py_0
  - python=3.6.7=h5001a0f_1
  - readline=7.0=haf1bffa_1
  - setuptools=40.6.2=py36_0
  - six=1.11.0=py36_1001
  - sqlite=3.26.0=hb1c47c0_0
  - tk=8.6.9=ha92aebf_0
  - traitlets=4.3.2=py36_1000
  - wcwidth=0.1.7=py_1
  - xz=5.2.4=h470a237_1
  - zarr=2.2.0=py_1
  - zlib=1.2.11=h470a237_3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugPotential issues with the zarr-python library

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions