question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected compound datatype construction

See original GitHub issue

When 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:open
  • Created 4 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rossbarcommented, Feb 25, 2020

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.

0reactions
sebergcommented, Feb 25, 2020

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 basic view or a maybe a new union dtype/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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found