-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix overflow of Plexon in numpy 2.0 #1613
Conversation
@h-mayorquin merge conflict from #1612. |
Solved. |
Cool. I'll double check this weekend :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One strategy question @h-mayorquin :)
@@ -209,6 +209,10 @@ def _parse_header(self): | |||
for index, pos in enumerate(positions): | |||
bl_header = data[pos : pos + 16].view(DataBlockHeader)[0] | |||
|
|||
# To avoid overflow errors when doing arithmetic operations on numpy scalars | |||
np_scalar_to_python_scalar = lambda x: x.item() if isinstance(x, np.generic) else x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason not to make this lambda function near the top so it is reusable. Or even define this as a true private function. How are you thinking about using the same lambda function twice being generated in the for loop. It should be relatively low cost although seems a bit of a waste no? We could define the function once and reuse in both the for loops, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured you'd have checked. Fair enough. :)
neo/rawio/plexonrawio.py
Outdated
channel_headers = slowChannelHeaders[chan_index] | ||
|
||
# To avoid overflow errors when doing arithmetic operations on numpy scalars | ||
np_scalar_to_python_scalar = lambda x: x.item() if isinstance(x, np.generic) else x | ||
channel_headers = {key: np_scalar_to_python_scalar(channel_headers[key]) for key in channel_headers.dtype.names} | ||
|
||
name = channel_headers["Name"].decode("utf8") | ||
chan_id = channel_headers["Channel"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last question.
so below you called it dsp_channel_headers which was really nice. Any interest in changing this to slow_channel_headers
, just so we make sure we never accidentally overwrite any variable. I think the explicit makes it cleaner and since we are already fixing up the variable naming might be worth the push?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sure.
@@ -209,6 +209,10 @@ def _parse_header(self): | |||
for index, pos in enumerate(positions): | |||
bl_header = data[pos : pos + 16].view(DataBlockHeader)[0] | |||
|
|||
# To avoid overflow errors when doing arithmetic operations on numpy scalars | |||
np_scalar_to_python_scalar = lambda x: x.item() if isinstance(x, np.generic) else x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured you'd have checked. Fair enough. :)
This should fix the errors in #1612.
At least for Plexon.