Exceptions when creating an array that has an object
See original GitHub issueI noticed two issues:
- 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.
- This is a related problem to item 1. zarr essentially only supports fill-values of
Nonefor 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:
- Created 2 years ago
- Comments:9 (9 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks @joshmoore !
Thanks for the quick reply @joshmoore!
Where do I pass in
data=? I don’t see it as an argument toGroup.create. If I simply pass it intofoo.createthen I get back the same error as before:Quick note: I fixed up the second reproducer I had above. I had a copy paste error that I didn’t notice before.