@@ -61,7 +61,7 @@ def dict_to_vector(self, d, *, size=None, dtype=None, name=None):
6161 if size is None :
6262 size = len (self )
6363 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 )
6565 return Vector .from_coo (indices , values , size = size , dtype = dtype , name = name )
6666
6767
@@ -116,7 +116,7 @@ def vector_to_dict(self, v, *, mask=None, fill_value=None):
116116 elif fill_value is not None and v .nvals < v .size :
117117 v (mask = ~ v .S ) << fill_value
118118 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 )}
120120
121121
122122def 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
198198 id_to_key = self .id_to_key
199199 if values_are_keys :
200200 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 )
202202 if use_row_index and use_column_index :
203203 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
205206 }
206207 if use_row_index :
207208 return {
208209 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 )
210212 }
211213 for row , (start , stop ) in it
212214 }
213215 if use_column_index :
214216 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 ))
216218 for row , (start , stop ) in it
217219 }
218220 return {
219221 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 )
221224 }
222225 for row , (start , stop ) in it
223226 }
@@ -239,9 +242,9 @@ def to_networkx(self, edge_attribute="weight"):
239242 rows = (id_to_key [row ] for row in rows .tolist ())
240243 cols = (id_to_key [col ] for col in cols .tolist ())
241244 if edge_attribute is None :
242- G .add_edges_from (zip (rows , cols ))
245+ G .add_edges_from (zip (rows , cols , strict = True ))
243246 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 )
245248 # What else should we copy over?
246249 return G
247250
@@ -258,4 +261,4 @@ def renumber_key_to_id(self, indices):
258261 return {id_to_key [index ]: i for i , index in enumerate (indices )}
259262 # Alternative (about the same performance)
260263 # 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