-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
MAINT: Add parameter checks to polynomial integration functions. #9930
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
MAINT: Add parameter checks to polynomial integration functions. #9930
Conversation
charris
commented
Oct 26, 2017
It was not being checked that the `lbnd` and `scl` parameters were scalars as required. Closes numpy#9901.
The `lbnd` and `scl` parameters of the various polynomial integration functions are documented to be scalars. Add tests that those parameters are checked and ValueError raised when it is not so.
d58bdf6
to
050cd17
Compare
if np.ndim(lbnd) != 0: | ||
raise ValueError("lbnd must be a scalar.") | ||
if np.ndim(scl) != 0: | ||
raise ValueError("scl must be a scalar.") |
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.
Nit: errors above and below have no terminating period, nor do the builtin python error messages.
@@ -203,6 +203,9 @@ def test_legint(self): | |||
assert_raises(ValueError, leg.legint, [0], .5) | |||
assert_raises(ValueError, leg.legint, [0], -1) | |||
assert_raises(ValueError, leg.legint, [0], 1, [0, 0]) | |||
assert_raises(ValueError, leg.legint, [0], lbnd=[0]) | |||
assert_raises(ValueError, leg.legint, [0], scl=[0]) | |||
assert_raises(ValueError, leg.legint, [0], axis=.5) |
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.
Shouldn't this raise a TypeError
?
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.
Hmm. I was just following the documentation ... It would probably be more correct if all the errors checked here were Type errors except possibly the third and sixth.
050cd17
to
06e62db
Compare
Updated. |
@@ -214,6 +214,9 @@ def test_chebint(self): | |||
assert_raises(ValueError, cheb.chebint, [0], .5) | |||
assert_raises(ValueError, cheb.chebint, [0], -1) | |||
assert_raises(ValueError, cheb.chebint, [0], 1, [0, 0]) | |||
assert_raises(TypeError, cheb.chebint, [0], lbnd=[0]) | |||
assert_raises(TypeError, cheb.chebint, [0], scl=[0]) | |||
assert_raises(ValueError, cheb.chebint, [0], axis=.5) |
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.
This strikes me as backwards. The first two should be ValueError
s, and the second should be a TypeError
.
I don't think there is any precedent in numpy for "wrong number of dimensions" → TypeError
, but there absolutely is precedent for isinstance(axis, float)
→ TypeError
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.
Floats here are fine as long as they are integer valued, same with cnt. Might not be the way things are done now, but this is very old code. What is done is conversion to int
followed by a check for equality against the original value.
If you think the first two should be ValueError
, then the original was correct. However, the ndim check is for scalar, so passing a list could be considered a TypeError
.
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 see your point - the int(x) == x
check is consistent with ValueError
, even if neither are consistent with the axis argument in the rest of numpy.
So yes, I prefered the original - sorry for not being clearer there.
numpy/polynomial/polynomial.py
Outdated
if np.ndim(lbnd) != 0: | ||
raise TypeError("lbnd must be a scalar.") | ||
if np.ndim(scl) != 0: | ||
raise TypeError("scl must be a scalar.") | ||
if iaxis != axis: | ||
raise ValueError("The axis must be integer") |
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.
This should be operator.index
, not int(axis) == axis
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.
In fact, this line and iaxis
should just be removed, and the normalize_axis_index
below allowed to throw a more useful error.
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.
But that's not part of this PR, so don't worry about it
06e62db
to
050cd17
Compare
OK, reverted to original. |
I'm guessing you'd prefer the terminating periods to stay, and I don't think it's worth me arguing over. Does this need a release note? If not, LGTM. |
Non-scalars should have been causing errors or bad results all along, so either a bug fix or just better error messages. I don't think a release note is needed. |
Fair call, thanks! I'll open an issue about the |