Skip to content

Commit e095d9d

Browse files
committed
FIX: revert part of commit 6e0baca to avoid regression with duplicate names (closes #247)
1 parent 9217b31 commit e095d9d

File tree

3 files changed

+26
-29
lines changed

3 files changed

+26
-29
lines changed

larray_editor/api.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,7 @@ def get_name(i, obj, depth=0):
213213
args = [la.Session(a) if not isinstance(a, la.Session) else a
214214
for a in args]
215215

216-
data = dict(zip(names, args))
217-
218-
if dlg.setup_and_check(data, title=title, caller_info=caller_info, **kwargs):
216+
if dlg.setup_and_check(args, names=names, title=title, caller_info=caller_info, **kwargs):
219217
return dlg
220218
else:
221219
return None

larray_editor/comparator.py

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ def _setup_and_check(self, widget, data, title, readonly, **kwargs):
183183
----------
184184
widget: QWidget
185185
Parent widget.
186-
data: dict of Array
187-
Arrays to compare as a {name: Array} dict.
186+
data: list or tuple of Array or ndarray
187+
Arrays to compare.
188188
title: str
189189
Title.
190190
readonly: bool
@@ -195,21 +195,16 @@ def _setup_and_check(self, widget, data, title, readonly, **kwargs):
195195
* atol: int or float
196196
* nans_equal: bool
197197
* bg_gradient: str
198+
* names: list of str
198199
"""
199-
if isinstance(data, (list, tuple)):
200-
names = kwargs.pop('names', [f"Array{i}" for i in range(len(data))])
201-
data = dict(zip(names, data))
202-
warnings.warn("For ArrayComparator.setup_and_check, using a list or tuple for the data argument, "
203-
"and using the names argument are both deprecated. Please use a dict instead",
204-
FutureWarning, stacklevel=3)
205-
206-
assert all(isinstance(s, la.Array) for s in data.values())
200+
arrays = [la.asarray(array) for array in data if isinstance(array, DISPLAY_IN_GRID)]
201+
names = kwargs.pop('names', [f"Array{i}" for i in range(len(arrays))])
207202

208203
layout = QVBoxLayout()
209204
widget.setLayout(layout)
210205

211206
comparator_widget = ComparatorWidget(self, **kwargs)
212-
comparator_widget.set_data(data.values(), la.Axis(data.keys(), 'array'))
207+
comparator_widget.set_data(arrays, la.Axis(names, 'array'))
213208
layout.addWidget(comparator_widget)
214209

215210

@@ -234,8 +229,8 @@ def _setup_and_check(self, widget, data, title, readonly, **kwargs):
234229
----------
235230
widget: QWidget
236231
Parent widget.
237-
data: dict of Session
238-
Sessions to compare as a {name: Session} dict.
232+
data: list or tuple of Session
233+
Sessions to compare.
239234
title: str
240235
Title.
241236
readonly: bool
@@ -246,17 +241,14 @@ def _setup_and_check(self, widget, data, title, readonly, **kwargs):
246241
* atol: int or float
247242
* nans_equal: bool
248243
* bg_gradient: str
244+
* names: list of str
249245
"""
250-
if isinstance(data, (list, tuple)):
251-
names = kwargs.pop('names', [f"Session{i}" for i in range(len(data))])
252-
data = dict(zip(names, data))
253-
warnings.warn("For SessionComparator.setup_and_check, using a list or tuple for the data argument, "
254-
"and using the names argument are both deprecated. Please use a dict instead",
255-
FutureWarning, stacklevel=3)
256-
257-
assert all(isinstance(s, la.Session) for s in data.values())
258-
self.sessions = data.values()
259-
self.stack_axis = la.Axis(data.keys(), 'session')
246+
sessions = data
247+
names = kwargs.pop('names', [f"Session{i}" for i in range(len(sessions))])
248+
249+
assert all(isinstance(s, la.Session) for s in sessions)
250+
self.sessions = sessions
251+
self.stack_axis = la.Axis(names, 'session')
260252

261253
layout = QVBoxLayout()
262254
widget.setLayout(layout)

larray_editor/tests/test_api_larray.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,16 @@ def make_demo(width=20, ball_radius=5, path_radius=5, steps=30):
144144

145145
# edit(arr2)
146146

147+
# test issue #247 (same names)
148+
# compare(arr3, arr3)
147149
# compare(arr3, arr3 + 1.0)
148150
# compare(arr3, arr3 + 1.0, names=['arr3', 'arr3 + 1.0'])
149151
# compare(np.random.normal(0, 1, size=(10, 2)), np.random.normal(0, 1, size=(10, 2)))
152+
150153
# sess1 = la.Session(arr4=arr4, arr3=arr3, data=data3)
151154
# sess1.save('sess1.h5')
152155
# sess2 = la.Session(arr4=arr4 + 1.0, arr3=arr3 * 2.0, data=data3 * 1.05)
153-
# compare('sess1.h5', sess2)
156+
# compare('sess1.h5', sess2) # sess1.h5/data is nan because np arrays are not saved to H5
154157
# compare(Path('sess1.h5'), sess2)
155158
# compare(la.Session(arr2=arr2, arr3=arr3),
156159
# la.Session(arr2=arr2 + 1.0, arr3=arr3 * 2.0))
@@ -176,14 +179,18 @@ def make_demo(width=20, ball_radius=5, path_radius=5, steps=30):
176179
# compare(arr1, arr2, rtol=0.3)
177180
#
178181
# arr2 = la.where(arr2 > 1, arr1, -arr1)
182+
# arr1_m = arr1['M'].copy()
179183
# arr1['M'] = la.nan
184+
# compare(arr1, arr2, nans_equal=False, title='with nans on left side')
180185
# arr2['M'] = la.nan
181-
# compare(arr1, arr2, nans_equal=False)
186+
# compare(arr1, arr2, nans_equal=False, title='with nans on both sides')
187+
# arr1['M'] = arr1_m
188+
# compare(arr1, arr2, nans_equal=False, title='with nans on right side')
182189
#
183190
# arr1 = la.ndtest((3, 3))
184191
# arr2 = 2 * arr1
185192
# arr3 = la.where(arr1 % 2 == 0, arr1, -arr1)
186-
# compare(arr1, arr2, arr3, bg_gradient='blue-red')
193+
# compare(arr1, arr2, arr3, bg_gradient='blue-white-red')
187194

188195
# test for arr.plot(show=True) which is the default
189196
# =================================================

0 commit comments

Comments
 (0)