Skip to content

Grouper, Resampler as public api - #8840

Merged
dcherian merged 32 commits into
pydata:mainfrom
dcherian:grouper-public-api
Jul 18, 2024
Merged

Grouper, Resampler as public api#8840
dcherian merged 32 commits into
pydata:mainfrom
dcherian:grouper-public-api

Conversation

@dcherian

@dcheriandcherian commented Mar 15, 2024

Copy link
Copy Markdown
Contributor
  1. Expose UniqueGrouper, BinGrouper and TimeResampler as public API under xarray.groupers
  2. Allow providing these objects to .resample and .groupby
  3. This is a step toward grouping by multiple variables, grouping by a dask array, and unblocking "chunking to a frequency" (Support specifying chunk sizes using labels (e.g. frequency string) #7559)

We do not yet officially support custom Grouper or Resampler objects. I'd like to clear up the API a bit before exposing that.


Comment threadxarray/core/dataarray.py Outdated
Comment threadxarray/tests/test_groupby.py Outdated
Comment threadxarray/core/groupers.py
Comment threadxarray/core/types.py Outdated
@dcheriandcherian mentioned this pull request Jun 13, 2024
@dcherian
dcherianforce-pushed the grouper-public-api branch from 04b433a to 235b553CompareJune 13, 2024 22:55
@dcherian
dcherianforce-pushed the grouper-public-api branch from b8085f8 to 384818fCompareJune 14, 2024 16:50
@dcherian
dcherianforce-pushed the grouper-public-api branch 3 times, most recently from 436997b to 7100907CompareJune 21, 2024 22:08
@dcherian
dcherianforce-pushed the grouper-public-api branch from 7100907 to 01fbf50CompareJune 21, 2024 22:35
@dcherian
dcherian marked this pull request as ready for review June 21, 2024 22:35
@dcherian

Copy link
Copy Markdown
ContributorAuthor

This is finally ready for review! Please take a look at the API and docs.

Comment threadxarray/tests/test_groupby.py Outdated
* main:
promote floating-point numeric datetimes to 64-bit before decoding (pydata#9182)
also pin `numpy` in the all-but-dask CI (pydata#9184)
temporarily remove `pydap` from CI (pydata#9183)
temporarily pin `numpy<2` (pydata#9181)
Change np.core.defchararray to np.char (pydata#9165) (pydata#9166)
Fix example code formatting for CachingFileManager (pydata#9178)
Slightly improve DataTree repr (pydata#9064)
switch to unit `"D"` (pydata#9170)
Docs: Add page with figure for navigating help resources (pydata#9147)
Add test for pydata#9155 (pydata#9161)
Remove mypy exclusions for a couple more libraries (pydata#9160)
Include numbagg in type checks (pydata#9159)
Improve zarr chunks docs (pydata#9140)
@dcheriandcherian reopened this Jun 30, 2024
Comment threadxarray/core/groupers.py Outdated
Comment threadxarray/core/groupers.py Outdated
Comment threadxarray/core/groupers.py Outdated
Comment threadxarray/core/dataset.py Outdated
Comment threadxarray/core/groupers.py Outdated
Comment threadxarray/core/groupby.py
@Illviljan

Copy link
Copy Markdown
Contributor

These looks related, same problem as before I guess:

xarray/core/dataset.py: note: In member "groupby" of class "Dataset":
xarray/core/dataset.py:10321: error: Incompatible types in assignment (expression has type "Mapping[Hashable, Any]", variable has type "dict[str, Grouper]") [assignment]
xarray/core/dataarray.py: note: In member "groupby" of class "DataArray":
xarray/core/dataarray.py:6778: error: Incompatible types in assignment (expression has type "Mapping[Hashable, Any]", variable has type "dict[str, Grouper]") [assignment]

* main:
exclude the bots from the release notes (pydata#9235)
switch the documentation to run with `numpy>=2` (pydata#9177)
`numpy` 2 compatibility in the iris code paths (pydata#9156)
`numpy` 2 compatibility in the `netcdf4` and `h5netcdf` backends (pydata#9136)
Fix time indexing regression in `convert_calendar` (pydata#9192)
Use duckarray assertions in test_coding_times (pydata#9226)
Use reshape and ravel from duck_array_ops in coding/times.py (pydata#9225)
Cleanup test_coding_times.py (pydata#9223)
Only use necessary dims when creating temporary dataarray (pydata#9206)
Fix two bugs in DataTree.update() (pydata#9214)
Use numpy 2.0-compat `np.complex64` dtype in test (pydata#9217)
@dcherian
dcherianforce-pushed the grouper-public-api branch from 12c4316 to c94d9c2CompareJuly 11, 2024 16:57
@dcherian

Copy link
Copy Markdown
ContributorAuthor

I ended up using type: ignore after struggling for a while...

@dcheriandcherian added plan to merge Final call for comments and removed needs review labels Jul 17, 2024
* main:
Enable pandas type checking (pydata#9213)
Per-variable specification of boolean parameters in open_dataset (pydata#9218)
test push
Added a space to the documentation (pydata#9247)
Fix typing for test_plot.py (pydata#9234)
Allow mypy to run in vscode (pydata#9239)
Revert "Test main push"
Test main push
Revert "Update _typing.py"
Update _typing.py
Add a `.drop_attrs` method (pydata#8258)
@dcherian

Copy link
Copy Markdown
ContributorAuthor

I'll merge tomorrow if there are no comments.

One thing to think about is whether we want UniqueGrouper or CategoricalGrouper or CategoryGrouper.

@headtr1ckheadtr1ck left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, only couple of minor details.
Feel free to ignore these as well :P

Comment threadxarray/core/dataarray.py Outdated
Comment threadxarray/core/dataset.py Outdated
Comment threadxarray/core/groupers.py Outdated
Comment threadxarray/core/types.py Outdated
Comment threadxarray/core/types.py Outdated
Comment threadxarray/core/groupers.py Outdated
@dcherian
dcherian enabled auto-merge (squash) July 18, 2024 03:18
@dcherian
dcherian merged commit b55c783 into pydata:mainJul 18, 2024
dcherian added a commit that referenced this pull request Jul 22, 2024
* main:
add backend intro and how-to diagram (#9175)
Fix copybutton for multi line examples in double digit ipython cells (#9264)
Update signature for _arrayfunction.__array__ (#9237)
Add encode_cf_datetime benchmark (#9262)
groupby, resample: Deprecate some positional args (#9236)
Delete ``base`` and ``loffset`` parameters to resample (#9233)
Update dropna docstring (#9257)
Grouper, Resampler as public api (#8840)
Fix mypy on main (#9252)
fix fallback isdtype method (#9250)
Enable pandas type checking (#9213)
Per-variable specification of boolean parameters in open_dataset (#9218)
test push
Added a space to the documentation (#9247)
Fix typing for test_plot.py (#9234)
dcherian added a commit that referenced this pull request Jul 24, 2024
* main: (54 commits)
Adding `open_datatree` backend-specific keyword arguments (#9199)
[pre-commit.ci] pre-commit autoupdate (#9202)
Restore ability to specify _FillValue as Python native integers (#9258)
add backend intro and how-to diagram (#9175)
Fix copybutton for multi line examples in double digit ipython cells (#9264)
Update signature for _arrayfunction.__array__ (#9237)
Add encode_cf_datetime benchmark (#9262)
groupby, resample: Deprecate some positional args (#9236)
Delete ``base`` and ``loffset`` parameters to resample (#9233)
Update dropna docstring (#9257)
Grouper, Resampler as public api (#8840)
Fix mypy on main (#9252)
fix fallback isdtype method (#9250)
Enable pandas type checking (#9213)
Per-variable specification of boolean parameters in open_dataset (#9218)
test push
Added a space to the documentation (#9247)
Fix typing for test_plot.py (#9234)
Allow mypy to run in vscode (#9239)
Revert "Test main push"
...
dcherian added a commit to JoelJaeschke/xarray that referenced this pull request Jul 25, 2024
…monotonic-variable
* main: (995 commits)
Adding `open_datatree` backend-specific keyword arguments (pydata#9199)
[pre-commit.ci] pre-commit autoupdate (pydata#9202)
Restore ability to specify _FillValue as Python native integers (pydata#9258)
add backend intro and how-to diagram (pydata#9175)
Fix copybutton for multi line examples in double digit ipython cells (pydata#9264)
Update signature for _arrayfunction.__array__ (pydata#9237)
Add encode_cf_datetime benchmark (pydata#9262)
groupby, resample: Deprecate some positional args (pydata#9236)
Delete ``base`` and ``loffset`` parameters to resample (pydata#9233)
Update dropna docstring (pydata#9257)
Grouper, Resampler as public api (pydata#8840)
Fix mypy on main (pydata#9252)
fix fallback isdtype method (pydata#9250)
Enable pandas type checking (pydata#9213)
Per-variable specification of boolean parameters in open_dataset (pydata#9218)
test push
Added a space to the documentation (pydata#9247)
Fix typing for test_plot.py (pydata#9234)
Allow mypy to run in vscode (pydata#9239)
Revert "Test main push"
...
@dcherian
dcherian deleted the grouper-public-api branch November 17, 2024 16:15
wavebyrd pushed a commit to wavebyrd/xarray that referenced this pull request Mar 13, 2026
* main: (54 commits)
Adding `open_datatree` backend-specific keyword arguments (pydata#9199)
[pre-commit.ci] pre-commit autoupdate (pydata#9202)
Restore ability to specify _FillValue as Python native integers (pydata#9258)
add backend intro and how-to diagram (pydata#9175)
Fix copybutton for multi line examples in double digit ipython cells (pydata#9264)
Update signature for _arrayfunction.__array__ (pydata#9237)
Add encode_cf_datetime benchmark (pydata#9262)
groupby, resample: Deprecate some positional args (pydata#9236)
Delete ``base`` and ``loffset`` parameters to resample (pydata#9233)
Update dropna docstring (pydata#9257)
Grouper, Resampler as public api (pydata#8840)
Fix mypy on main (pydata#9252)
fix fallback isdtype method (pydata#9250)
Enable pandas type checking (pydata#9213)
Per-variable specification of boolean parameters in open_dataset (pydata#9218)
test push
Added a space to the documentation (pydata#9247)
Fix typing for test_plot.py (pydata#9234)
Allow mypy to run in vscode (pydata#9239)
Revert "Test main push"
...
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plan to mergeFinal call for commentstopic-groupby

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update GroupBy constructor for grouping by multiple variables, dask arrays

5 participants

@dcherian@Illviljan@keewis@headtr1ck@TomNicholas