Raise the intended error for a zero sampling_period in instantaneous_rate - #710
Open
adityasingh2400 wants to merge 1 commit into
Open
Conversation
A sampling_period of exactly zero passed the 'sampling_period.magnitude < 0' guard and reached the bin-count computation, where dividing the recording duration by zero produced infinity and int() raised OverflowError: cannot convert float infinity to integer. The docstring already documents the intended contract, it lists a sampling_period that is 'not larger than zero' under Raises, so only the guard was wrong. Widen it to '<= 0' and raise the informative ValueError instead. The Raises section now lists that case under ValueError, which is the class the function actually raises for a negative sampling period.
Author
|
The The sphinx build dies executing a notebook that downloads sample data, this time with Counting across the four PRs, that fetch has now failed five different ways in roughly two hours: certificate verification, 403, connection reset, timeout, and now another timeout. @CozySocksAlways mentioned on #708 they were going to look into the docs side, so flagging it here for the same reason. |
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
instantaneous_rateaccepts asampling_periodof exactly zero and then dies deep inside the bin count computation with an error that says nothing about the argument that caused it.On current master:
The documented contract is already correct, only the validation is wrong. The
Raisessection ofinstantaneous_ratesays:"not larger than zero" includes zero, but the guard only rejects negative values, so zero slips through, the duration divided by zero is infinity, and
int()raisesOverflowError. This widens the guard to<= 0and reports the intended message, so the same script now ends withValueError: The 'sampling_period' (0.0 ms) must be larger than zero.The
Raisessection is also made self consistent. It listed the zero case underTypeErrorand a separate "smaller than zero" case underValueError, while the function has always raisedValueErrorhere. The single bullet now sits underValueErrorand reads "not larger than zero", which is both the documented contract and what the code does.test_instantaneous_rate_errorsgains two cases, a single spike train and a list of spike trains, both withsampling_period=0, asserting theValueErrormessage. Revertingstatistics.pyto master makes it fail with theOverflowErrorabove. After, 101 passed, 1 skipped and 33 subtests passed.pycodestylereports no new findings on either changed file.Unrelated but noticed in the same module while reading:
cv2,lvandlvrall documentwith_nanasDefault: Truewhile their signatures usewith_nan=False. Happy to send that as a separate docs only change if it is wanted.Disclosure: this change was prepared with AI assistance. I have reviewed and tested it.