BUG: Fixes #7395, operator.index now fails on numpy.bool_ by eric-wieser · Pull Request #9685 · numpy/numpy

Conversation

@eric-wieser

Rebase of @emilienkofman's #7420, along with added test and release notes. The description from there is

Attempt to fix the bug described in #7395. If this needs a depreciation warning I can change the Err to Warning and maybe add a test (?)

mhvk

Choose a reason for hiding this comment

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

Wondering about the one comment; less code is better...

bool_index(PyObject *a)
{
return PyInt_FromLong(PyArrayScalar_VAL(a, Bool));
PyErr_SetString(PyExc_TypeError,

Choose a reason for hiding this comment

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

Instead of raising an error here, isn't it easier to remove this whole definition and not define (or explicitly set to NULL; not sure) PyBoolArrType_Type.tp_as_number->nb_index? (it is currently defined in L4114).

Choose a reason for hiding this comment

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

Yeah, good catch

@eric-wieser

@mhvk: Addressed. Does this want a deprecation cycle? We already hit operator.index(array(True)) in a previous release

@seberg

Unless this is a big bug somewhere, the default should be to go through the deprecation I think.

@eric-wieser

@charris

Fixed merge conflict and merged. Thanks Eric.

BvB93 pushed a commit to BvB93/numpy that referenced this pull request

Sep 7, 2020

Labels