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.

in operator with dtype and set does not work as expected

See original GitHub issue

When testing if the dtype of an array is present in a set of dtypes, the answer is unexpected.

Reproducing code example:

import numpy as np
f32_dtype = np.zeros(1, dtype=np.float32).dtype

# test with list of dtypes
print(f32_dtype in [np.float32, np.uint8])  # => True (as expected)

# test with set of dtypes
print(f32_dtype in {np.float32, np.uint8})  # => False (not as expected)

Error message:

none

Numpy/Python version information:

numpy 1.18.4 Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
eric-wiesercommented, May 11, 2020

Agreed that this is a bit unpleasant - we might be able to adjust dtype.__hash__ to fix this.

0reactions
sebergcommented, Feb 24, 2021

Going to close this as duplicate of gh-7242.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sorting array of objects by row using custom dtype
In my case, str is a standin for arbitrary objects that support rich comparison. I noted that the sort works perfectly for integers,...
Read more >
Working with text data — pandas 1.5.2 documentation
There are two ways to store text data in pandas: object -dtype NumPy array. StringDtype extension type. We recommend using StringDtype to store...
Read more >
NumPy: Cast ndarray to a specific dtype with astype()
Basically, one dtype is set for one ndarray object, and all elements are of the same data type. This article describes the following ......
Read more >
JAX Errors - JAX documentation - Read the Docs
This error can occur when a JAX Tracer object is used in a context where a Python integer is expected. It typically occurs...
Read more >
pandas/base.py at main · pandas-dev/pandas - arrays - GitHub
The ExtensionArray interface does not impose any rules on how this data. is stored. ... Coercion : Most users will expect basic coercion...
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