-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
__array__
copy keyword changes incomplete
#25916
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
Comments
This breaks a number of tests in sympy:
At the same time we are also seeing a segfault in CI with the numpy nightly wheels but I don't know if that is related to this (they both seem to happen at the same time): |
I can't reproduce the segfault locally so it is only in CI for now... |
Can you try a CI run where you only use one of nightly numpy/nightly scipy to try to narrow it down a bit? |
Almost certainly related, so not sure it is worth digging. this is the test in question (where it segfaults): def test_issue_14943():
# Test that __array__ accepts the optional dtype argument
try:
from nu
8000
mpy import array
except ImportError:
skip('NumPy must be available to test creating matrices from ndarrays')
M = Matrix([[1,2], [3,4]])
assert array(M, dtype=float).dtype.name == 'float64' |
Yes, the |
Thanks all. The sympy CI jobs are green now so it looks like it's working as expected. If anything about class Matrix:
def __array__(self, dtype=object):
... We could add a Perhaps it should be something like: class Matrix:
def __array__(self, dtype=object, copy=None):
if copy is not None and not copy:
raise TypeError("Cannot implement copy=False when converting Matrix to ndarray")
... The dev docs suggest that the signature should have Is the intention that not having the |
That signature and logic look right to me.
Indeed. Right now it's a |
I was thinking a couple of years :) |
Also you’ll only see the warning if you explicitly pass |
It's still very early in the morning and I may simply not be awake yet, but it looks to me like the
__array__
changes in gh-25168 are incomplete and don't have a regression test for the old signature:I didn't follow the review of the C code in detail, so I'm probably missing some details, but it doesn't look like the current implementation does what was intended. In particular:
copy
keyword if it's not the default value ofNone
, to have a smaller impact,False
orNone
(never_copy ? Py_False : Py_None;
),dtype
keyword should still be passed, so the code should popcopy
and retry withkwargs
rather than passing NULL.It looks like the changes should be along these lines (incomplete):
Cc @mtsokol @ngoldbaum @seberg.
The text was updated successfully, but these errors were encountered: