Skip to content

BUG: partition/argpartition do not accept uint64 indices #19832

@BvB93

Description

@BvB93

The partition and argpartition functions currently raise when the kth indices are supplied as a uint64 array-like.

The functions in question check that the indice-type can safelly be cast to intp, which of course will fail in the case of uint64. I'm not quite sure how the likes of __getitem__ and take do manage to deal with uint64, but there it seems to work just fine.

if (!PyArray_CanCastSafely(PyArray_TYPE(ktharray), NPY_INTP)) {
PyErr_Format(PyExc_TypeError, "Partition index must be integer");
return NULL;
}

Example

In [1]: import numpy as np

In [2]: ar = np.arange(10)

In [3]: ar.partition(np.uint64(5))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-fee31ee69481> in <module>
----> 1 ar.partition(np.uint64(5))

TypeError: Partition index must be integer

NumPy/Python version information:

1.22.0.dev0+997.g8e4e40f60
3.9.6 | packaged by conda-forge | (default, Jul 11 2021, 03:36:15) 
[Clang 11.1.0 ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions