Skip to content

Commit

Permalink
BUG: Set __hash__ = None for non-hashable classes.
Browse files Browse the repository at this point in the history
Because neither poly1d nor the Polynomial package polynomial classes are
immutable, hence not reliably hashable, they should signal that by
setting __hash__ = None. This also fixes the warning

Overriding __eq__ blocks inheritance of __hash__ in 3.x

that is given when the command `python2.7 -3 -c"import numpy"` is run.
  • Loading branch information
charris committed Aug 28, 2013
1 parent bec793a commit e2675e3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions numpy/lib/polynomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,8 @@ class poly1d(object):
coeffs = None
order = None
variable = None
__hash__ = None

def __init__(self, c_or_r, r=0, variable=None):
if isinstance(c_or_r, poly1d):
for key in c_or_r.__dict__.keys():
Expand Down
2 changes: 2 additions & 0 deletions numpy/polynomial/polytemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class $name(pu.PolyBase) :
window = np.array($domain)
# Don't let participate in array operations. Value doesn't matter.
__array_priority__ = 1000
# Not hashable
__hash__ = None
def has_samecoef(self, other):
"""Check if coefficients match.
Expand Down

0 comments on commit e2675e3

Please sign in to comment.