Skip to content

Commit 4755cce

Browse files
Merged in cbillington/lyse/python3 (pull request labscript-suite#41)
Python 3 Approved-by: Jan Werkmann <jan.wrk.fb@gmail.com>
2 parents e87ed37 + 511f93d commit 4755cce

File tree

3 files changed

+18
-37
lines changed

3 files changed

+18
-37
lines changed

__init__.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
# require pandas v0.15.0 up to the next major version
3939
check_version('pandas', '0.15.0', '1.0')
4040
check_version('zprocess', '2.2.0', '3.0')
41-
check_version('labscript_utils', '2.4', '3.0')
41+
check_version('labscript_utils', '2.6', '3.0')
4242
from labscript_utils import PY2
4343
if PY2:
4444
str = unicode
@@ -143,7 +143,7 @@ def set_group(self, groupname):
143143
def trace_names(self):
144144
with h5py.File(self.h5_path) as h5_file:
145145
try:
146-
return h5_file['data']['traces'].keys()
146+
return list(h5_file['data']['traces'].keys())
147147
except KeyError:
148148
return []
149149

@@ -176,7 +176,7 @@ def save_result(self, name, value, group=None, overwrite=True):
176176
elif not group in h5_file:
177177
# Create the group if it doesn't exist
178178
h5_file.create_group(group)
179-
if name in h5_file[group].attrs.keys() and not overwrite:
179+
if name in h5_file[group].attrs and not overwrite:
180180
raise Exception('Attribute %s exists in group %s. ' \
181181
'Use overwrite=True to overwrite.' % (name, group))
182182
h5_file[group].attrs[name] = value
@@ -269,7 +269,7 @@ def get_all_image_labels(self):
269269
images_list = {}
270270
with h5py.File(self.h5_path) as h5_file:
271271
for orientation in h5_file['/images'].keys():
272-
images_list[orientation] = h5_file['/images'][orientation].keys()
272+
images_list[orientation] = list(h5_file['/images'][orientation].keys())
273273
return images_list
274274

275275
def get_image_attributes(self, orientation):
@@ -352,7 +352,7 @@ def append_units(name, obj):
352352
def globals_groups(self):
353353
with h5py.File(self.h5_path) as h5_file:
354354
try:
355-
return h5_file['globals'].keys()
355+
return list(h5_file['globals'].keys())
356356
except KeyError:
357357
return []
358358

__main__.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
except ImportError:
3131
raise ImportError('Require labscript_utils > 2.1.0')
3232

33-
check_version('qtutils', '2.0.0', '3.0.0')
33+
check_version('qtutils', '2.1.0', '3.0.0')
3434

3535
import zprocess.locking
3636
from zprocess import ZMQServer
@@ -190,8 +190,10 @@ def handler(self, request_data):
190190
elif isinstance(request_data, dict):
191191
if 'filepath' in request_data:
192192
h5_filepath = shared_drive.path_to_local(request_data['filepath'])
193-
if not (isinstance(h5_filepath, unicode) or isinstance(h5_filepath, str)):
194-
raise AssertionError(str(type(h5_filepath)) + ' is not str or unicode')
193+
if isinstance(h5_filepath, bytes):
194+
h5_filepath = h5_filepath.decode('utf8')
195+
if not isinstance(h5_filepath, str):
196+
raise AssertionError(str(type(h5_filepath)) + ' is not str or bytes')
195197
app.filebox.incoming_queue.put(h5_filepath)
196198
return 'added successfully'
197199
return ("error: operation not supported. Recognised requests are:\n "
@@ -2016,10 +2018,14 @@ def get_save_data(self):
20162018
save_data = {}
20172019

20182020
box = self.singleshot_routinebox
2019-
save_data['SingleShot'] = zip([routine.filepath for routine in box.routines], [box.model.item(row, box.COL_ACTIVE).checkState() for row in range(box.model.rowCount())])
2021+
save_data['SingleShot'] = list(zip([routine.filepath for routine in box.routines],
2022+
[box.model.item(row, box.COL_ACTIVE).checkState()
2023+
for row in range(box.model.rowCount())]))
20202024
save_data['LastSingleShotFolder'] = box.last_opened_routine_folder
20212025
box = self.multishot_routinebox
2022-
save_data['MultiShot'] = zip([routine.filepath for routine in box.routines], [box.model.item(row, box.COL_ACTIVE).checkState() for row in range(box.model.rowCount())])
2026+
save_data['MultiShot'] = list(zip([routine.filepath for routine in box.routines],
2027+
[box.model.item(row, box.COL_ACTIVE).checkState()
2028+
for row in range(box.model.rowCount())]))
20232029
save_data['LastMultiShotFolder'] = box.last_opened_routine_folder
20242030

20252031
save_data['LastFileBoxFolder'] = self.filebox.last_opened_shots_folder

dataframe_utilities.py

+2-27
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from numpy import *
2323
import tzlocal
2424
import labscript_utils.shared_drive
25+
from labscript_utils.dict_diff import dict_diff
2526

2627
import runmanager
2728

@@ -157,7 +158,7 @@ def flat_dict_to_flat_series(dictionary):
157158
result[key] = dictionary[key]
158159
else:
159160
result[key[0]] = dictionary[key]
160-
keys = result.keys()
161+
keys = list(result.keys())
161162
keys.sort(key = lambda item:
162163
(len(item),) + item if isinstance(item, tuple) else (1,item))
163164
return pandas.Series(result,index=keys)
@@ -220,31 +221,5 @@ def replace_with_padding(df, row, index):
220221
df = df.sort_index()
221222
return df
222223

223-
def dict_diff(dict1, dict2):
224-
"""Return the difference between two dictionaries as a dictionary of key: [val1, val2] pairs.
225-
Keys unique to either dictionary are included as key: [val1, '-'] or key: ['-', val2]."""
226-
diff_keys = []
227-
common_keys = intersect1d(dict1.keys(), dict2.keys())
228-
for key in common_keys:
229-
if iterable(dict1[key]):
230-
if any(dict1[key] != dict2[key]):
231-
diff_keys.append(key)
232-
else:
233-
if dict1[key] != dict2[key]:
234-
diff_keys.append(key)
235-
236-
dict1_unique = [key for key in dict1.keys() if key not in common_keys]
237-
dict2_unique = [key for key in dict2.keys() if key not in common_keys]
238-
239-
diff = {}
240-
for key in diff_keys:
241-
diff[key] = [dict1[key], dict2[key]]
242-
243-
for key in dict1_unique:
244-
diff[key] = [dict1[key], '-']
245-
246-
for key in dict2_unique:
247-
diff[key] = ['-', dict2[key]]
248224

249-
return diff
250225

0 commit comments

Comments
 (0)