Unexpected compound datatype construction
See original GitHub issueWhen constructing compound types giving a tuple of tuples, instead of a list of tuples as is common in docs, leads to unexpected results.
Reproducing code example:
import numpy as np
print(np.__version__)
print()
dts = [
[('int',int), ('float',float)],
(('int',int), ('float',float))
]
for dt in dts:
print(dt)
print(np.dtype(dt))
print(np.full(5, 10, dtype=dt))
print()
On my system this is producing:
1.18.1 3.6.5 (default, Jun 17 2018, 12:13:06)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)]
[('int', <class 'int'>), ('float', <class 'float'>)]
[('int', '<i8'), ('float', '<f8')]
[(10, 10.) (10, 10.) (10, 10.) (10, 10.) (10, 10.)]
(('int', <class 'int'>), ('float', <class 'float'>))
int64
[10 10 10 10 10]```
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Nested compound datatypes in HDF5 - c++ - Stack Overflow
In the first pass, I gather layout information and build a compound datatype and a dataset. I then make a second pass over...
Read more >Add built-in support to write compound data types #1013
My preference would be to extend HDF5.datatype to work on arbitrary structs and named tuples so that we can just use the normal...
Read more >SML/NJ Error Messages
This error occurs when type constructors with incompatible equality properties are equated by sharing constraints. When this happens, the signature is not ...
Read more >1.2 Built-in Types of Data - Introduction to Programming in Java
A data type is a set of values and a set of operations defined on them. ... A physics student gets unexpected results...
Read more >Compound data type - Rosetta Code
Task Create a compound data type: Point(x,y) A compound data type is one that holds multiple independent values. Related task Enumeration ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks for the time spent chasing this down @seberg. An approach along the lines you proposed + additional tests seems like a good approach (+ some extra time for fully grokking the change to the logic 😃 ).
I’d also advocate adding an additional example to the doc string to highlight the “special” behavior of len-2 tuples for specifying dtypes.
I think we should do that. Not limiting user datatypes would be possible, but I am currently not sure what the point of an
int64+ fields is. You are going to lose that extra informtion in ufuncs, etc. anyway typically. So it seems to me that basicviewor a maybe a newuniondtype/structured dtype with overlapping fields makes more sense. In other words: Rather than not restricting user dtypes as I did above, I would prefer to think about deprecating the whole thing unless someone finds a good use-case. It seems way too smart to me.