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.

Masked is unhashable

See original GitHub issue

Description

Masked classes are unhashable.

Expected behavior

It is washable, like the unmasked version.

Actual behavior

hash(X) returns a TypeError because it is unhashable.

Steps to Reproduce

from astropy import units as u
from astropy.utils.masked import Masked
MQ = Masked(u.Quantity)
hash(MQ(2 * u.km))  # raises TypeError

System Details

macOS-10.16-x86_64-i386-64bit Python 3.8.2 | packaged by conda-forge | (default, Apr 24 2020, 07:56:27) [Clang 9.0.1 ] Numpy 1.18.4 astropy 4.3.dev1486+gddc6fb76f.d20210505 Scipy 1.4.1 Matplotlib 3.4.1

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
mhvkcommented, May 6, 2021

@nstarman - only Quantity scalars are hashable, which is to have an analogy with the np.float64 scalars, etc. (even though the analogy is not perfect, since with a scalar length quantity q += 1*u.cm changes the object in-place, while the equivalent for a numpy scalar creates a new object). For the masked class, having a hashable object makes even less sense, I think, since the mask itself is very explicitly meant to be mutable.

0reactions
mhvkcommented, May 6, 2021

I checked and neither np.ma.masked, nor a scalar np.ma.MaskedArray are hashable. Since the problem that triggered this issue is unrelated, I’ll close this for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should np.ma.masked be hashable? · Issue #4660 - GitHub
ma.masked should not be hashable. It is an instance of MaskedConstant , which strongly implies that it is not mutable (even if it...
Read more >
How to overcome TypeError: unhashable type: 'list' [duplicate]
I know that keys in a dictionary can't be lists but I'm trying to make my value into a list not the key....
Read more >
MASH Error - unhashable type: 'list' # - Maya - Autodesk Forums
The error says that you try to use a list as dictionary key, you'll have to change your list into tuples if you...
Read more >
How to Handle Unhashable Type List Exceptions in Python
Unhashable type errors appear in a Python program when a data type that is not hashable is used in code that requires hashable...
Read more >
typeerror: unhashable type: 'series' - You.com | The Search ...
_cols[col_name][mask] = col 380 --> 381 elif name in self._cols: 382 self._cols[name] = self._prepare_series_for_add(col) 383 else: TypeError: unhashable ...
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