-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
flox: don't set fill_value where possible #9433
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7133b42
flox: don't set fill_value where possible
dcherian 76019ed
Update doctest
dcherian e7d0ab6
Fix test
dcherian b96618b
Merge branch 'main' into flox-preserve-dtype
dcherian eebb067
fix test
dcherian 5c9f291
Merge branch 'main' into flox-preserve-dtype
dcherian d2648bc
Merge branch 'main' into flox-preserve-dtype
dcherian 327e8be
Test for flox >= 0.9.12
dcherian 0fbe7d1
Merge branch 'main' into flox-preserve-dtype
dcherian 93cda75
fix whats-new
dcherian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -791,14 +791,12 @@ def _maybe_restore_empty_groups(self, combined): | |
"""Our index contained empty groups (e.g., from a resampling or binning). If we | ||
reduced on that dimension, we want to restore the full index. | ||
""" | ||
from xarray.groupers import BinGrouper, TimeResampler | ||
|
||
has_missing_groups = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice generalization. |
||
self.encoded.unique_coord.size != self.encoded.full_index.size | ||
) | ||
indexers = {} | ||
for grouper in self.groupers: | ||
if ( | ||
isinstance(grouper.grouper, BinGrouper | TimeResampler) | ||
and grouper.name in combined.dims | ||
): | ||
if has_missing_groups and grouper.name in combined._indexes: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The switch from |
||
indexers[grouper.name] = grouper.full_index | ||
if indexers: | ||
combined = combined.reindex(**indexers) | ||
|
@@ -853,10 +851,6 @@ def _flox_reduce( | |
else obj._coords | ||
) | ||
|
||
any_isbin = any( | ||
isinstance(grouper.grouper, BinGrouper) for grouper in self.groupers | ||
) | ||
|
||
if keep_attrs is None: | ||
keep_attrs = _get_keep_attrs(default=True) | ||
|
||
|
@@ -930,14 +924,14 @@ def _flox_reduce( | |
): | ||
raise ValueError(f"cannot reduce over dimensions {dim}.") | ||
|
||
if kwargs["func"] not in ["all", "any", "count"]: | ||
kwargs.setdefault("fill_value", np.nan) | ||
if any_isbin and kwargs["func"] == "count": | ||
# This is an annoying hack. Xarray returns np.nan | ||
# when there are no observations in a bin, instead of 0. | ||
# We can fake that here by forcing min_count=1. | ||
# note min_count makes no sense in the xarray world | ||
# as a kwarg for count, so this should be OK | ||
has_missing_groups = ( | ||
self.encoded.unique_coord.size != self.encoded.full_index.size | ||
) | ||
if has_missing_groups or kwargs.get("min_count", 0) > 0: | ||
# Xarray *always* returns np.nan when there are no observations in a group, | ||
# We can fake that here by forcing min_count=1 when it is not set. | ||
# This handles boolean reductions, and count | ||
# See GH8090, GH9398 | ||
kwargs.setdefault("fill_value", np.nan) | ||
kwargs.setdefault("min_count", 1) | ||
|
||
|
This file contains 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
This file contains 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
Oops, something went wrong.
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.
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 is an improvement, since dtype is preserved now