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

Encoding and Decoding Compound Arrays Does not work with JSON Encoder/Decoder #518

Open
mavaylon1 opened this issue Apr 3, 2024 · 2 comments
Labels

Comments

@mavaylon1
Copy link

I currently use the pickle encoder and decoder; however, I've been requested to have the encoding/decoding process be doable through JSON encoder/decoder.

When dealing with compound structures, i.e., structured arrays, I run into a dimension issue. Below reproduces the issue. Is this structure supported and if so is there something I need to change so that the input item is in a specific format?

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

import numcodecs
import numpy as np


item = np.array([(1, 'dataset_1', {'source': '.', 'path': '/dataset_1', 'object_id': None, 'source_object_id': None}),
       (2, 'dataset_2', {'source': '.', 'path': '/dataset_2', 'object_id': None, 'source_object_id': None})],
      dtype=[('id', '<i4'), ('name', 'O'), ('reference', 'O')])
cs = numcodecs.JSON()

en = cs.encode(item)
out=cs.decode(en)

This returns:

 File "~./json.py", line 75, in decode
    dec[:] = items[:-2]
    ~~~^^^
ValueError: setting an array element with a sequence. The requested array would exceed the maximum number of dimension of 1.

Version and installation information

  • numcodecs: the dev branch via git clone and pip install -e .
  • mac OS
  • python 3.11
@mavaylon1
Copy link
Author

Any ideas?

@martindurant
Copy link
Member

The trouble is this line: https://github.com/zarr-developers/numcodecs/blob/main/numcodecs/json.py#L62

buf.dtype.str

is '|V20', for a dtype [('id', '<i4'), ('name', 'O'), ('reference', 'O')]. We should be encoding the complex type.

@dstansby dstansby added the bug label Aug 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants