catalystneuro / roiextractors

Python-based module for extracting from, converting between, and handling optical imaging data from several file formats. Inspired by SpikeInterface.
https://roiextractors.readthedocs.io/en/latest/index.html
BSD 3-Clause "New" or "Revised" License
11 stars 7 forks source link

fix inscopix dtype #326

Closed bendichter closed 3 months ago

bendichter commented 3 months ago

Apparently np.uint16 is different from np.dtype(np.uint16)

CodyCBakerPhD commented 3 months ago

Specifically seems that if you ever see numpy.uint16 it's from taking the type instead of the .dtype of an array element or numpy scalar;

array = np.array([1,2,3], dtype="uint16")
type(array[0])
> np.uint16

array[0].dtype
> dtype('uint16')
CodyCBakerPhD commented 3 months ago

Is there a test to add or fix (doesn't look like changing this line in source altered the outcome of a test?) for this

bendichter commented 3 months ago

Unfortunately,

np.uint16 == np.dtype(np.uint16)
True

however

np.uint16.itemsize()
TypeError: 'getset_descriptor' object is not callable

while

np.dtype(np.uint16).itemsize
2

I suppose I could test asking for the itemsize

CodyCBakerPhD commented 3 months ago

Unfortunately,

np.uint16 == np.dtype(np.uint16)

I believe this might be intended since equality is somewhat looser than saying each side of the expression should be of the same object type (with same methods/attributes, etc)

I think the correct assertion would instead be

assert extractor.get_dtype() is np.dtype("uint16")
bendichter commented 3 months ago

@CodyCBakerPhD good point. I changed it to is and it works. You are right, is should be more restrictive