As discovered in #7259 and #7260, string- and unicode- numpy scalars do not support indexing with an empty tuple, unlike other scalars:
>>> numpy.string_("ABC")[()]
TypeError: string indices must be integers, not tuple
>>> numpy.int32(1)[()]
1
This may be a problem because indexing with an empty tuple is a way of converting possible 0-d arrays to scalars:
>>> a = numpy.int64(1)
>>> b = numpy.array(a)
>>> type(a[()]), type(b[()])
(numpy.int64, numpy.int64)
As of writing this it's not 100% clear to me we actually want this. It could be that instead of just writing
we should encourage people to write something like
if isinstance(possiblearr, ndarray):
return possiblearr[()]
return possiblearr
But, on the other hand it's probably a good idea for all scalar types to behave similarly. I made a rough outline for a fix in a comment in #7260.
As discovered in #7259 and #7260, string- and unicode- numpy scalars do not support indexing with an empty tuple, unlike other scalars:
This may be a problem because indexing with an empty tuple is a way of converting possible 0-d arrays to scalars:
As of writing this it's not 100% clear to me we actually want this. It could be that instead of just writing
we should encourage people to write something like
But, on the other hand it's probably a good idea for all scalar types to behave similarly. I made a rough outline for a fix in a comment in #7260.