larray-project / larray

N-dimensional labelled arrays in Python
https://larray.readthedocs.io/
GNU General Public License v3.0
8 stars 6 forks source link

setting a single cell with an Array value breaks #1070

Closed gdementen closed 10 months ago

gdementen commented 1 year ago

For size one array, this must be valid. This is a regression in 0.34

gdementen commented 10 months ago

I fixed this in my local copy but I just noticed Numpy 1.25 has the following deprecation warning:

Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)

So I wonder if I shouldn't rather implement a better error message for that case instead of working around Numpy's limitation.

FWIW: here is my test case:

res = ndtest((2, 3))
res['a0', 'b1'] = Array([42], 'dummy=d0')
assert_larray_equal(res, from_string(r"""a\b b0  b1 b2
                                          a0  0  42  2
                                          a1  3   4  5"""))

On the other hand, we (and numpy!) accept extra size-one dimensions when the target is not a scalar, so it does not seem out of place to accept that for the scalar case too. For example, this is valid code:

arr = ndtest(3)
arr[:'a1'] = ndtest((2, 1)) * 10
# this works too (pure numpy)
arr = np.array([1, 2, 3])
arr[:2] = np.array([[5, 6]])

@alixdamman : what do you think?

gdementen commented 10 months ago

In the end, I decided to wontfix this. I don't see a strong reason to deviate from numpy. If anybody has a strong feeling about this, I could be convinced otherwise though.