Skip to content

Commit

Permalink
add extra tests for non-numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
blakedewey committed Jul 6, 2024
1 parent 111d1e2 commit c1cc856
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/torchio/transforms/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ def to_range(n, around):

def parse_params(self, params, around, name, make_ranges=True, **kwargs):
params = to_tuple(params)
if make_ranges and any(isinstance(p, (str, bytes)) for p in params):
message = (
f'"{name}" must be a number or a sequence of numbers for'
f' make_ranges=True, not {params}'
)
raise ValueError(message)
# d or (a, b)
if len(params) == 1 or (len(params) == 2 and make_ranges):
params *= 3 # (d, d, d) or (a, b, a, b, a, b)
Expand Down
2 changes: 1 addition & 1 deletion src/torchio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def guess_external_viewer() -> Optional[Path]:
def parse_spatial_shape(shape):
result = to_tuple(shape, length=3)
for n in result:
if n < 1 or n % 1:
if isinstance(n, (str, bytes)) or n < 1 or n % 1:
message = (
'All elements in a spatial shape must be positive integers,'
f' but the following shape was passed: {shape}'
Expand Down

0 comments on commit c1cc856

Please sign in to comment.