Repository navigation
Honor the step given in get_riemann_rectangles' x_range - #2532
Open
NgoQuocViet2001 wants to merge 1 commit into
Open
NgoQuocViet2001 wants to merge 1 commit into
NgoQuocViet2001 wants to merge 1 commit into
Conversation
np.arange steps by x_range[2], so nudging the upper bound to include the requested right endpoint takes one of those steps. The code nudged by dx instead, which on the three-element path is the axis default rather than the step the caller asked for -- x_range=[0, 2, 0.5] on a default Axes drew five rectangles, the last spanning 2.0 to 2.5, entirely outside the range. The same line also wrote to the caller's own sequence, so [0, 2, 0.5] came back as [0, 3.0, 0.5] and a second call drifted further. Copy it first. Two-element x_range is unaffected: dx is appended as x_range[2] there, so the two nudges are the same value.
This branch has not been deployed
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.
Motivation
get_riemann_rectanglesaccepts a three-elementx_rangeso the caller can choose the sampling step — that is what theif len(x_range) < 3branch normalises away. On that path two things go wrong in one line:np.arangesteps byx_range[2], so reaching the requested right endpoint takes exactly one of those steps. The nudge usesdx, which on the three-element path was never set fromx_range— it isself.x_range[2], the axis default.The same line writes into the sequence the caller passed in. The two-element path builds a new list, so only the three-element path mutates the caller's object.
Measured on
masterwithAxes()(defaultx_range(-8, 8, 1.0)):The last rectangle sits entirely outside the requested range, so the drawn area is wrong, and a second call with the same list drifts further because the bound has already been raised.
Proposed changes
x_rangebefore writing to it.x_range[2], the step actually being sampled.Two-element
x_rangeis byte-identical:dxis appended asx_range[2]there, so the two nudges are the same number.Test
Two cases added to the existing
tests/test_coordinate_systems.py— one asserting four rectangles ending at 2.0, one asserting the caller's list is unchanged.Result: 8 passed. On
masterboth new tests fail — five rectangles, and[0, 3.0, 0.5]where[0, 2, 0.5]is expected.