Skip to content

Volume dtype restriction#410

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

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

Conversation

@mccle

@mccle mccle commented May 18, 2026

Copy link
Copy Markdown
Collaborator

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

@CPBridge CPBridge left a comment

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.

A couple of minor suggestions

Comment thread src/highdicom/volume.py Outdated
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 Outdated
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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Assuming that the starting dtype is unimportant for array reassignment, it should be safe to avoid nesting them. I have split them into separate tests for the init dtypes and for the reassign dtypes.

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