Masked is unhashable
See original GitHub issueDescription
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:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top 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 >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 FreeTop 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
Top GitHub Comments
@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 quantityq += 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.I checked and neither
np.ma.masked
, nor a scalarnp.ma.MaskedArray
are hashable. Since the problem that triggered this issue is unrelated, I’ll close this for now.