@@ -61,7 +61,7 @@ def dict_to_vector(self, d, *, size=None, dtype=None, name=None):
61
61
if size is None :
62
62
size = len (self )
63
63
key_to_id = self ._key_to_id
64
- indices , values = zip (* ((key_to_id [key ], val ) for key , val in d .items ()))
64
+ indices , values = zip (* ((key_to_id [key ], val ) for key , val in d .items ()), strict = True )
65
65
return Vector .from_coo (indices , values , size = size , dtype = dtype , name = name )
66
66
67
67
@@ -116,7 +116,7 @@ def vector_to_dict(self, v, *, mask=None, fill_value=None):
116
116
elif fill_value is not None and v .nvals < v .size :
117
117
v (mask = ~ v .S ) << fill_value
118
118
id_to_key = self .id_to_key
119
- return {id_to_key [index ]: value for index , value in zip (* v .to_coo (sort = False ))}
119
+ return {id_to_key [index ]: value for index , value in zip (* v .to_coo (sort = False ), strict = True )}
120
120
121
121
122
122
def vector_to_list (self , v , * , values_are_keys = False ):
@@ -198,26 +198,29 @@ def matrix_to_dicts(self, A, *, use_row_index=False, use_column_index=False, val
198
198
id_to_key = self .id_to_key
199
199
if values_are_keys :
200
200
values = [id_to_key [val ] for val in values ]
201
- it = zip (rows , np .lib .stride_tricks .sliding_window_view (indptr , 2 ).tolist ())
201
+ it = zip (rows , np .lib .stride_tricks .sliding_window_view (indptr , 2 ).tolist (), strict = True )
202
202
if use_row_index and use_column_index :
203
203
return {
204
- row : dict (zip (col_indices [start :stop ], values [start :stop ])) for row , (start , stop ) in it
204
+ row : dict (zip (col_indices [start :stop ], values [start :stop ], strict = True ))
205
+ for row , (start , stop ) in it
205
206
}
206
207
if use_row_index :
207
208
return {
208
209
row : {
209
- id_to_key [col ]: val for col , val in zip (col_indices [start :stop ], values [start :stop ])
210
+ id_to_key [col ]: val
211
+ for col , val in zip (col_indices [start :stop ], values [start :stop ], strict = True )
210
212
}
211
213
for row , (start , stop ) in it
212
214
}
213
215
if use_column_index :
214
216
return {
215
- id_to_key [row ]: dict (zip (col_indices [start :stop ], values [start :stop ]))
217
+ id_to_key [row ]: dict (zip (col_indices [start :stop ], values [start :stop ], strict = True ))
216
218
for row , (start , stop ) in it
217
219
}
218
220
return {
219
221
id_to_key [row ]: {
220
- id_to_key [col ]: val for col , val in zip (col_indices [start :stop ], values [start :stop ])
222
+ id_to_key [col ]: val
223
+ for col , val in zip (col_indices [start :stop ], values [start :stop ], strict = True )
221
224
}
222
225
for row , (start , stop ) in it
223
226
}
@@ -239,9 +242,9 @@ def to_networkx(self, edge_attribute="weight"):
239
242
rows = (id_to_key [row ] for row in rows .tolist ())
240
243
cols = (id_to_key [col ] for col in cols .tolist ())
241
244
if edge_attribute is None :
242
- G .add_edges_from (zip (rows , cols ))
245
+ G .add_edges_from (zip (rows , cols , strict = True ))
243
246
else :
244
- G .add_weighted_edges_from (zip (rows , cols , vals ), weight = edge_attribute )
247
+ G .add_weighted_edges_from (zip (rows , cols , vals , strict = True ), weight = edge_attribute )
245
248
# What else should we copy over?
246
249
return G
247
250
@@ -258,4 +261,4 @@ def renumber_key_to_id(self, indices):
258
261
return {id_to_key [index ]: i for i , index in enumerate (indices )}
259
262
# Alternative (about the same performance)
260
263
# keys = self.list_to_keys(indices)
261
- # return dict(zip(keys, range(len(indices))))
264
+ # return dict(zip(keys, range(len(indices)), strict=True ))
0 commit comments