Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Incorrect Exception when indexing array with field. #8519

@godaygo

Description

@godaygo

When record array is indexed with incorrect field name it raises ValueError as expected:

> arr = np.zeros(10, dtype=[('a', 'i8')])
> arr['b']

ValueError: no field of name b

When a simple array is indexed, it raises IndexError as unexpected:

> arr = np.arange(10)
> arr['a']

IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or 
boolean arrays are valid indices

According to this question on SO previously it was ValueError in both cases. Because you can not typecheck, they are both ndarrays, it is odd to have different types of exceptions.

Was this an intended change?

Also according to all this, the message for IndexError is not full, it does not say about fields.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions