Skip to content

When _shuffled_index and __getitem__ receive NumPy integer scalars, divmod propagates the NumPy types. Downstream modulo operations like (seed + epoch) % 2**32 can then fail with OverflowError: Python integer 4294967296 out of bounds for int32 if the scalar is np.int32 (or narrower) because Python delegates to the NumPy ufunc which attempts to coerce 2**32 into the scalar's precision.#1366

Open
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_952392989

Conversation

@copybara-service

@copybara-service copybara-service Bot commented Jul 22, 2026

Copy link
Copy Markdown

When _shuffled_index and __getitem__ receive NumPy integer scalars, divmod propagates the NumPy types. Downstream modulo operations like (seed + epoch) % 2**32 can then fail with OverflowError: Python integer 4294967296 out of bounds for int32 if the scalar is np.int32 (or narrower) because Python delegates to the NumPy ufunc which attempts to coerce 2**32 into the scalar's precision.

By casting the input index to int early in ShuffleMapDataset._shuffled_index,
WindowShuffleMapDataset._shuffled_index, MixedMapDataset.__getitem__, and
_ConcatSelectionMap.__getitem__, we ensure downstream operations remain
Python integers, guarding against unexpected overflows regardless of caller inputs.

…s, `divmod` propagates the NumPy types. Downstream modulo operations like `(seed + epoch) % 2**32` can then fail with `OverflowError: Python integer 4294967296 out of bounds for int32` if the scalar is `np.int32` (or narrower) because Python delegates to the NumPy ufunc which attempts to coerce `2**32` into the scalar's precision.

By casting the input index to `int` early in `ShuffleMapDataset._shuffled_index`,
`WindowShuffleMapDataset._shuffled_index`, `MixedMapDataset.__getitem__`, and
`_ConcatSelectionMap.__getitem__`, we ensure downstream operations remain
Python integers, guarding against unexpected overflows regardless of caller inputs.

PiperOrigin-RevId: 952392989
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