FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fixes a bug when the source and target run in opposite directions by HGWright · Pull Request #407 · SciTools/python-stratify · GitHub

Fixes a bug when the source and target run in opposite directions - #407

Open
HGWright wants to merge 3 commits into
SciTools:mainfrom
HGWright:r_opposite_dir
Open

Fixes a bug when the source and target run in opposite directions#407
HGWright wants to merge 3 commits into
SciTools:mainfrom
HGWright:r_opposite_dir

Conversation

Copy link
Copy Markdown
Contributor

🚀 Pull Request

Description

Closes #50

This is a replacement PR for #343 that uses a simpler approach to achieve the same goal. In the cases that rising = None we use the first 2 points of the source to determine rising, we then also use the same method for the target. Comparing rising (for the source) to tgt_rising if they do not match, we flip the source and source data on the axis of interpolation.


Comment on lines 115 to +117
def test_wrong_rising_target(self):
r = self.interpolate([2, 1], [1, 2])
assert_array_equal(r, [1, np.inf])
assert_array_equal(r, [0.0, 1.0])

HGWright Feb 18, 2026
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

We know that there are extra steps taking place in this test. But it is not indicative of the simple interpolation of this data, as shown by the example below.

import numpy as np
import stratify

z_targ = np.array([2, 1])

z_source = np.array([1, 2])
data_source = z_source.copy()
out  = stratify.interpolate(z_targ, z_source, data_source)
print(out)

[2. 1.]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Sure. But it doesn't seem appropriate to try and preserve this test, just with a new Known Good Output, right? If I understand correctly, we no longer expect it to be possible to have a 'wrong' rising target - it should always work?

trexfeathers self-assigned this Mar 19, 2026

trexfeathers left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks @HGWright, this seems a pragmatic solution. Some rough edges to deal with though

Comment thread src/stratify/_vinterp.pyx
Comment on lines +645 to +647
tgt_indexer = [slice(None)] * z_target.ndim
tgt_indexer[tgt_axis] = slice(0, 2)
tgt_first_two = z_target[tuple(tgt_indexer)].ravel()[:2]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Is there a reason that this is different logic to the indexing of z_src?

z_src_indexer = [0] * z_src.ndim
z_src_indexer[zp_axis] = slice(0, 2)
src_first_two = z_src[tuple(z_src_indexer)]
rising = src_first_two[0] <= src_first_two[1]

If it's just a matter of taste/style, I would be keen to see the same logic for both. Could even be put into a convenience function.

Comment on lines 115 to +117
def test_wrong_rising_target(self):
r = self.interpolate([2, 1], [1, 2])
assert_array_equal(r, [1, np.inf])
assert_array_equal(r, [0.0, 1.0])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Sure. But it doesn't seem appropriate to try and preserve this test, just with a new Known Good Output, right? If I understand correctly, we no longer expect it to be possible to have a 'wrong' rising target - it should always work?

def test_non_monotonic_coordinate_interp(self):
result = self.interpolate([15, 5, 15.0], [10.0, 20, 0, 20])
assert_array_equal(result, [1, 2, 3])
assert_array_equal(result, [1.0, 1.0, 2.0])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The dtype stuff definitely needs to be sorted out - that's gonna break some user assumptions. Especially since it only affects stuff that goes through the flipping process (am I right?), so the dtype will depend on the direction of the inputs, that doesn't seem right.

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

stratify gives strange results if heights run in opposite directions

2 participants


Back | FazBrowse Home | New Git URL