Inconsistency in behaviour between numpy.ndarray and ZBigArray
Hello,
I encountered an unexpected behavior when using wendelin.bigarray.array_zodb.ZBigArray.
When initializing a ZBigArray by using a list for the shape parameter, the append method will raise an error:
>>> from wendelin.bigarray.array_zodb import ZBigArray
>>> zbig_array = ZBigArray(shape=[1], dtype=float)
>>> zbig_array.append([1])
ValueError: all the input array dimensions except for theconcatenation axis must match exactly
It will raise this error because it will come to [] != () here:
zbig_array.shape returns a list, but the shape property of the adhoc created array which is supposed to be appended returns a tuple.
It's fair to say this is actually an users error, because the numpy documentation clearly specifies the shape parameter as a tuple of ints.
Nevertheless recent versions of numpy.ndarray still do accept a list as a valid input of shape:
>>> import numpy
>>> numpy.__version__
1.23.1
>>> numpy.ndarray(shape=[2]).shape
(2,)
>>> numpy.ndarray(shape=[2]).shape == numpy.ndarray(shape=(2,)).shape
True
What is the preferred way how to handle this difference in behavior between numpy.ndarray and wendelin.bigarray.array_zodb.ZBigArray?
I've thought about:
-
Simply wrapping
shapeinto atuplecall here (e.g.self._shape = tuple(shape)). -
Somehow improve the error message. It's perhaps not a big deal, but it can be confusing and time-consuming when encountering the described
appendscenario with the badshapeparameter.
Best, Levin
/cc @kirr