Stricter Argument Checking for Flatten Methods - #6823
Conversation
|
Mayyybe we should do a deprecation cycle for this, but personally I'd be
|
|
Could you clarify what you mean by this (not a lot of experience with working on large open-source projects)? Even if the proposed coding changes are not merged in, I would certainly propose the changes to the documentation, as it seems misleading given the behind-the-scenes functionality |
|
Yikes. Travis just blew up on me there. Seems like I may have been too strict on the |
|
Sure, to expand: I think the change is a good one. But, it's possible that it will end up taking code that used to work, and make it start throwing exceptions. Of course that code was probably poorly written if it assumed that it was okay to do How much code like this is out there? I don't know. Maybe ~none. Maybe a surprising amount. It's hard to say. The usual way to handle this kind of issue is with a "deprecation cycle", which goes through several stages: first we change the code so that it still works the same way as before, but it calls This is kinda a borderline case, because arguably anyone who was depending on the broken behavior was depending on a bug, and usually we don't do deprecation warnings for bug fixes. But if this turns out to break lots of code then we still probably want to do the deprecation thing, because making stuff work in this reality is more important that being able to claim that we have virtuously followed all the rules of the alternate reality where everyone does what they're supposed to... So what I was saying was that: this is a borderline case where it isn't 100% obvious whether we need a deprecation cycle or not -- this is the sort of thing that has to be figured out when reviewing a change -- but I'd be fine with merging it, so long as we keep an eye out for it causing problems when we put out a Release Candidate for people to test, and possibly revert it then and take the slower route. |
|
Okay, I understand. I have been starting to see what you mean already, as my subsequent commits have been catching errors in which booleans were passed in the |
|
Oh yeah, that is a bad sign... if |
|
A quick skim of scipy source finds lots of lowercase |
|
Oh, that's right. I forgot that |
|
It's not just scipy -- there are literally hundreds of libraries out there that use numpy, and any of them can (potentially) be broken by major changes in numpy. scipy is a convenient one to check though, because it's especially widely used and because it's even older then numpy so has a special habit of using grotty old conventions from the bad old days :-) |
|
Fair enough. Do you think it's best then that I role back some of the changes I made to the C code and replace them with |
|
Yes, we have a |
|
Do we really want to make lowercase versions an error? It seems a little too strict to me... |
|
@seberg : I'm not entirely sure I follow what you were saying. Could you explain? @jaimefrio : I guess it's an issue between what you are allowed to do and what the documentation says you can do. If I'm not mistaken, I don't think the documentation says you can use lowercase. Perhaps the documentation should then be expanded to state this? |
|
Well, Nathaniel did mention there were tests in scipy using lowercase that would be broken by this change... |
|
Right, but I guess the question is: should we allow people to pass in lowercase parameters? That will determine what sort of warning I could put in the C code instead of the changes I made. |
|
@gfyoung, I mean that yes, please change the pull request to give deprecations. Just wanted to note where tests would go and DEPRECATE macro we have. |
|
Fair enough. I updated the PR to use the |
There was a problem hiding this comment.
DEPRECATE needs to be
if (DEPRECATE("blabla") < 0) {
cleanup_code/goto;
return;
}
since it raises an error when the warnings are set accordingly. Also, please add a short test for both deprecations into the test_deprecations.py file, that would also find such an issue.
There was a problem hiding this comment.
I'm sorry: could you clarify what you mean by this? I tried reading the documentation on Python Docs, but I'm not sure I quite follow still.
There was a problem hiding this comment.
Deprecate/PyErr_WarnEx can return an error value (specifically, this happens if you do for example import warnings; warnings.simplefilter("error", DeprecationWarning).
In that case you need to check for a negative return, do the typical cleanup (which might be nothing in this case) and return an error return (NULL or -1 normally).
There was a problem hiding this comment.
If you are curious: https://docs.python.org/2/c-api/exceptions.html#c.PyErr_WarnEx the second paragraph mentions it, the error handling code you can probably steal/infer from other error handling in the funciton.
|
@seberg : Ah, I think I understand. PR updated with a still happy Travis. |
There was a problem hiding this comment.
Yeah, this is right. Can you add a comment /* 2015-12-14, 1.11 */ above both? I think the \ might be unnecessary here, since it is all in brackets? Or was that different in C, don't remember?
Other nitpick, I think I prefer order in lower case maybe with backticks, but frankly I doubt we have a consistent style, so not unless someone else complains soon. I am not sure we should name ORDER explicitly, since in principle the argument could be called differently. Don't have a much nicer idea though, maybe someone else has ;).
There was a problem hiding this comment.
Maybe also just: "invalid order; only 'C', 'F', 'A', or 'K' can be converted to a memory/iteration order." (could add what was actually given, but it tends to be a bit annoying). Anyway, as I said, I am not good at writing these, just thinking loud :).
There was a problem hiding this comment.
You only need \ in multiline defines.
There was a problem hiding this comment.
@seberg : Regarding the comments, sure thing
Good point on the \. It's hard juggling multiple languages at once. :) I did a slight revision to the warning messages to not explicitly mention the order parameter
|
Anyway, thanks, almost there, will leave a bit in case someone has some nitpicks about the message or so. |
|
Oh, sorry :(, one more thing, can wait a bit, but maybe you can add a short note to the release notes in doc/release/ for 1.11, we have most deprecations in there, and if we don't add it now, we would just forget about it later. |
There was a problem hiding this comment.
PEP8 prefers putting the whole string inside parenthesis, and getting rid of both the \s and the +s, relying on string literal concatenation.
There was a problem hiding this comment.
Good to know. Will do.
|
@seberg : No worries. I perfectly understand wanting to make sure the PR is just right. It's difficult to undo a bad merge. :) - I updated the release notes with the deprecation. |
There was a problem hiding this comment.
It is more general, this is used (almost) everywhere where an order argument is used. Also, I think you don't have to argue that it should not be allowed, it will not be allowed in the future ;). Anyway, the document will be revised again for the release.
When you are done with this, could you squash the commits together into one or two (rebase -i HEAD~7 or similar for example). Best give it a commit like "DEP: ..." and you can include "closes gh-6598" at the end in the message as well (the message will be closed automatically and we have the reference).
There was a problem hiding this comment.
Oh, and don't worry about the test failure, seems there is something else going on.
There was a problem hiding this comment.
Regarding the release note, sure thing. Regarding the test failure, got it. I think several people (myself included) have brought this up in the discussion mailing list.
|
Close and reopen to restart tests. |
|
@charris : Thanks! If Travis is happy, and if everyone else is happy, this should be good to merge. |
|
Sorry for the delay. If you got some patience left, the best form would be to have: The DEPRECATE strings could be aligned more PEP8 like and the closing bracket on the same line ;). But I think I will merge this in a bit in any case. Lets hope it only annoys a moderate number of people ^^. |
|
No worries. #6824 has been keeping me occupied :) This PR is good to merge I feel, so tidying it up a bit doesn't hurt at all. Will make those adjustments and make sure Travis is still happy. |
The bug traces to the PyArray_OrderConverter method in conversion_utils.c, where no errors are thrown if the ORDER parameter passed in is not of the string data-type or has a string value of length greater than one. This commit causes a DeprecationWarning to be raised, which will later be turned into a TypeError or another type of error in a future release. Closes gh-6598.
|
32-bit build was hanging for no apparent reason. Closing and reopening PR to see if that was just an anomaly. |
|
@seberg : Travis is happy again! Style suggestions implemented successfully. Should be ready to merge. |
|
OK, lets give it a shot. Thanks a lot! |
Stricter Argument Checking for Flatten Methods
Addresses bug described in #6598 in which calls to the
flattenmethod using nonsense arguments for theorderparameter did not produce errors. This PR changes that behavior so that aTypeErroris now thrown unless theorderparameter is omitted OR takes on one of the following values (case-sensitive but unicode-insensitive): 'C', 'F', 'A', or 'K'. Here is what the behavior looks like now:This is my first PR to the
numpylibrary, so all comments regarding the proposed changes as well as the PR itself are welcome!