67E6
1
1
import ast
2
+ import warnings
3
+
2
4
import numpy as np
3
5
import larray as la
4
6
14
16
15
17
class ComparatorWidget (QWidget ):
16
18
"""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 ):
18
20
QWidget .__init__ (self , parent )
19
21
20
22
layout = QVBoxLayout ()
@@ -179,27 +181,33 @@ def _setup_and_check(self, widget, data, title, readonly, **kwargs):
179
181
----------
180
182
widget: QWidget
181
183
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 .
184
186
title: str
185
187
Title.
186
188
readonly: bool
189
+ Ignored argument (comparator is always read only)
187
190
kwargs:
188
191
189
192
* rtol: int or float
190
193
* atol: int or float
191
194
* nans_equal: bool
192
195
* bg_gradient: str
193
- * names: list of str
194
196
"""
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 ())
197
205
198
206
layout = QVBoxLayout ()
199
207
widget .setLayout (layout )
200
208
201
209
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' ))
203
211
layout .addWidget (comparator_widget )
204
212
205
213
@@ -224,26 +232,29 @@ def _setup_and_check(self, widget, data, title, readonly, **kwargs):
224
232
----------
225
233
widget: QWidget
226
234
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 .
229
237
title: str
230
238
Title.
231
239
readonly: bool
240
+ Ignored argument (comparator is always read only)
232
241
kwargs:
233
242
234
243
* rtol: int or float
235
244
* atol: int or float
236
245
* nans_equal: bool
237
246
* bg_gradient: str
238
- * names: list of str
239
- * colors: str
240
247
"""
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 )
243
254
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' )
247
258
248
259
layout = QVBoxLayout ()
249
260
widget .setLayout (layout )
@@ -260,6 +271,7 @@ def _setup_and_check(self, widget, data, title, readonly, **kwargs):
260
271
self .listwidget = listwidget
261
272
262
273
comparatorwidget = ComparatorWidget (self , ** kwargs )
274
+ # do not call set_data on the comparatorwidget as it will be done by the setCurrentRow below
263
275
self .arraywidget = comparatorwidget
264
276
265
277
main_splitter = QSplitter (Qt .Horizontal )
0 commit comments