rsenk330/python-quantities — comment on commit f83caa3d7ae32effe41530ce24357b69f1a3c987
File:  line 0
By hgrecco:

This hash function is not good because different ndarrays with the same representation will yield the same hash. This appears in at least two cases:
1.- when the displayed precision is not enough to account for the difference between two numbers
2.- when the shape of the array is big so that the string representation contains "..." to indicate non displayed rows

Additionally, different Quantities can actually be the same. For example:
Quantity(60, 'km/h') and Quantity(1, 'km/min')

I think a better hash will be something like:

def __hash__(self):
simp = self.simplified
return hash((simp.magnitude.tostring(), str(simp.units)))

It is still not perfect as the same number with different *dtypes* will yield different hashes. Maybe better will be

def __hash__(self):
simp = self.simplified
return hash((numpy.asarray(simp.magnitude, dtype=numpy.float64).tostring(), str(simp.units)))

I am not sure if it is bullet proof and if is fast enough.

But I would really like to see a __hash__ for quantities.