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

bug: inserting a list into a two-dimensional array does not work as in numpy #421

Open
ombschervister opened this issue Mar 24, 2019 · 2 comments
Labels
help wanted Issue could use help from someone with familiarity on the topic

Comments

@ombschervister
Copy link

ombschervister commented Mar 24, 2019

Numpy supports inserting:

import numpy as np
a = np.array([(1, 2), (2, 3), (3, 4)])
a[0:1] = [5, 6]

Zarr gets an exception:

import zarr
za = zarr.array(a)
za[0:1] = [5, 6]

ValueError: parameter 'value': expected array with shape (1, 2), got (2,)

@ombschervister ombschervister changed the title bug: inserting a list into a two-dimensional array does not work bug: inserting a list into a two-dimensional array does not work as in numpy Mar 24, 2019
@ombschervister
Copy link
Author

For arrays with structured types does not work at all.

Numpy supports inserting:

import numpy as np

t = [('c1', np.int), ('c2', np.float)]
a = np.array([(1, 2.0), (2, 3.0), (3, 4.0)], dtype=t)
a[0] = (4, 5.0)
a[0:1] = [(5, 6.0)]
a[0:2] = [(6, 7.0), (7, 8.0)]

Zarr gets an exception:

import zarr
za = zarr.array(a)
za[0] = (8, 9.0)
za[0:1] = [(5, 6.0)]   # ValueError: parameter 'value': expected array with shape (1,), got (1, 2)
za[0:2] = [(6, 7.0), (7, 8.0)]   # ValueError: parameter 'value': expected array with shape (2,), got (2, 2)

@martindurant
Copy link
Member

How about

za[0:1] = [ [5, 6] ]

The upcasting of the shape (broadcasting) is a special case, perhaps it should be better handled indeed.

@joshmoore joshmoore added the help wanted Issue could use help from someone with familiarity on the topic label Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issue could use help from someone with familiarity on the topic
Projects
None yet
Development

No branches or pull requests

3 participants