-
Notifications
You must be signed in to change notification settings - Fork 59
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
Dimensionless units as "1" - adapt to numpy 2 #1814
Conversation
Sadly, there is one last issue that I did not see how to fix. @coxipi the following tests fail with numpy 2:
I'm guessing it's also a data type promotion issue, but I don't know where to look. |
The SPI functions were only the canary in the mine... indices assigning "" (dimensionless units) are concerned, you can also test "test_ffdi.py" to see this. It comes from pint2cfunits, here is a minimal example with the problematic part: import xclim
value = xclim.core.units.units2pint("")
f"{value:cf}" I guess this should be reported upstream? I'm not sure what body is in charge of operations like return "" if value == units2pint("") else f"{value:cf}" |
This is fixed when you install my branch from cf-xarray. If you do so (with pint 0.24.1 and xarray's master), you'll see that only SPI errors are left. |
How should we handle the new pint version? Will it support Python3.9+? Can we safely raise the lower pin to that upcoming version? |
I guess I was eager to begin my weekend when I wrote this PR's top comment, I could have given more info ;). My current PR to cf_xarray will fix the issue for pint 0.24.1. An older pint version can be used with any cf-xarray, and next cf-xarray will be usable with any pint version. Unless we want to write a somewhat complex dependency string, I suggest we pin cf-xarray only, not pint. Note: I will do further changes to the cf-xarray PR, so the change will be a bit more breaking than initially thought, which goes in the direction of my suggestion. Pint 0.24.1 supports python 3.9+. When all dependent PRs and releases are done, I'll test xclim with different versions of pint to be sure, before merging this PR. |
Oups. The units issue was fixed in Changing xclim to return "1" thus requires cf-xarray 0.9.3 and pint >= 0.24.1, but the latter implies numpy >=21. Footnotes
|
@coxipi FYI, these are the SPI errors on my side:
This PR still requires xarray's master to run. |
@aulemahal I'm tapping out here for now. I needed to replace
Here are the issues I can see that needs adjusting:
Ping me if you have questions. |
Thanks for the work! I think the errors you saw in the ensemble modules are those caused by the float64 issue with cftime in xarray's current release. In my env with xarray@master, I see no failures in this module. The h5netcdf error "OSError: Unable to synchronously open file (file signature not found)" happens when you try to open a non-HDF5 netcdf with engine "h5netcdf". I.e. : if you wrote it with scipy and try to force In my env, the CLI tests failed because the outputs were written without a specified engine and xarray seemed to default to scipy. The subsequent opening with h5netcdf forced failed with this (sadly unclear) error. I disagree with making
But it is a test dependency, of course. The best way to force tests not to use netCDF4 is to not have the package in the env in the first place. In my env, I uninstalled it and all tests pass. I'll push somehing and we'll see! I have no strong feelings about forcing |
@Zeitsperre FYI, I removed a test that was ensuring an error was raised on unfound opendap url. As we don't install |
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Pull Request Checklist:
number
) and pull request (:pull:number
) has been addedWhat kind of change does this PR introduce?
pint2cfunits
.ensure_absolute_tempetature
to its module's__all__
and moveensure_delta
up in the same module so both functions are near another in the file.Does this PR introduce a breaking change?
Yes it does. Fixing numpy 2 issues made me fix pint 0.24.1 issues that made me fix cf_xarray issues which have solution that is not backwards-compatible and now pint and cf_xarray have updated pinned that imply a numpy >=2 pin.
Other information:
We will require 3 new pins :create_ensemble
come from a np2 bug in xarray, which was fixed here promote floating-point numeric datetimes to 64-bit before decoding pydata/xarray#9182.We are thus waiting for a release. Xarray 2024.07.0 out on the 30th.which requires numpy 2, so pinning this as well.UPDATE: No pins were added, but the behaviour of xclim will be different for dimensionless indicators depending on the cf_xarray/pint versions installed.