Handle edge cases in linspace() for num < 2#98
Closed
leofernandezg wants to merge 1 commit intocdelker:masterfrom
Closed
Handle edge cases in linspace() for num < 2#98leofernandezg wants to merge 1 commit intocdelker:masterfrom
leofernandezg wants to merge 1 commit intocdelker:masterfrom
Conversation
linspace(start, stop, num=1) raised ZeroDivisionError because step = (stop - start) / (num - 1) divides by zero when num is 1. Return [start] when num=1 and [] when num=0, consistent with numpy.linspace behavior. Added test/test_linspace.py. Fixes cdelker#93
Author
Test suite resultsFull test suite (
The 38 pre-existing failures are in |
Author
|
Update: Re-ran the full test suite with all optional dependencies installed (matplotlib, ziamath, pyparsing).
No regressions introduced. |
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.
Summary
ZeroDivisionErrorwhen callinglinspace()withnum=1Problem
linspace(start, stop, num=1)computesstep = (stop - start) / (num - 1), which divides by zero. This function is used internally byroundcorners()andSegmentArc.get_bbox().Changes
schemdraw/util.py: Return[start]whennum=1and[]whennum=0, consistent withnumpy.linspacebehaviortest/test_linspace.py: New test file coveringnum=0,num=1,num=2, and default casesTest results
Without fix:
test_linspace_num_1fails withZeroDivisionErrorWith fix: all 4 tests pass
Fixes #93