-
Notifications
You must be signed in to change notification settings - Fork 70
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
Update InVEST to build against numpy 2 #1642
Conversation
There appears to be some overlap here with #1631 ... guess I need to be more careful with my branches! |
…1-update-for-numpy-2 Conflicts: HISTORY.rst
…vest into task/1641-update-for-numpy-2
…1-update-for-numpy-2
…1-update-for-numpy-2 Conflicts: HISTORY.rst
An RST error in a footnote in Wave Energy was breaking the binary builds in the main InVEST repository. This is now addressed. RE:natcap#1641
The numpy2 update was producing slightly different numerical outputs, but also we weren't asserting that they were numerically close, just that they had the same number of digits after the decimal ... which wasn't working well because most of these values were large. RE:natcap#1641
This is part of the numpy2 migration. RE:natcap#1641
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.
Thanks @phargogh ! I had one small question around sample / test data in the Makefile.
Makefile
Outdated
|
||
$(GIT_TEST_DATA_REPO_PATH): | $(DATA_DIR) | ||
-git clone $(GIT_TEST_DATA_REPO) $(GIT_TEST_DATA_REPO_PATH) | ||
git -C $(GIT_TEST_DATA_REPO_PATH) fetch | ||
git -C $(GIT_TEST_DATA_REPO_PATH) lfs install | ||
git -C $(GIT_TEST_DATA_REPO_PATH) checkout $(GIT_TEST_DATA_REPO_REV) | ||
git -C $(GIT_TEST_DATA_REPO_PATH) lfs fetch | ||
git -C $(GIT_TEST_DATA_REPO_PATH) lfs checkout | ||
git -C $(GIT_TEST_DATA_REPO_PATH) lfs checkout $(GIT_TEST_DATA_REPO_REV) |
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.
Is that last checkout
step needed? We've done the lfs fetch
and should already be in $(GIT_TEST_DATA_REPO_REV)
right?
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.
Yep, it should be fine without this change! Removed in 89d236b
pyproject.toml
Outdated
@@ -46,7 +46,8 @@ invest = "natcap.invest.cli:main" | |||
# available at runtime. | |||
requires = [ | |||
'setuptools>=61', 'wheel', 'setuptools_scm>=8.0', 'cython>=3.0.0', 'babel', | |||
'oldest-supported-numpy' | |||
'oldest-supported-numpy; python_version<="3.8"', | |||
'numpy>=2; python_version>"3.8"', # numpy 2 only available for 3.9+ |
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.
Awesome, and >3.8
wouldn't grab 3.8.6
or something I'm assuming.
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.
It shouldn't (at least as far as I know), but I've clarified this anyways in 75107e7
@@ -1238,7 +1238,7 @@ def cn_op(lulc_array, soil_group_array): | |||
# if lulc_array value not in lulc_to_soil[soil_group_id]['lulc_values'] | |||
# then numpy.digitize will not bin properly and cause an IndexError | |||
# during the reshaping call | |||
lulc_unique = set(numpy.unique(lulc_array)) | |||
lulc_unique = set(i.item() for i in numpy.unique(lulc_array)) |
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.
I tried to look this up quickly, but I'm not sure I follow calling item()
here...
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.
Ah, unless we're concerned with datatypes, I bet that's it.
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.
Yep, that's it exactly! i
would normally be a native numpy object (e.g. numpy.float32
), so calling .item()
gets the python representation of the object.
@@ -936,7 +936,8 @@ def validate(args, limit_to=None): | |||
nan_mask = cn_df.isna() | |||
if nan_mask.any(axis=None): | |||
nan_lucodes = nan_mask[nan_mask.any(axis=1)].index | |||
lucode_list = list(nan_lucodes.values) | |||
# Convert numpy dtype values to native python types |
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.
Yep!
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 looks good! Thanks!
This PR updates InVEST to build against numpy 2.
Fixes #1641
Checklist
- [ ] Updated the user's guide (if needed)- [ ] Tested the Workbench UI (if relevant)