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

Creation of empty DataArrays in a Dataset #9468

Open
itcarroll opened this issue Sep 9, 2024 · 2 comments · May be fixed by #9976
Open

Creation of empty DataArrays in a Dataset #9468

itcarroll opened this issue Sep 9, 2024 · 2 comments · May be fixed by #9976

Comments

@itcarroll
Copy link
Contributor

Is your feature request related to a problem?

Initializing a DataArray from a scalar along with non-scalar coords and dims, which was implemented in #3159, does not extend to Datasets. Initializing multiple DataArrays with shared dimensions, as a Dataset, is not similarly possible.

Describe the solution you'd like

Dataset creation and assignment could handle scalar values in the same way as DataArray creation.

For example

Dataset({"y": ("x", None)}, coords={"x": [0, 1, 2]})

could yield the same thing as

Dataset({"y": xr.DataArray(None, coords={"x": [0, 1, 2]}, dims="x")})

Only the first case easily extends to multiple variables sharing x.

Describe alternatives you've considered

Defining Coordinates in advance is the currently working alternative, but it's not as elegant and is a rare case of needing to explicitly define a Coordinates instance.

Additional context

If this enhancement is supported, I would attempt a PR.

@shoyer
Copy link
Member

shoyer commented Sep 10, 2024

This sounds like a reasonable addition to me.

@itcarroll itcarroll linked a pull request Jan 23, 2025 that will close this issue
3 tasks
@itcarroll
Copy link
Contributor Author

Comments welcome on #9976 although it's still a WIP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants