Avoid in-place multiplication of a large value to an array with small integer dtype#8867
Merged
dcherian merged 7 commits intopydata:mainfrom Mar 29, 2024
Merged
Conversation
for more information, see https://pre-commit.ci
Contributor
|
Why is in-place multiplication a problem here? |
Contributor
Author
|
Quick response for a draft PR! My idea 5 minutes ago is that will create a number larger than int8, which is strange. So I think we should create a new array instead with whatever numpy thinks is the best dtype. |
Illviljan
commented
Mar 26, 2024
| # there isn't one, and set it to transparent where data is masked. | ||
| if z.shape[-1] == 3: | ||
| alpha = np.ma.ones(z.shape[:2] + (1,), dtype=z.dtype) | ||
| safe_dtype = np.promote_types(z.dtype, np.uint8) |
Contributor
Author
There was a problem hiding this comment.
The dtype should allow at least 0 and 255. But it will be converted in np.ma.concatenate at some point anyway so I thought it's best to just figure it out early and initialize alpha correctly.
Contributor
|
Thanks for figuring this out! |
dcherian
added a commit
to dcherian/xarray
that referenced
this pull request
Apr 2, 2024
* main: (26 commits) [pre-commit.ci] pre-commit autoupdate (pydata#8900) Bump the actions group with 1 update (pydata#8896) New empty whatsnew entry (pydata#8899) Update reference to 'Weighted quantile estimators' (pydata#8898) 2024.03.0: Add whats-new (pydata#8891) Add typing to test_groupby.py (pydata#8890) Avoid in-place multiplication of a large value to an array with small integer dtype (pydata#8867) Check for aligned chunks when writing to existing variables (pydata#8459) Add dt.date to plottable types (pydata#8873) Optimize writes to existing Zarr stores. (pydata#8875) Allow multidimensional variable with same name as dim when constructing dataset via coords (pydata#8886) Don't allow overwriting indexes with region writes (pydata#8877) Migrate datatree.py module into xarray.core. (pydata#8789) warn and return bytes undecoded in case of UnicodeDecodeError in h5netcdf-backend (pydata#8874) groupby: Dispatch quantile to flox. (pydata#8720) Opt out of auto creating index variables (pydata#8711) Update docs on view / copies (pydata#8744) Handle .oindex and .vindex for the PandasMultiIndexingAdapter and PandasIndexingAdapter (pydata#8869) numpy 2.0 copy-keyword and trapz vs trapezoid (pydata#8865) upstream-dev CI: Fix interp and cumtrapz (pydata#8861) ...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Upstream numpy has become a bit more particular with which types you can use for inplace operations. This PR fixes
Some curious behaviors seen while debugging:
xref: #8844