Skip to content
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

Add Coordinates.assign() method #8102

Merged
merged 11 commits into from
Sep 1, 2023
Merged

Conversation

benbovy
Copy link
Member

@benbovy benbovy commented Aug 23, 2023

  • Tests added
  • User visible changes (including notable bug fixes) are documented in whats-new.rst
  • New functions/methods are listed in api.rst

This is consistent with the Dataset and DataArray assign methods (now that Coordinates is also exposed as public API).

This allows writing:

midx = pd.MultiIndex.from_arrays([["a", "a", "b", "b"], [0, 1, 0, 1]])
midx_coords = xr.Coordinates.from_pandas_multiindex(midx, "x")

ds = xr.Dataset(coords=midx_coords.assign(y=[1, 2]))

which is quite common (at least in the tests) and a bit nicer than

ds = xr.Dataset(coords=midx_coords.merge({"y": [1, 2]}).coords)

Co-authored-by: Illviljan <[email protected]>
@benbovy benbovy added the plan to merge Final call for comments label Aug 25, 2023
@benbovy benbovy enabled auto-merge (squash) September 1, 2023 13:25
@benbovy benbovy disabled auto-merge September 1, 2023 13:25
@benbovy benbovy merged commit 71177d4 into pydata:main Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plan to merge Final call for comments
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants