-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Use cumsum from flox #10987
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
base: main
Are you sure you want to change the base?
Use cumsum from flox #10987
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Co-authored-by: Deepak Cherian <dcherian@users.noreply.github.com>
for more information, see https://pre-commit.ci
| # median isn't enabled yet, because it would break if a single group was present in multiple | ||
| # chunks. The non-flox code path will just rechunk every group to a single chunk and execute the median | ||
| method_is_not_flox_supported = method.name in ("median", "cumsum", "cumprod") | ||
| method_is_not_flox_supported = method.name in ("median", "cumprod") |
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.
FYI in a future PR, I'd like to use the new flox.is_supported_aggregation here. It's a little smarter about this dispatching. We'll also have to figure out what to do about median which currently auto-rechunks so it always works.
| ) | ||
| return f"""\ | ||
| return self.reduce( | ||
| out = self.reduce( |
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 this needed?
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 thought this looked nice and it was clear there was tweak to fix cumsum/cumprod:
out = self.reduce(
duck_array_ops.cumsum,
dim=dim,
skipna=skipna,
keep_attrs=keep_attrs,
**kwargs,
)
return out.assign_coords(self._obj.coords)Then for consistency and readability I followed that pattern on the others.
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.
Can we apply the assign_coords fix for Dataset.cumsum et al too?
| assert_identical(expected.foo, actual) | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "method, expected_array, use_flox, use_dask", |
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.
The use_dask here should mean grouping a dask array by a numpy array. That will work always.
whats-new.rstapi.rstThe non-flox version reduces chunksizes significantly:
With flox the chunksize is retained: