Skip to content

fix: preserve zero-dimensional arrays in sparse conversions - #963

Merged
hameerabbasi merged 1 commit into
pydata:mainfrom
Doribelove:codex/sparse-scalar-conversion
Sep 22, 2026
Merged

hameerabbasi merged 1 commit into
pydata:mainfrom
Doribelove:codex/sparse-scalar-conversion

Conversation

@Doribelove

Copy link
Copy Markdown
Contributor

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 main at 7b075c7.

Checklist

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

Please explain your changes below.

COO.from_iter({(): 5}, shape=()) raises ValueError, as does converting a scalar COO with a stored value through DOK back to COO. Empty coordinate tuples get a floating-point dtype and fail coordinate validation. The separate (data, coordinates) form also cannot construct scalars or empty arrays.

Keep empty coordinate arrays integer-typed, including the zero-axis case, and handle empty data before accessing its first element. Nonempty fractional coordinates remain invalid. Separately, DOK.from_numpy(np.array(5)) now handles the scalar directly, avoiding the invalid zero-dimensional np.nonzero call and retaining DOK's zero fill value.

Validation on Python 3.12.14 / NumPy 2.5.3:

  • 55 new parametrized cases: 49 failed and 6 passed before the fix; all pass afterward. Coverage includes both COO input layouts, iterators, duplicate scalar coordinates, empty arrays, DOK round trips, dtypes, NaN and nonzero fill values.
  • Numba-backend tests and module doctests: 6,329 passed, 1 skipped, 98 xfailed, 59 xpassed, 2 warnings.
  • Repository pre-commit hooks, wheel build and git diff --check passed. Other backends and platforms were not tested locally.

Prepared with assistance from OpenAI Codex; validation was executed locally.

@github-actions github-actions Bot added the fix label Sep 22, 2026
@hameerabbasi
hameerabbasi enabled auto-merge (squash) September 22, 2026 06:58
@hameerabbasi
hameerabbasi merged commit 6f5f88f into pydata:main Sep 22, 2026
12 of 14 checks passed
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