-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
BUG: Fix scipy incompatibility with cleanup to poly1d #8788
Conversation
4cec73a
to
9bb818f
Compare
I think this should work. Might make a note in |
Maybe the easiest thing to do all round is to make the attributes writable. |
I'd argue not - what
If you measure easiness by lines changed, that's actually less easy! |
In the original poly1d it would only have required removing |
Yes, that's true. Although making |
If there is an easy way to fix the "broken scipy", we could also put a deprecation warning somewhere probably. |
@seberg: I've already submitted the easy fix to "broken scipy" in scipy/scipy#7184 |
Which is why it needs a comment in the code... |
By that, I mean its an implementation detail of |
The problem is that one needs to read through a lot of garbage code and implementation details to figure out how |
So at line 1098, something like
|
This is really ugly, and now you end up with a
(note that the property itself gets store in the class's |
@mhvk I like that. Bit tricksy -- I would not have understood it without the explanation -- but definitely cleaner. |
@mhvk: Huh, wasn't away that while I still think that we want # our internal _coeffs property need to be backed by __dict__['coeffs'] for scipy to work
@property
def _coeffs(self):
return self.__dict__['coeffs']
@_coeffs.setter
def _coeffs(self, coeffs):
self.__dict__['coeffs'] = coeffs
# expose a readonly copy of the coefficients publicly
# note that this does not return a copy for .coeffs, as the above workaround overwrites
# this getter. It does not, however, affect the behaviour for .c, .coef, or .coefficients
@property
def coeffs(self):
return self._coeffs.copy()
c = coef = coefficients = coeffs |
Both the proposed new versions work, although only if |
Scipy needs `.__dict__['coeffs']` to work, so we can't call the member _coeffs
`poly.coeffs = 1` has always failed with a strong exception guarantee. However, `poly.coeffs += 1` would both change the state and fail. Now both fail without affecting the value.
9bb818f
to
0ea21d1
Compare
@charris: Ok, updated with my suggestion. Is the second commit reasonable, given that it makes |
I think it is worth a shot. We will see if anyone complains in the 1.13.0, aka FU, release. |
I think that |
Thanks Eric. |
If you look at the class dict, |
@charris: I really don't think that is the case, else @mhvk's remark about this being derived from And if it is the case, then I need to correct the comment I made in the code saying that it wasn't the case ... |
Well, it turns out you're right! I guess I need to rethink my understanding of the property model, and make a PR to fix this PR fixing that PR... |
@@ -1059,6 +1059,16 @@ def roots(self): | |||
""" The roots of the polynomial, where self(x) == 0 """ | |||
return roots(self._coeffs) | |||
|
|||
# our internal _coeffs property need to be backed by __dict__['coeffs'] for | |||
# scipy to work correctly. Note that as a result, the getter for .coeffs | |||
# does not run unless accessed through one of its aliases. |
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 comment is false
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.
Sorry to have been out of the loop, but indeed the second sentence is incorrect.
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.
Fixed in #8807
Scipy was relying on some of the broken things that #8762 fixed