Skip to content

Ignore labels absent from a cell in least_common - #78

Open
ZackaryLoevseth wants to merge 1 commit into
xarray-contrib:mainfrom
ZackaryLoevseth:fix/least-common
Open

ZackaryLoevseth wants to merge 1 commit into
xarray-contrib:mainfrom
ZackaryLoevseth:fix/least-common

Conversation

@ZackaryLoevseth

Copy link
Copy Markdown

Fixes #77.

compute_mode counts labels with fill_value=-1, so a label missing from a cell gets a count of −1 and idxmin returns it. For the anti-mode, absent labels are now set to the count dtype's maximum before idxmin, so they are never chosen and the result keeps the input's integer dtype. Masking them with NaN instead would turn every result into a float. An empty cell still gives the first label, as most_common does.

The run-only test_least_common is replaced with the example from #77 and checks the exact values and the dtype. It fails on main and passes with the change. The rest of the suite is unchanged: the only failures are the two test_conservative_nan_thresholds_against_coarsen cases that #76 marks as xfail. Ruff and mypy give the same findings as on main. I'll add the changelog line once #76 is in, since it adds the Unreleased section.

compute_mode counts with fill_value=-1, so a label missing from a cell got a count of -1 and idxmin returned it. Absent labels are now set to the count dtype's maximum before idxmin, which keeps the integer output dtype. The run-only test_least_common is replaced with the example from xarray-contrib#77.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

least_common can return a label absent from the target cell

1 participant