Skip to content

fix: use int64 in rle_encode for Windows + NumPy 2 compat - #25

Merged
umbertoDifa merged 1 commit into
masterfrom
fix/rle-encode-int64-windows
Apr 14, 2026
Merged

umbertoDifa merged 1 commit into
masterfrom
fix/rle-encode-int64-windows

Conversation

@umbertoDifa

Copy link
Copy Markdown
Collaborator

Summary

  • Root cause: rle_encode declared cdef long[:] counts with dtype=np.int_. On Windows, C long is 32-bit while NumPy 2's np.int_ is 64-bit — Cython rejects the buffer dtype mismatch at runtime.
  • Fix: Switch to int64_t (from libc.stdint) and np.int64, which are always 64-bit on all platforms. Regenerated the .c file from Cython.
  • Version bump: 0.2.1 → 0.2.2
  • Tests: Added tests/test_run_length_encoding.py with regression coverage.

Context

This blocks Python 3.13 support in darwin-py#1136 — on Windows + Py 3.13, NumPy 2.x is required, triggering this bug. Once this is released, the skip workaround in darwin-py can be removed.

Test plan

  • CI passes on all platforms (Linux, macOS, Windows) across Python 3.10–3.13
  • rle_encode produces correct counts on a simple mask
  • darwin-py's test_complex_polygon passes on Windows + 3.13 after upgrading upolygon

Made with Cursor

On Windows, C `long` is 32-bit while NumPy 2's `np.int_` resolves to
64-bit, causing a buffer dtype mismatch in the Cython typed memoryview.

Switch to explicit `int64_t` / `np.int64` so the array and memoryview
always match regardless of platform. Regenerate the .c file from Cython.

Also bump version to 0.2.2 and add regression tests.

Made-with: Cursor
@umbertoDifa
umbertoDifa merged commit 6ccf577 into master Apr 14, 2026
4 checks passed
@umbertoDifa
umbertoDifa deleted the fix/rle-encode-int64-windows branch April 14, 2026 14:33
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.

1 participant