-
Notifications
You must be signed in to change notification settings - Fork 648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AtomGroups are not hashable on python 3 #1397
Comments
Looks good.
We shouldn't use |
@jbarnoud if you want, you can add a knownfailure test and merge that, then @tylerjereddy or I will make sure that this passes for py3 |
@richardjgowers I have a PR almost ready. |
Groups (AtomGroup, ResidueGroup, SegmentGroup) cannot be stored in sets or used as dict key if they are not hashable. In python 3, the __hash__ method is not defined implicitly anymore when a class has a __eq__ method. Fixes #1397
Groups (AtomGroup, ResidueGroup, SegmentGroup) cannot be stored in sets or used as dict key if they are not hashable. In python 3, the __hash__ method is not defined implicitly anymore when a class has a __eq__ method. Fixes #1397
Groups (AtomGroup, ResidueGroup, SegmentGroup) cannot be stored in sets or used as dict key if they are not hashable. In python 3, the __hash__ method is not defined implicitly anymore when a class has a __eq__ method. Fixes #1397
Groups (AtomGroup, ResidueGroup, SegmentGroup) cannot be stored in sets or used as dict key if they are not hashable. In python 3, the __hash__ method is not defined implicitly anymore when a class has a __eq__ method. Fixes #1397
- Explicitly define __hash__ for groups: Groups (AtomGroup, ResidueGroup, SegmentGroup) cannot be stored in sets or used as dict key if they are not hashable. In python 3, the hash method is not defined implicitly anymore when a class has a eq method. - fixes #1397
Expected behaviour
An
AtomGroup
is hashable, it can therefore be placed in aset
or as a dictionary key.topologyattr.Bonds.fragments
, that creates a set ofAtomGroups
, works as intended.Actual behaviour
Attempting to get the hash of an
AtomGroup
on python 3 raises the following error:It works on python 2.
In python 3, a class that defines
__eq__
but not__hash__
has__hash__
set toNone
, see https://docs.python.org/3/reference/datamodel.html#object.__hash__. So we should define a__hash__
method for theGroupBase
class. I think this method could look like:Code to reproduce the behaviour
Currently version of MDAnalysis:
(run
python -c "import MDAnalysis as mda; print(mda.__version__)"
)'0.16.2-dev0' (7652710)
The text was updated successfully, but these errors were encountered: