Skip to content

Commit b204f9e

Browse files
committed
fix: Allow numpy arrays to treat PaddedInt like int
If an exception is raised by `val == self.sval or ...` (that is, `val.__eq__(self.sval).__bool__()`), we defer to the `val` type to determine the correct behavior. This is currently only expected to be triggered by array-like types, but any type that goes this far out of its way to change its boolean behavior is one we don't want to get too fancy with. In the spirit of not getting fancy, we drop any consideration of the padded string in this context.
1 parent 1ce0bf8 commit b204f9e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/bids/layout/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ def __init__(self, val):
6565
self.sval = str(val)
6666

6767
def __eq__(self, val):
68-
return val == self.sval or super().__eq__(val)
68+
try:
69+
return val == self.sval or super().__eq__(val)
70+
except ValueError:
71+
# `or` triggers `__bool__`. If this fails, it is almost
72+
# certainly an array type. Do not attempt string comparisons
73+
# and allow val to determine the return type
74+
return val == self
6975

7076
def __str__(self):
7177
return self.sval

0 commit comments

Comments
 (0)