-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Use deepcopy recursively on numpy arrays #4379
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
Conversation
Thanks for the PR @darikg ! Re tests failing — is there a chance python interns the |
it seems that's a backwards compatibility issue with |
Weird, I can't reproduce that locally, even after reverting to numpy 1.15. Trying with a non-object class |
Oh, sorry, I actually can reproduce it locally. Turns out arrays in numpy 1.15 don't have if deep:
if hasattr(data, "__array_function__") or isinstance(
data, dask_array_type
):
data = copy.deepcopy(data)
elif not isinstance(data, PandasIndexAdapter):
# pandas.Index is immutable
data = np.array(data) could just be if deep and not isinstance(data, PandasIndexAdapter):
data = copy.deepcopy(data) But I'm not familiar with |
thanks for tracking this down. The easiest way to fix the test would be to decorate it with pytest.mark.skipif(not IS_NEP18_ACTIVE, reason="requires NEP18") Even easier would be to bump We might also try to rewrite the condition to: if (
hasattr(data, "__array_function__")
or isinstance(data, dask_array_type)
or (not IS_NEP18_ACTIVE and isinstance(data, np.ndarray))
):
data = copy.deepcopy(data) Thoughts, @pydata/xarray? |
4dabee3
to
edd5c1e
Compare
This looks good to go! There's one small formatting fix, and then we can merge. Cheers @darikg |
actually, we should probably merge #4381 to fix the formatting. |
I went with @keewis's last suggestion because I think it makes the most sense for deepcopy to behave as expected even with older versions of numpy |
Great, let's merge both? |
@darikg Thank you for the contribution! If you want to put a whatsnew, feel free to — either as a new PR or if you're planning any more contributions atm, then as part of that. Not obligatory though |
Thanks for everybody's help! Also just wanted to say, you guys have an incredible test suite. |
isort . && black . && mypy . && flake8
whats-new.rst
(Not sure this is worth noting in whats-new)