You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice if a structured-stype constructor taking **kwargs was available, ie.
np.dtype(foo=int, bar=(float, 2))
being equivalent to
np.dtype([("foo", int), ("bar", float, 2)])
the latter being quite a mouthful to type (I realize that this can be made into a one-line helper function too..).
It is true that further overloading the (already very overloaded) np.dtype constructor results in an ambiguity, because the following is currently legal:
In [1]: np.dtype(dtype=np.uint16)
Out[1]: dtype('uint16')
(even though the docs say that the first argument is named "obj" -- but it's actually named "dtype"...)
However, I think it would make sense to make the first argument (when used in that semantic) positional only, so that (after some deprecation period) np.dtype(dtype=np.uint16) means np.dtype([("dtype", np.uint16)]).
Obviously, if there are no fields named "dtype", there is no ambiguity even as of now.
Numpy/Python version information:
1.16.3 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0]
The text was updated successfully, but these errors were encountered:
I would be very against adding more overloads to the dtype constructor, it has too many overloads already. A different helper function or static factory function might be fine though. Elsewhere I show how to declare structured types using class syntax
Note also that your proposed syntax results in a non-deterministic field order until python 3.6
That's definitely intended for Py3.6+ (I'm fine with waiting until numpy only supports Py3.6+, it's not really urgent...).
Making this a separate function is fine too.
It would be nice if a structured-stype constructor taking
**kwargs
was available, ie.being equivalent to
the latter being quite a mouthful to type (I realize that this can be made into a one-line helper function too..).
It is true that further overloading the (already very overloaded) np.dtype constructor results in an ambiguity, because the following is currently legal:
(even though the docs say that the first argument is named "obj" -- but it's actually named "dtype"...)
However, I think it would make sense to make the first argument (when used in that semantic) positional only, so that (after some deprecation period)
np.dtype(dtype=np.uint16)
meansnp.dtype([("dtype", np.uint16)])
.Obviously, if there are no fields named "dtype", there is no ambiguity even as of now.
Numpy/Python version information:
1.16.3 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0]
The text was updated successfully, but these errors were encountered: