fix: apply coords-as-truth rule to mask in add_variables/add_constraints#725
Open
FBumann wants to merge 1 commit into
Open
fix: apply coords-as-truth rule to mask in add_variables/add_constraints#725FBumann wants to merge 1 commit into
FBumann wants to merge 1 commit into
Conversation
Collaborator
Author
|
@FabianHofmann THis is somewhat breaking, but we had a Future Warning in place. It aligns the treatment of vounds and mask in |
FBumann
added a commit
that referenced
this pull request
May 24, 2026
…ds keys Numpy and unnamed-pandas inputs are positional — there are no names on the input to map to dims, so passing them through ``as_dataarray`` without a ``dims`` kwarg makes them fall back to ``dim_0/dim_1/...``. The subsequent ``set(arr.dims) - set(expected)`` check then sees those as "extra dimensions" and raises ``ValueError``, even when the input has the right shape for the coords. This regressed the ``add_variables(..., mask=numpy_mask, coords=[a, b])`` case from the ``creating-variables`` notebook (and broke the RTD docs build for #725 because of it). Default ``dims`` to the coords' dim names when not supplied, so a 2-D numpy mask paired with 2-D coords gets the right labels and flows through validate/expand/transpose normally. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ffb83b9 to
681728d
Compare
…onstraints
Routes ``mask`` through ``as_dataarray_in_coords(mask, data.coords)``
instead of ``as_dataarray(...) + broadcast_mask(...)``, so pandas
``Series`` / ``DataFrame`` masks missing a dimension are broadcast
to the variable / constraint shape (parallel to the bounds fix in
the previous PR). The ``add_variables`` ``mask`` type hint widens
to ``MaskLike`` to match ``add_constraints``.
The deprecation announced via ``FutureWarning`` in ``broadcast_mask``
("Missing values will be filled with False ... In a future version,
this will raise an error") is now in effect: masks whose
coordinates are a sparse subset of the data's coordinates raise
``ValueError`` instead of silently filling missing entries.
Mask dims not in the data raise ``ValueError`` instead of
``AssertionError`` for consistency with the bounds path.
``broadcast_mask`` had no other callers and is removed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
681728d to
75f33bc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Stacked on #722. Extends the same coords-as-truth rule to
mask.maskinadd_variables/add_constraintsnow routes throughas_dataarray_in_coords(mask, data.coords). PandasSeries/DataFramemasks missing a dim are broadcast like bounds;masktype hint onadd_variableswidens toMaskLike.broadcast_maskhad no other callers and is deleted.Breaking change (delivering on the previously-emitted
FutureWarning):ValueErrorinstead of silently filling missing entries withFalse. Workaround:mask.reindex({...}, fill_value=False).ValueErrorinstead ofAssertionError.