Skip to content

Creation of empty DataArrays in a Dataset #9468

@itcarroll

Description

@itcarroll
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.

Activity

shoyer

shoyer commented on Sep 10, 2024

@shoyer
Member

This sounds like a reasonable addition to me.

itcarroll

itcarroll commented on Jan 23, 2025

@itcarroll
ContributorAuthor

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @shoyer@itcarroll

      Issue actions

        Creation of empty DataArrays in a Dataset · Issue #9468 · pydata/xarray