8000 Error in the find_index functon · Issue #107 · rougier/from-python-to-numpy · GitHub
[go: up one dir, main page]

Skip to content
Error in the find_index functon #107
@fat-crocodile

Description

@fat-crocodile

Hi!

Z = base[6:2:-1, 5::-1]
find_index(base, Z)

produces an exception

TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

The problem is here, in line 43

if step is not None and stop is not None:
if step < 0:
start, stop = stop, start - 1
else:
start, stop = start, stop + 1

We've checked that stop is not None, but step is less than zero and we didn't check start, BOOM!

I suggest code like this:

        if step is not None:
            if step < 0:
                start, stop = stop, start
            if stop is not None:
                stop += np.sign(step)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0