Repository navigation
ENH: improve error message for ragged-array creation failure - #13913
Conversation
seberg
left a comment
There was a problem hiding this comment.
The logic seems right (I cannot see how it can fail), tried with structured dtypes just to be sure. Matti said that the approach to move the check out of this function turned out less nice. So I am in favor as a small but clear improvement at least in some cases. If we add something more broadly can still remove it again.
|
A related effect of this change is that assigning a ragged list (but still of correct number of values) to a slice no longer works, as shown in this example, extracted from Matplotlib's tests: fails with a I wrote a fix for this, but a question did come up for whether this was an intended change? |
|
Oh, I am surprised our tests did not find that, thanks, sounds like I have yo look much closet and possibly revert. |
Fixes #5303, #6584 for the case where
np.arraygets a ragged-sequence input and a dtype is specified. This does not try to fix the case for where no dtype is specified.Previously
np.array([[1], [2, 3]], dtype=int)would emit a "setting an array element with a sequence" message, now changed to "cannot create an array from unequal-length (ragged) sequences". This also is the error for structured dtypes where previously the error was "TypeError: expected a readable buffer object"Test added.