Provide Variable initialization from np.full
for Datasets
#9976
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
whats-new.rst
Adds logic to
variable.as_variable
that handles tuples like(["x", "y"], 0)
and(["x", "y"],)
which results in a Variable with the given dimensions and a constant value (usingnp.nan
if not given). Theas_variable
function takes an new optional argument calledsizes
that calling functions (notablycore.merge
) can construct from existing mappings. The construction ofsizes
added tocore.merge
is a possible performance concern.I also considered putting the logic "higher up" in
dataset.merge_data_and_coords
, but that required an additional loop through thedata_vars
mapping and ended up with duplicate case checking inas_variable
anyways.Starting as draft for feedback and before updating any documentation. I've also discovered that the analogous enhancement to DataArray doesn't work with non-dimensional coordinates, which I'd like to take a look at for consistency.