Skip to content

BUG: use same-kind casting for the np.repeat repeats argument - #32665

Open
ikrommyd wants to merge 2 commits into
numpy:mainfrom
ikrommyd:fix-repeat-intp-same-kind-casting
Open

ikrommyd wants to merge 2 commits into
numpy:mainfrom
ikrommyd:fix-repeat-intp-same-kind-casting

Conversation

@ikrommyd

@ikrommyd ikrommyd commented Sep 16, 2026

Copy link
Copy Markdown
Member

PR summary

np.repeat now casts repeats with same-kind casting, following #26610 (np.take) and #28355 (np.bincount). Integer arrays such as uint64, or int64 on 32-bit platforms, no longer raise a TypeError.

Closes #4384.

AI Disclosure

An AI model was used to investigate the history of the issue and draft the changes.

Signed-off-by: Iason Krommydas <iason.krom@gmail.com>
Signed-off-by: Iason Krommydas <iason.krom@gmail.com>
0, 1,
NPY_ARRAY_SAME_KIND_CASTING | NPY_ARRAY_DEFAULT,
NULL);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is the contiguous important for determining when to copy?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't fully understand what you're asking. The code used to do PyArray_ContiguousFromAny which is PyArray_FromAny(..., NPY_ARRAY_DEFAULT, NULL). So I'm just expanding the macro here and adding NPY_ARRAY_SAME_KIND_CASTING effectively. Are you asking if contiguous was important in the first place before my change?

@ikrommyd ikrommyd Sep 17, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I did not try to understand why before but I now see that in this PR and in np.put, both functions skip the array machinery and take the raw pointer to the data. So yes, contiguity is required because they can't jump elements with strides. counts = (npy_intp *)PyArray_DATA(repeats); a few lines below.

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.

int32/64 cast issue

2 participants