Skip to content

No override for csc_matrix.__init__(arg1=(vals, (rows, cols)), ...) #748

@ggirelli

Description

@ggirelli

I am trying to use scipy-stubs but my code instantiates csc_matrix with the 4th way of doing so, according to scipy's docs:

csc_matrix((data, (row_ind, col_ind)), [shape=(M, N)])
where data, row_ind and col_ind satisfy the relationship a[row_ind[k], col_ind[k]] = data[k].

When I use scipy-stubs with that I hit the following errors:

No overloads for "__init__" match the provided argumentsPylance[reportCallIssue](https://github.com/microsoft/pylance-release/blob/main/docs/diagnostics/reportCallIssue.md)

and (for v)

Argument of type "tuple[_Array[tuple[int, int], float64], tuple[NDArray[signedinteger[_32Bit]], NDArray[signedinteger[_32Bit]]]]" cannot be assigned to parameter "arg1" of type "Sequence[Sequence[JustFloat]]" in function "__init__"
  "ndarray[tuple[int, int], dtype[float64]]" is not assignable to "Sequence[JustFloat]"
  "ndarray[_AnyShape, dtype[signedinteger[_32Bit]]]" is incompatible with protocol "JustFloat"
    "hex" is not present
      "__class__" is an incompatible type
        Type "() -> type[ndarray[_AnyShape, dtype[signedinteger[_32Bit]]]]" is not assignable to type "() -> type[float]"
        Type "(type: type[ndarray[_AnyShape, dtype[signedinteger[_32Bit]]]], /) -> None" is not assignable to type "(t: type[float], /) -> None"
          "JustFloat" is not assignable to "ndarray[_AnyShape, dtype[signedinteger[_32Bit]]]"
          Function return type "type[ndarray[_AnyShape, dtype[signedinteger[_32Bit]]]]" is incompatible with type "type[float]"Pylance[reportArgumentType](https://github.com/microsoft/pylance-release/blob/main/docs/diagnostics/reportArgumentType.md)

Can be reproduced with

import numpy as np
from scipy.sparse import csc_matrix

nr = 10
nc = 10
v = np.ones((nr, nc), dtype=np.float64)
r = np.concatenate([np.arange(nr), np.arange(nc)]).astype(np.int32)
c = np.concatenate([np.arange(nc), np.arange(nr)]).astype(np.int32)
csc_matrix[np.float64]((v, (r, c)), shape=(nr, nc))

I am using scipy v1.16.0 and scipy-stubs v1.16.0.2.

Do I understand correctly that that __init__ is currently not covered?

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions