classify: align natural_breaks parameter order with sibling classifiers#3418
Open
brendancol wants to merge 2 commits into
Open
classify: align natural_breaks parameter order with sibling classifiers#3418brendancol wants to merge 2 commits into
brendancol wants to merge 2 commits into
Conversation
natural_breaks ordered its parameters (agg, num_sample, name, k), while the other classifiers that take the same arguments order them (agg, k, num_sample, name): quantile and maximum_breaks. So natural_breaks(raster, 5) quietly set num_sample=5 instead of k=5. Reorder natural_breaks to (agg, k=5, num_sample=20000, name) and add a backward-compatible shim. Legacy callers always passed k as a keyword (it was the last parameter), so a call with k= as a keyword plus a second positional is using the old order; treat that positional as the old num_sample and warn. This keeps natural_breaks(raster, 20000, k=4) working. Also add the missing type hints to binary, the only public classifier without them. Tests cover the new positional k and the deprecated legacy order. Refs #3398
…tency-classify-2026-06-20 # Conflicts: # .claude/sweep-api-consistency-state.csv # xrspatial/classify.py # xrspatial/tests/test_classify.py
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.
What
natural_breaksordered its parameters differently from the otherclassifiers that take the same arguments. This lines it up and adds the
type hints
binarywas missing.Closes #3398.
The drift
quantileandmaximum_breaksputkfirst andnamelast.natural_breaksdid the opposite, sonatural_breaks(raster, 5)setnum_sample=5instead ofk=5.Change
natural_breaksto(agg, k=5, num_sample=20000, name=...).kas akeyword (it was the last parameter), so a call that gives
k=as akeyword and a second positional is using the old order: that
positional is the old
num_sample. Remap it and emit aDeprecationWarning.natural_breaks(raster, 20000, k=4)(used inone example notebook) keeps working.
agg: xr.DataArray,name: Optional[str], and the return hint tobinary, the only public classifier without type hints.Deprecation impact
The reorder is breaking for code that passed
num_samplepositionally.The shim covers the one documented pattern (
kkeyword plus positionalnum_sample) and warns rather than silently reinterpreting the value.Tests
test_natural_breaks_positional_k_matches_siblings: second positionalarg is now
k.test_natural_breaks_legacy_positional_num_sample_warns: the oldorder warns and produces the same result.
Verified on numpy and cupy entry points (CUDA available on this host),
plus the Dataset path. Full
test_classify.pyandtest_validation.pypass.
Found by the api-consistency deep-sweep against
classify.