> Ewww, kinda wish that would be an error... It would be too easy for a
> typo to get accepted this way.
> On Wed, Dec 26, 2018 at 1:59 AM Eric Wieser
> <[hidden email] <mailto:wieser.eric%[hidden email]>>
> In the latest version of numpy, this runs without an error,
> although may or may not be what you want:
> |In : np.array([[1,2],[[1,2],[3,4]]]) Out: array([[1, 2],
> [list([1, 2]), list([3, 4])]], dtype=object) |
> Here the result is a 2x2 array, where some elements are numbers
> and others are lists.
Specify the dtype explicitly: `dtype=int` or so, then NumPy will refuse
to create a ragged array.
There has been occasional discussion of `dtype='not-object'`, but I
don't think it resulted in an issue or PR.
The rationale for the change allowing that construction was twofold: it's easier to understand what has gone wrong when seeing the `list`s in the repr than it was from the cryptic error message; and there were some jagged cases that already succeeded in this way, and it was less confusing to be consistent.
I agree that the behavior is not terribly useful, and object arrays constructed containing lists are quite possibly something we should warn about.