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: Fix interpolate #5624
FIX: Fix interpolate #5624
Conversation
Although thinking about it a bit, this probably isn't going to be a safe check case for some fill values that start with dimension 2, right...? I guess it would be ambiguous at that point if the two elements were start and end fills, or if they were the 2 values that should be used for both the start and the end. So maybe an error should be raised in that specific case? |
@@ -309,7 +309,7 @@ def _duplicate(ab): | |||
# transform to a pair (a, a) | |||
try: | |||
a, b = ab | |||
except TypeError: | |||
except (TypeError, ValueError): # ndarray can rais ValueError here |
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 can fix this typo and open the fix to master
if people agree it's the right move
Somehow I did not test array-valued fill_values, thanks for catching it! Sadly, just catching ValueError does not do the right thing e.g., here:
Maybe the right thing is to do One more issue with arrays as fill_values is You can fix this now or I'll do it separately a bit later. |
This could be fixed by checking |
Hmmm... this is a bit more complex than I originally thought. I have some fixes in the works. But I realized that our use case actually made use of the fact that the |
@ev-br pushed a commit that fixes the use cases you mentioned. It also makes the code more DRY by only doing |
Sadly this is going to actually break my use case, but I can fix it for my library. I hope it doesn't also silently break other people's code who had been using the broadcastability before, even if it wasn't documented. I could build the broadcastability check instead, if that's a worthwhile enhancement. |
Ugh. Yes, broadcasting fill_value is undocumented and untested. But. Assuming it's useful (and I trust you on that!), this is likely more important use case than having two fill_values: there's no need to break good code by small convenience enhancements. Therefore, I guess it makes sense to i) write a bunch of tests ignoring the two fill_values first, ii) write the definitive statements in the docstring. Then, when it's tested and documented, the question is if we can add two fill_values on top of that in a way that is unambiguous and not too brittle :-). If we can, great. Otherwise, we take two fill_values off until it's too late and it's frozen by being released. How does this sound? Since you have a use case, how much is it to ask you to work on it? I'm willing to help but I don't know your library and its uses. |
I can implement it hopefully in the next few days. The brittle cases will
be where there is ambiguity between two values, or a first dimension of
length two. Not sure what to do in that case, I'll think on it.
|
@ev-br do you think it's sufficient to check the type as |
Okay @ev-br I made it work with broadcasting, modified docstring (should explain the changes properly) and tests, got rid of the warnings during tests about |
# at least one check failed | ||
raise ValueError('%s argument must be able to broadcast up ' | ||
'to shape %s but had shape %s' | ||
% (name, shape_to, shape_from)) |
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.
It seems like something like this must already exist in numpy
or scipy
, but I couldn't find it with a little bit of googling so I implemented it myself
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.
It could likely work with broacast_to
(which is new in numpy 1.10 IIRC) in a try-except block?
Anyway, this version seems to work so it's fine IMO.
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.
@ev-br regarding backport -- the checks I added just make the failures come earlier, with a bit clearer error messages. Previously, broadcasting worked if the array was the right size. If the fill_value was the wrong size, it would bomb mentioning a size mismatch only once the |
@Eric89GXL I'm confused now. Is the external code of yours still broken with this PR? |
No, it works with this PR
|
And it's broken with master/rc? Why then it should not be backported to 0.17.x? |
Ahh I see what you mean. This is a PR into 0.17 already so I assumed you
meant 0.16 backport. Yeah I think it should be in both master and 0.17.
|
Uh, I see now. We're on the same page, great! Thanks for clarifying it. The fix looks pretty good. I think we need some more tests checking that an array-valued fill_value is actually used, similar to https://github.com/scipy/scipy/blob/master/scipy/interpolate/tests/test_interpolate.py#L305, for potentially confusing cases: a fill_value being a tuple of length 2, a list of length 2, a 1d array of two elements, a list of two lists (is this a single fill_value?), a tuple of two lists (this should be a pair of fill_values), a 2 by 2 array. |
@ev-br good call on the tests, I found a bug with the broadcasting. Ready to go from my end if you're happy with the latest commit. |
Will have a careful look a bit later, ran out of time this year :-). Happy New Year! |
Sounds good -- happy new year to you, too! |
00d0d9e
to
163c638
Compare
y = self._reshape_yi(y) | ||
self._y = self._reshape_yi(self.y) | ||
self.x = x | ||
del y, 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.
For my education: What does this do here?
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.
Up to you, I'm fine either way.
This had grown a bit hairier than anticipated, huh. |
Yeah, testing and covering all the possible cases took more lines than I thought. But I think the result should be pretty stable.
Done and done. The only things changed since you last looked at the code is adding an inline comment to the |
Great, thanks! I'll keep this open for a short while in case someone wants to have a look. Otherwise, I'll merge it and forward port to master. |
Merged, thank you Eric. |
@ev-br this fixes a cryptic error I was getting:
Turns out that doing e.g.
a, b = np.array([1.])
raisesValueError
, notTypeError
likea, b = 1.
would.