Closed thouis closed 11 years ago
atmention:FrancescAlted wrote on 2006-09-27
As an aside, I'd say that the error raised should be a !ValueError (i.e. a la numarray) and not a !TypeError, but this is subject to interpretation, of course.
atmention:teoliphant wrote on 2006-09-27
I'll look into it. The strings problem we can hopefully fix. The other error is raised from a different location than the sequence conversion code. It may be harder to "fix"
atmention:teoliphant wrote on 2006-09-27
I've changed string and unicode getitems so that sequences are not allowed (unless they are strings or unicode sequences. Previously str(obj) and unicode(obj) were being called on the object being set. If this was a sequence, then the stringified sequence was used without difficulty.
The array from sequence code basically looks like
#
So, a 1-d loop is used and the setitem is used of new with the getitem of obj to construct the result. If there is a mismatch in the level of nesting this is not caught until the attempt at setting doesn't work.
All error messages have been changed for the problem trying to set an array element with a sequence to "setting an array element with a sequence". It is still a type-error. For strings and unicode arrays, strings and unicode "sequences" are of course allowed.
Original ticket http://projects.scipy.org/numpy/ticket/297 on 2006-09-27 by atmention:FrancescAlted, assigned to unknown.
!NumPy is not detecting string nested sequence with different lengths:
numarray does:
and I think this last message is quite adequate for the issue.
Furthermore, I'd say that a message like numarray is better for numerical nested sequences with different lengths.
NumPy:
numarray: