[Numpy-discussion] Tuples vs. lists when defining recarrays with array()
Sun Jun 7 20:44:54 CDT 2009
On Sun, Jun 7, 2009 at 4:31 PM, David Warde-Farley<firstname.lastname@example.org> wrote:
> A question was raised on the #scipy IRC earlier today, about the
> behaviour of array() with structured dtypes. After some educated
> guessing I figured out that for record arrays, tuples (rather than
> lists) must be used to indicate atomic elements. What I wondered is
> whether this behaviour is documented anywhere, and does it belong in
> the array() docstring, for example? The docstring currently reads "...
> or any (nested) sequence."
+1 for a clear indication of this fact, as it's rather unusual that a
tuple is OK where a list is not (for typical pythyon APIs) and the
error is *very* obscure. I've been bitten enough times by this that
by now I'm used to it, but I distinctly remember much head scratching
and looking in the wrong places the first time I was hit by this
I don't know if there's a good reason why lists aren't accepted
though, so that instead of documenting an oddity it could just be
cleaned up. Is it not possible for the constructor to duck-type here
a list for a tuple? Maybe there's a good reason, but it feels like a
bit of a wart.
In any case, whether fixing or documenting it, +1 from this side.
More information about the Numpy-discussion