@@ -73,7 +73,7 @@ def check_class_nan(test):
73
73
from ._compressed import GCXS
74
74
from ._coo import COO
75
75
76
- if isinstance (test , ( GCXS , COO ) ):
76
+ if isinstance (test , GCXS | COO ):
77
77
return nan_check (test .fill_value , test .data )
78
78
if _is_scipy_sparse_obj (test ):
79
79
return nan_check (test .data )
@@ -248,7 +248,7 @@ def matmul(a, b):
248
248
a = a [(None ,) * (b .ndim - a .ndim )]
249
249
if a .ndim > b .ndim :
250
250
b = b [(None ,) * (a .ndim - b .ndim )]
251
- for i , j in zip (a .shape [:- 2 ], b .shape [:- 2 ]):
251
+ for i , j in zip (a .shape [:- 2 ], b .shape [:- 2 ], strict = True ):
252
252
if i != 1 and j != 1 and i != j :
253
253
raise ValueError ("shapes of a and b are not broadcastable" )
254
254
@@ -655,11 +655,11 @@ def _dot_csr_csr(out_shape, a_data, b_data, a_indices, b_indices, a_indptr, b_in
655
655
head = - 2
656
656
length = 0
657
657
next_ [:] = - 1
658
- for j , av in zip (
658
+ for j , av in zip ( # noqa: B905
659
659
a_indices [a_indptr [i ] : a_indptr [i + 1 ]],
660
660
a_data [a_indptr [i ] : a_indptr [i + 1 ]],
661
661
):
662
- for k , bv in zip (
662
+ for k , bv in zip ( # noqa: B905
663
663
b_indices [b_indptr [j ] : b_indptr [j + 1 ]],
664
664
b_data [b_indptr [j ] : b_indptr [j + 1 ]],
665
665
):
@@ -921,11 +921,11 @@ def _dot_coo_coo(out_shape, a_coords, b_coords, a_data, b_data, a_indptr, b_indp
921
921
head = - 2
922
922
length = 0
923
923
next_ [:] = - 1
924
- for j , av in zip (
924
+ for j , av in zip ( # noqa: B905
925
925
a_coords [1 , a_indptr [i ] : a_indptr [i + 1 ]],
926
926
a_data [a_indptr [i ] : a_indptr [i + 1 ]],
927
927
):
928
- for k , bv in zip (
928
+ for k , bv in zip ( # noqa: B905
929
929
b_coords [1 , b_indptr [j ] : b_indptr [j + 1 ]],
930
930
b_data [b_indptr [j ] : b_indptr [j + 1 ]],
931
931
):
@@ -1425,7 +1425,7 @@ def einsum(*operands, **kwargs):
1425
1425
sizes = {}
1426
1426
for t , term in enumerate (terms ):
1427
1427
shape = operands [t ].shape
1428
- for ix , d in zip (term , shape ):
1428
+ for ix , d in zip (term , shape , strict = False ):
1429
1429
if d != sizes .setdefault (ix , d ):
1430
1430
raise ValueError (f"Inconsistent shape for index '{ ix } '." )
1431
1431
total .setdefault (ix , set ()).add (t )
@@ -1437,7 +1437,7 @@ def einsum(*operands, **kwargs):
1437
1437
# we could identify and dispatch to tensordot here?
1438
1438
1439
1439
parrays = []
1440
- for term , array in zip (terms , operands ):
1440
+ for term , array in zip (terms , operands , strict = True ):
1441
1441
# calc the target indices for this term
1442
1442
pterm = "" .join (ix for ix in aligned_term if ix in term )
1443
1443
if pterm != term :
@@ -1924,7 +1924,7 @@ def moveaxis(a, source, destination):
1924
1924
1925
1925
order = [n for n in range (a .ndim ) if n not in source ]
1926
1926
1927
- for dest , src in sorted (zip (destination , source )):
1927
+ for dest , src in sorted (zip (destination , source , strict = True )):
1928
1928
order .insert (dest , src )
1929
1929
1930
1930
return a .transpose (order )
@@ -2042,7 +2042,7 @@ def asarray(obj, /, *, dtype=None, format="coo", device=None, copy=False):
2042
2042
2043
2043
format_dict = {"coo" : COO , "dok" : DOK , "gcxs" : GCXS }
2044
2044
2045
- if isinstance (obj , ( COO , DOK , GCXS ) ):
2045
+ if isinstance (obj , COO | DOK | GCXS ):
2046
2046
return obj .asformat (format )
2047
2047
2048
2048
if _is_scipy_sparse_obj (obj ):
@@ -2051,7 +2051,7 @@ def asarray(obj, /, *, dtype=None, format="coo", device=None, copy=False):
2051
2051
dtype = sparse_obj .dtype
2052
2052
return sparse_obj .astype (dtype = dtype , copy = copy )
2053
2053
2054
- if np .isscalar (obj ) or isinstance (obj , ( np .ndarray , Iterable ) ):
2054
+ if np .isscalar (obj ) or isinstance (obj , np .ndarray | Iterable ):
2055
2055
sparse_obj = format_dict [format ].from_numpy (np .asarray (obj ))
2056
2056
if dtype is None :
2057
2057
dtype = sparse_obj .dtype
@@ -2068,7 +2068,7 @@ def _support_numpy(func):
2068
2068
2069
2069
def wrapper_func (* args , ** kwargs ):
2070
2070
x = args [0 ]
2071
- if isinstance (x , ( np .ndarray , np .number ) ):
2071
+ if isinstance (x , np .ndarray | np .number ):
2072
2072
warnings .warn (
2073
2073
f"Sparse { func .__name__ } received dense NumPy array instead "
2074
2074
"of sparse array. Dispatching to NumPy function." ,
0 commit comments