bioio-devs / bioio-base

Typing, base classes, and more for BioIO projects.
https://bioio-devs.github.io/bioio-base/
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Clearer error message if incorrect type is passed to get_image_dask_data #17

Closed pgarrison closed 4 months ago

pgarrison commented 5 months ago

Issue

I wrote some incorrect code that was a little hard to debug because the error message lacked detail.

Simplified example

time = foo()  # returns 4
channel = bar()  # returns None
reader.get_image_dask_data("ZYX", T=time, C=channel)

The current error message: TypeError: '>' not supported between instances of 'NoneType' and 'int'

Changes

Implementation notes

We're checking against Integral instead of int because Integral is more general, including numpy integers, for example.

Testing

I ran the following script. I didn't add a unit test because the error class (TypeError) remains the same.

from bioio_base.transforms import reshape_data
import numpy as np

reshape_data(np.zeros(( 40, 40, 40, 40, 40 )), "CTZYX", "XYZ", T=np.int64(4), C=0)
reshape_data(np.zeros(( 40, 40, 40, 40, 40 )), "CTZYX", "XYZ", T=np.int64(4), C=None)
toloudis commented 4 months ago

Looks like lint is failing because line too long