Skip to content

sub_matrix panics on an out-of-range or negative index #26

Open

Description

@CarlKCarlK

pysnptools.util.sub_matrix (used by every SnpData/PstData subset) passes indexes straight to the Rust helper, which panics on an index out of range:

import numpy as np, pysnptools.util as pstutil
matrix = np.random.rand(4, 3)
pstutil.sub_matrix(matrix, [5], [0])            # pyo3_runtime.PanicException: ndarray: index out of bounds
pstutil.sub_matrix(matrix, np.array([-1]), [0]) # PanicException (the -1 wraps to a huge uintp)
pstutil.sub_matrix(matrix, [-1], [0])           # OverflowError: Python integer -1 out of bounds for uint64

A Rust panic also prints a thread backtrace to stderr and is a BaseException, so except Exception does not catch it.

Expected: a clear IndexError naming the bad index, for lists and arrays alike.

Found while adding CuPy support to sub_matrix (PR #25), where CuPy indexing silently wraps such indexes instead.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions