question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exceptions when creating an array that has an object

See original GitHub issue

I noticed two issues:

  1. Zarr raises an exception when attempting to create an array with a structured dtype that contains an object.
>>> import numcodecs
>>> import zarr
>>> foo = zarr.open('foo')
>>> foo.create('bar', dtype=[('x', float), ('y',object)],  shape=(10, 20), object_codec=numcodecs.Pickle())
TypeError                                 Traceback (most recent call last)
    ...
MetadataError: error decoding metadata: Cannot change data-type for object array.

I think that the issue is in the functions encode_fill_value and decode_fill_value. A structured dtype that contains an object reports its kind as ‘V’ so zarr encodes it using standard_b64encode, but if dtype.has_object is true then it should first pickle the fill_value and only then encode it.

  1. This is a related problem to item 1. zarr essentially only supports fill-values of None for object arrays:
>>> import numpy
>>> import zarr
>>> x = zarr.open('x')
>>> y = x.create('y', shape=(2, 2), dtype='O', fill_value=zarr.Blosc, object_codec=numcodecs.Pickle())
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
    ...
TypeError: Object of type type is not JSON serializable
  • Value of zarr.__version__: 2.8.3
  • Value of numcodecs.__version__: 0.6.4 – 0.8.0
  • Version of Python interpreter: 3.7.4 – 3.9.6
  • Operating system (Linux/Windows/Mac): Mac/Linux
  • How Zarr was installed (e.g., “using pip into virtual environment”, or “using conda”): pip or conda

Edit: I cleaned up the second example (I copied and pasted an incorrect reproducer here).

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
abergoucommented, Aug 30, 2021

Thanks @joshmoore !

1reaction
abergoucommented, Aug 9, 2021

Thanks for the quick reply @joshmoore!

Where do I pass in data=? I don’t see it as an argument to Group.create. If I simply pass it into foo.create then I get back the same error as before:

>>> import numcodecs
>>> import numpy
>>> import zarr
>>> foo = zarr.open('foo')
>>> foo.create('bar', dtype=[('x', float), ('y',object)],  shape=(10, 20), object_codec=numcodecs.Pickle(), data=numpy.zeros((10, 20), dtype=[('x', float), ('y', object)]))
TypeError                                 Traceback (most recent call last)
    ...
MetadataError: error decoding metadata: Cannot change data-type for object array.

Quick note: I fixed up the second reproducer I had above. I had a copy paste error that I didn’t notice before.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Array Exceptions in Java - C# Corner
In this article we are going to describe the many exceptions that are possibly generated by an array in Java.
Read more >
Exception in creating array of Objects - java - Stack Overflow
I am storing sum of all pairs of an array element to pairSum[] array. For this I have created PairSum class which store...
Read more >
Chapter 10. Arrays
An array object contains a number of variables. ... Declaring a variable of array type does not create an array object or allocate...
Read more >
Creating and Throwing Exceptions | Microsoft Learn
Learn about creating and throwing exceptions. Exceptions are used to indicate that an error has occurred while running a program.
Read more >
throw - JavaScript - MDN Web Docs - Mozilla
You can specify an object when you throw an exception. You can then reference the object's properties in the catch block.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found