-
-
Notifications
You must be signed in to change notification settings - Fork 556
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
raise ValueError instead of IndexError in .any_root() #37034
raise ValueError instead of IndexError in .any_root() #37034
Conversation
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.
LGTM overall but some very minor things to address.
Thanks, done. |
Documentation preview for this PR (built with commit d6660cd; changes) is ready! 🎉 |
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.
Thank you. LGTM.
sagemathgh-37034: raise ValueError instead of IndexError in .any_root() The `.any_root()` method sometimes raises an `IndexError` instead of the usual `ValueError` when no root exists. Example (Sage 10.2): ```sage sage: R.<x> = Zmod(55)[] sage: (x^2 + 1).any_root() ------------------------------------------------------------------------ --- IndexError Traceback (most recent call last) Cell In[2], line 1 ----> 1 (x**Integer(2)+Integer(1)).any_root() File /usr/lib/python3.11/site- packages/sage/rings/polynomial/polynomial_element.pyx:2315, in sage.rings.polynomial.polynomial_element.Polynomial.any_root (build/cythonized/sage/rings/polynomial/polynomial_element.c:34795)() 2313 return (self//h).any_root(ring, -degree, True) 2314 else: -> 2315 return self.roots(ring=ring, multiplicities=False)[0] 2316 2317 def __truediv__(left, right): IndexError: list index out of range ``` With this patch, we check for the `IndexError` before it happens and raise a `ValueError` instead. URL: sagemath#37034 Reported by: Lorenz Panny Reviewer(s): Travis Scrimshaw
sagemathgh-37034: raise ValueError instead of IndexError in .any_root() The `.any_root()` method sometimes raises an `IndexError` instead of the usual `ValueError` when no root exists. Example (Sage 10.2): ```sage sage: R.<x> = Zmod(55)[] sage: (x^2 + 1).any_root() ------------------------------------------------------------------------ --- IndexError Traceback (most recent call last) Cell In[2], line 1 ----> 1 (x**Integer(2)+Integer(1)).any_root() File /usr/lib/python3.11/site- packages/sage/rings/polynomial/polynomial_element.pyx:2315, in sage.rings.polynomial.polynomial_element.Polynomial.any_root (build/cythonized/sage/rings/polynomial/polynomial_element.c:34795)() 2313 return (self//h).any_root(ring, -degree, True) 2314 else: -> 2315 return self.roots(ring=ring, multiplicities=False)[0] 2316 2317 def __truediv__(left, right): IndexError: list index out of range ``` With this patch, we check for the `IndexError` before it happens and raise a `ValueError` instead. URL: sagemath#37034 Reported by: Lorenz Panny Reviewer(s): Travis Scrimshaw
sagemathgh-37034: raise ValueError instead of IndexError in .any_root() The `.any_root()` method sometimes raises an `IndexError` instead of the usual `ValueError` when no root exists. Example (Sage 10.2): ```sage sage: R.<x> = Zmod(55)[] sage: (x^2 + 1).any_root() ------------------------------------------------------------------------ --- IndexError Traceback (most recent call last) Cell In[2], line 1 ----> 1 (x**Integer(2)+Integer(1)).any_root() File /usr/lib/python3.11/site- packages/sage/rings/polynomial/polynomial_element.pyx:2315, in sage.rings.polynomial.polynomial_element.Polynomial.any_root (build/cythonized/sage/rings/polynomial/polynomial_element.c:34795)() 2313 return (self//h).any_root(ring, -degree, True) 2314 else: -> 2315 return self.roots(ring=ring, multiplicities=False)[0] 2316 2317 def __truediv__(left, right): IndexError: list index out of range ``` With this patch, we check for the `IndexError` before it happens and raise a `ValueError` instead. URL: sagemath#37034 Reported by: Lorenz Panny Reviewer(s): Travis Scrimshaw
The
.any_root()
method sometimes raises anIndexError
instead of the usualValueError
when no root exists.Example (Sage 10.2):
With this patch, we check for the
IndexError
before it happens and raise aValueError
instead.