Skip to content

fix: preserve boolean values in discrete differences - #995

Open
xiehuanyi wants to merge 1 commit into
pydata:mainfrom
xiehuanyi:fix/boolean-differences-20261012
Open

xiehuanyi wants to merge 1 commit into
pydata:mainfrom
xiehuanyi:fix/boolean-differences-20261012

Conversation

@xiehuanyi

Copy link
Copy Markdown

What type of PR is this? (check all applicable)

  • 💾 Refactor
  • 🪄 Feature
  • 🐞 Bug Fix
  • 🔧 Optimization
  • 📚 Documentation
  • 🧪 Test
  • 🛠️ Other

Related issues

No separate issue filed; reproduced on current main.

Checklist

  • Code follows style guide
  • Tests added
  • Documented the changes

Please explain your changes below.

sparse.diff(COO.from_numpy(np.array([False, True, True, False]))) raises TypeError because it subtracts boolean arrays. NumPy's documented behavior returns [True, False, True] and preserves the boolean dtype.

Select inequality for boolean differencing and subtraction for other dtypes after concatenating any prepend/append arrays. This preserves numeric promotion when a boolean input has numeric edges. Extend the existing NumPy-parity tests to cover booleans, signed/unsigned integers, floats, complex values, higher-order differences, axes and prepend/append combinations, including nonzero boolean fill values in COO and GCXS.

Validation on Python 3.12.13 / NumPy 2.5.4: 32 boolean regressions fail on unchanged main; numeric and complex controls pass. All 147 focused cases pass after the fix. Full Numba-backend suite and module doctests with branch coverage: 7,017 passed, 1 skipped, 97 xfailed, 60 xpassed, 2 warnings. All added coverable lines and arcs are covered. Repository hooks, wheel build and diff checks pass. Finch/MLIR and other operating systems/interpreters were not tested locally.

Prepared with OpenAI Codex assistance and independently reviewed before submission.

Copilot AI balanced review requested due to automatic review settings October 12, 2026 11:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added the fix label Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants