@@ -130,16 +130,27 @@ def test_invalid_connectivity_is_rejected_without_reinterpretation(
130130
131131
132132@pytest .mark .parametrize ("sparse_format" , ["coo" , "csr" , "csc" , "lil" , "bsr" ])
133- def test_sparse_stored_zero_entries_are_rejected (sparse_format : str ) -> None :
134- row = np .array ([0 , 1 ], dtype = np .int32 )
135- column = np .array ([1 , 0 ], dtype = np .int32 )
133+ def test_sparse_stored_zero_entries_are_not_edges (sparse_format : str ) -> None :
134+ # A stored zero is dropped, as if it were not stored: files written by
135+ # other tools keep them, and they carry no edge.
136+ row = np .array ([0 , 1 , 0 , 2 ], dtype = np .int32 )
137+ column = np .array ([1 , 0 , 2 , 0 ], dtype = np .int32 )
136138 candidate = sparse .coo_matrix (
137- (np .zeros ( 2 , dtype = np . float64 ), (row , column )),
138- shape = (2 , 2 ),
139+ (np .array ([ 0.5 , 0.5 , 0.0 , 0.0 ] ), (row , column )),
140+ shape = (3 , 3 ),
139141 ).asformat (sparse_format )
140142
141- with pytest .raises (ValueError , match = "stored zero" ):
142- validate_connectivity_edges (candidate , n_cells = 2 )
143+ edges = validate_connectivity_edges (candidate , n_cells = 3 )
144+ assert edges .n_edges == 1
145+ assert edges .sources .tolist () == [0 ]
146+ assert edges .destinations .tolist () == [1 ]
147+ assert edges .weights .tolist () == [0.5 ]
148+
149+ only_zeros = sparse .coo_matrix (
150+ (np .zeros (2 ), (row [:2 ], column [:2 ])),
151+ shape = (3 , 3 ),
152+ ).asformat (sparse_format )
153+ assert validate_connectivity_edges (only_zeros , n_cells = 3 ).n_edges == 0
143154
144155
145156@pytest .mark .parametrize ("sparse_format" , ["coo" , "csr" , "csc" , "lil" , "bsr" ])
0 commit comments