Skip to content

Volume dtype restriction#410

Open
mccle wants to merge 4 commits into
v0.28.0devfrom
volume_dtype_restriction
Open

Volume dtype restriction#410
mccle wants to merge 4 commits into
v0.28.0devfrom
volume_dtype_restriction

Conversation

@mccle
Copy link
Copy Markdown
Collaborator

@mccle mccle commented May 18, 2026

Added checks to the volume init and setter methods to ensure volumes have float, integer, or bool types. A new test was added to verify that volumes cannot be instantiated with an array of an unsupported data type nor changed after instantiation to a new data type that is unsupported.

@mccle mccle requested a review from CPBridge May 18, 2026 18:10
Copy link
Copy Markdown
Collaborator

@CPBridge CPBridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of minor suggestions

Comment thread src/highdicom/volume.py
Comment on lines +2512 to +2513
"Argument 'array' must have a dtype of float, integer,"
f" or bool, received '{array.dtype}'."
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suggests that the dtype must be one of these options exactly. How about:

Suggested change
"Argument 'array' must have a dtype of float, integer,"
f" or bool, received '{array.dtype}'."
"Argument 'array' must have an integer, floating point, "
f" or boolean dtype, received '{array.dtype}'."

Comment thread src/highdicom/volume.py Outdated
Comment thread tests/test_volume.py
Comment on lines +1386 to +1400
for disallowed_dtype in [
np.complex64,
complex,
np.complex128,
np.complex256,
str
]:
with pytest.raises(
ValueError,
match=(
"Array must have a dtype of float, integer,"
" or bool, received"
)
):
volume.array = np.zeros((10, 10, 10), dtype=disallowed_dtype)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this test? Isn't it the same regardless of dtype, and therefore run loads of times unnecessarily?

Would it be cleaner to have two tests: one for valid dtypes and the other for invalid dtypes?

Co-authored-by: Chris Bridge <chrisbridge44@googlemail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants