Skip to content

Commit 3ed201a

Browse files
committed
PERF: use object.__hash__ for Axis.__hash__ instead of our own __hash__
Given Axis.__hash__ is used *a lot*, this brings a small performance improvement
1 parent 350707d commit 3ed201a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

larray/core/axis.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -877,8 +877,8 @@ def __contains__(self, key):
877877
# TODO: ideally, _to_tick shouldn't be necessary, the __hash__ and __eq__ of Group should include this
878878
return _to_tick(key) in self._mapping
879879

880-
def __hash__(self):
881-
return id(self)
880+
# use the default hash. We have to specify it explicitly because we define __eq__
881+
__hash__ = object.__hash__
882882

883883
def _is_key_type_compatible(self, key):
884884
key_kind = np.dtype(type(key)).kind
@@ -3643,9 +3643,9 @@ def evaluate(self, context):
36433643
"""
36443644
return context[self.name]
36453645

3646-
# needed because ExprNode.__hash__ (which is object.__hash__) takes precedence over Axis.__hash__
3647-
def __hash__(self):
3648-
return id(self)
3646+
# Use the default hash. We have to specify it explicitly because we define __eq__ via ExprNode and
3647+
# ExprNode.__hash__ (which is not set explicitly) takes precedence over Axis.__hash__
3648+
__hash__ = object.__hash__
36493649

36503650

36513651
class AxisReferenceFactory(object):

0 commit comments

Comments
 (0)