PolyData is not hashable anymore
See original GitHub issueDescribe the bug, what’s wrong, and what you expect:
I use pyvista to visulize FE-Results. Therefore I create shapes (PolyData-Objects) and store them to interact later with them. I used dictionarys to store relations between my shapes and other Instancecs, like the corresponding Actor. Since version 0.32 the PolyData object is not hashable anymore and I can not use them as keys. Is this a feature or a bug? I can’t elaborate which change exactly cause this issue.
A clear and concise description of what you expected to happen. I expect the Polydata object able to be used as key for a dictionary.
To Reproduce
Please include a code snippet to reproduce the bug in the block below:
import pyvista as pv
shape = pv.PolyData([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]])
a = {shape, 'a'}
TypeError: unhashable type: 'PolyData'
System Information: Please run the following code wherever you are experiencing the bug and paste the output below. This report helps us track down bugs and it is critical to addressing your bug:
# Get system info
import pyvista as pv
print(pv.Report())
--------------------------------------------------------------------------------
Date: Tue Oct 26 14:08:36 2021 Mitteleuropäische Sommerzeit
OS : Windows
CPU(s) : 8
Machine : AMD64
Architecture : 64bit
RAM : 15.9 GiB
Environment : IPython
GPU Vendor : Intel
GPU Renderer : Intel(R) HD Graphics 4600
GPU Version : 4.3.0 - Build 20.19.15.5063
Python 3.7.10 | packaged by conda-forge | (default, Oct 5 2021, 16:32:37)
[MSC v.1916 64 bit (AMD64)]
pyvista : 0.32.1
vtk : 9.0.3
numpy : 1.20.3
imageio : 2.9.0
appdirs : 1.4.4
scooby : 0.5.7
meshio : 4.4.6
matplotlib : 3.4.3
pyvistaqt : 0.5.0
PyQt5 : 5.15.4
IPython : 7.28.0
scipy : 1.7.1
--------------------------------------------------------------------------------
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (9 by maintainers)
Interesting discussion.
Agree with @adeak, a hash should be only for immutable objects and a pyvista DataSet is absolutely mutable.
I’d recommend using the
==
operator until we implement apyvista.allclose
.I like the idea of a separate
pyvista.allclose
function to be used when we want to check for almost equality, but not as the equality comparison.