Skip to content

classify: align natural_breaks parameter order with sibling classifiers#3418

Open
brendancol wants to merge 2 commits into
mainfrom
deep-sweep-api-consistency-classify-2026-06-20
Open

classify: align natural_breaks parameter order with sibling classifiers#3418
brendancol wants to merge 2 commits into
mainfrom
deep-sweep-api-consistency-classify-2026-06-20

Conversation

@brendancol

Copy link
Copy Markdown
Contributor

What

natural_breaks ordered its parameters differently from the other
classifiers that take the same arguments. This lines it up and adds the
type hints binary was missing.

Closes #3398.

The drift

quantile(agg, k=4, num_sample=20000, name='quantile')
maximum_breaks(agg, k=5, num_sample=20000, name='maximum_breaks')
natural_breaks(agg, num_sample=20000, name='natural_breaks', k=5)   # before

quantile and maximum_breaks put k first and name last.
natural_breaks did the opposite, so natural_breaks(raster, 5) set
num_sample=5 instead of k=5.

Change

  • Reorder natural_breaks to (agg, k=5, num_sample=20000, name=...).
  • Add a shim for the old order. Pre-1.0 callers always passed k as a
    keyword (it was the last parameter), so a call that gives k= as a
    keyword and a second positional is using the old order: that
    positional is the old num_sample. Remap it and emit a
    DeprecationWarning. natural_breaks(raster, 20000, k=4) (used in
    one example notebook) keeps working.
  • Add agg: xr.DataArray, name: Optional[str], and the return hint to
    binary, the only public classifier without type hints.

Deprecation impact

The reorder is breaking for code that passed num_sample positionally.
The shim covers the one documented pattern (k keyword plus positional
num_sample) and warns rather than silently reinterpreting the value.

Tests

  • test_natural_breaks_positional_k_matches_siblings: second positional
    arg is now k.
  • test_natural_breaks_legacy_positional_num_sample_warns: the old
    order 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.py and test_validation.py
pass.

Found by the api-consistency deep-sweep against classify.

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
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.

classify: natural_breaks parameter order drifts from quantile/maximum_breaks

1 participant