Skip to content

sunset_angle uses numpy.clip that is not compatible with numpy 2 #84

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

Closed
deltamarnix opened this issue Mar 6, 2025 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@deltamarnix
Copy link

Describe the bug
When calling sunset_angle with an xarray object, I receive an error. I have mentioned it here: pydata/xarray#7848 (comment).

The problem is the compatibility of numpy and xarray in numpy 2.
It's likely the best way to solve this by checking for the type of data (xarray.DataArray), and then explicitly calling da.clip(-1,1), instead of numpy.clip(da, -1, 1).

This is the line of code that goes wrong:

return arccos(clip(-tan(sol_dec.values) * tan(lat).T, -1, 1)).T

The error is: TypeError: DataWithCoords.clip() got an unexpected keyword argument 'out'.

numpy version: 2.1.3
xarray version: 2025.1.2
pyet version: 1.3.1

@deltamarnix
Copy link
Author

rad_utils.py also has a call to clip that will need fixing:

solar_rat = clip(rs / rso, 0.3, 1)

@raoulcollenteur
Copy link
Member

Thanks for reporting @deltamarnix ! We'll work on this over the next couple of weeks to fix this. Or, if you want, feel free to open a PR with the suggested changes :)

Cheers,
Raoul

@raoulcollenteur raoulcollenteur added the bug Something isn't working label Mar 9, 2025
@raoulcollenteur raoulcollenteur added this to the 1.3: PyEt Reloaded milestone Mar 9, 2025
@deltamarnix
Copy link
Author

I've looked a little deeper into this and reported the issue to xarray. pydata/xarray#10103. It seems that the TypeError happens as part of a DeprecationWarning and I had my warnings as errors enabled in pytest.

To avoid the DeprecationWarning, it's still possible to do a type check, but it might be up to xarray to fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants