Preserve masked bounds in Coord.cell (#5158)#7120
Merged
trexfeathers merged 2 commits intoJun 16, 2026
Merged
Conversation
Coord.cell() used np.array() to extract the bound for a given index, which silently drops the mask and reveals the raw value stored beneath it. The point path was already changed to np.asanyarray for this reason; apply the same treatment to bounds so a masked bound stays masked, both in the returned Cell and in the cube/coordinate printout. Fixes SciTools#5158.
trexfeathers
approved these changes
Jun 16, 2026
trexfeathers
left a comment
Contributor
There was a problem hiding this comment.
Looks good, thanks @gaoflow. I've tested the printout too 👍
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7120 +/- ##
=======================================
Coverage 90.15% 90.15%
=======================================
Files 91 91
Lines 24981 24981
Branches 4685 4685
=======================================
Hits 22522 22522
Misses 1682 1682
Partials 777 777 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
🚀 Pull Request
Description
Closes #5158.
When a coordinate has a masked bound, :meth:
iris.coords.Coord.cellrevealed the value stored underneath the mask instead of reporting it as masked. This also surfaced in the cube / coordinate printout.The cause is the use of
np.array()when extracting the bound, which drops the mask:The point path was already switched to
np.asanyarrayfor exactly this reason (and #5158 was diagnosed by @pp-mo as pointing atCoord.cell); this PR applies the same treatment to bounds.Reproduction (before)
After
and the cube printout now shows
height 5.0, bound=(--, 7.0)instead of(3.0, 7.0).Implementation
np.array(x, ndmin=1)is replaced withnp.atleast_1d(np.asanyarray(x)), the mask-preserving equivalent (mirroring the existing point handling on the line above). Unmasked bounds are unaffected.Verification
Test_cell:test_masked_bound(fails onmain, passes here) andtest_masked_point(guards the already-fixed point path).tests/unit/coords/suite (411),test_Cell(31), andtests/unit/representation/cube summary/printout suite (59) all pass.ruff check/ruff formatclean.