11import ast
2+ import warnings
3+
24import numpy as np
35import larray as la
46
1416
1517class ComparatorWidget (QWidget ):
1618 """Comparator Widget"""
17- def __init__ (self , parent = None , bg_gradient = 'red-white-blue' , rtol = 0 , atol = 0 , nans_equal = True , ** kwargs ):
19+ def __init__ (self , parent = None , bg_gradient = 'red-white-blue' , rtol = 0 , atol = 0 , nans_equal = True ):
1820 QWidget .__init__ (self , parent )
1921
2022 layout = QVBoxLayout ()
@@ -179,27 +181,33 @@ def _setup_and_check(self, widget, data, title, readonly, **kwargs):
179181 ----------
180182 widget: QWidget
181183 Parent widget.
182- data: list or tuple of Array, ndarray
183- Arrays to compare.
184+ data: dict of Array
185+ Arrays to compare as a {name: Array} dict .
184186 title: str
185187 Title.
186188 readonly: bool
189+ Ignored argument (comparator is always read only)
187190 kwargs:
188191
189192 * rtol: int or float
190193 * atol: int or float
191194 * nans_equal: bool
192195 * bg_gradient: str
193- * names: list of str
194196 """
195- arrays = [la .asarray (array ) for array in data if isinstance (array , DISPLAY_IN_GRID )]
196- names = kwargs .get ('names' , [f"Array{ i } " for i in range (len (arrays ))])
197+ if isinstance (data , (list , tuple )):
198+ names = kwargs .pop ('names' , [f"Array{ i } " for i in range (len (data ))])
199+ data = dict (zip (names , data ))
200+ warnings .warn ("For ArrayComparator.setup_and_check, using a list or tuple for the data argument, "
201+ "and using the names argument are both deprecated. Please use a dict instead" ,
202+ FutureWarning , stacklevel = 3 )
203+
204+ assert all (isinstance (s , la .Array ) for s in data .values ())
197205
198206 layout = QVBoxLayout ()
199207 widget .setLayout (layout )
200208
201209 comparator_widget = ComparatorWidget (self , ** kwargs )
202- comparator_widget .set_data (arrays , la .Axis (names , 'array' ))
210+ comparator_widget .set_data (data . values () , la .Axis (data . keys () , 'array' ))
203211 layout .addWidget (comparator_widget )
204212
205213
@@ -224,26 +232,29 @@ def _setup_and_check(self, widget, data, title, readonly, **kwargs):
224232 ----------
225233 widget: QWidget
226234 Parent widget.
227- data: list or tuple of Session
228- Sessions to compare.
235+ data: dict of Session
236+ Sessions to compare as a {name: Session} dict .
229237 title: str
230238 Title.
231239 readonly: bool
240+ Ignored argument (comparator is always read only)
232241 kwargs:
233242
234243 * rtol: int or float
235244 * atol: int or float
236245 * nans_equal: bool
237246 * bg_gradient: str
238- * names: list of str
239- * colors: str
240247 """
241- sessions = data
242- names = kwargs .get ('names' , [f"Session{ i } " for i in range (len (sessions ))])
248+ if isinstance (data , (list , tuple )):
249+ names = kwargs .pop ('names' , [f"Session{ i } " for i in range (len (data ))])
250+ data = dict (zip (names , data ))
251+ warnings .warn ("For SessionComparator.setup_and_check, using a list or tuple for the data argument, "
252+ "and using the names argument are both deprecated. Please use a dict instead" ,
253+ FutureWarning , stacklevel = 3 )
243254
244- assert all (isinstance (s , la .Session ) for s in sessions )
245- self .sessions = sessions
246- self .stack_axis = la .Axis (names , 'session' )
255+ assert all (isinstance (s , la .Session ) for s in data . values () )
256+ self .sessions = data . values ()
257+ self .stack_axis = la .Axis (data . keys () , 'session' )
247258
248259 layout = QVBoxLayout ()
249260 widget .setLayout (layout )
@@ -260,6 +271,7 @@ def _setup_and_check(self, widget, data, title, readonly, **kwargs):
260271 self .listwidget = listwidget
261272
262273 comparatorwidget = ComparatorWidget (self , ** kwargs )
274+ # do not call set_data on the comparatorwidget as it will be done by the setCurrentRow below
263275 self .arraywidget = comparatorwidget
264276
265277 main_splitter = QSplitter (Qt .Horizontal )
0 commit comments