From c31276b89cebdbfb4658f2442b52fc59c11170e2 Mon Sep 17 00:00:00 2001 From: zariiii9003 <52598363+zariiii9003@users.noreply.github.com> Date: Tue, 12 Dec 2023 19:26:56 +0100 Subject: [PATCH 1/5] activate flake8-comprehensions --- .pre-commit-config.yaml | 4 +- pyproject.toml | 1 + src/asammdf/blocks/mdf_v3.py | 4 +- src/asammdf/blocks/mdf_v4.py | 4 +- src/asammdf/blocks/utils.py | 2 +- src/asammdf/blocks/v2_v3_blocks.py | 10 +- .../gui/dialogs/bus_database_manager.py | 4 +- src/asammdf/gui/dialogs/multi_search.py | 4 +- src/asammdf/gui/utils.py | 4 +- src/asammdf/gui/widgets/batch.py | 4 +- src/asammdf/gui/widgets/cursor.py | 22 +- src/asammdf/gui/widgets/file.py | 12 +- src/asammdf/gui/widgets/functions_manager.py | 2 +- src/asammdf/gui/widgets/mdi_area.py | 30 +- src/asammdf/gui/widgets/numeric.py | 10 +- src/asammdf/gui/widgets/plot.py | 351 +++++++++--------- src/asammdf/gui/widgets/tabular_base.py | 7 +- src/asammdf/mdf.py | 27 +- .../gui/widgets/test_BaseFileWidget.py | 9 +- .../widgets/test_FileWidget_TabChannels.py | 7 +- .../test_FileWidget_TabModifyAndExport.py | 2 +- test/test_mdf.py | 2 +- 22 files changed, 250 insertions(+), 272 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5b4088f53..41c253802 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,10 +1,10 @@ repos: - repo: https://github.com/ambv/black - rev: 23.11.0 + rev: 23.12.0 hooks: - id: black - repo: https://github.com/charliermarsh/ruff-pre-commit # Ruff version. - rev: v0.1.6 + rev: v0.1.7 hooks: - id: ruff \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 9ab96d380..926812ab2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,6 +24,7 @@ skip = "pp* *_ppc64le *-musllinux* *_s390x" # skip pypy and irrelevant archite [tool.ruff] select = [ "B", # flake8-bugbear + "C4", # flake8-comprehensions "F", # pyflakes "UP", # pyupgrade "I", # isort diff --git a/src/asammdf/blocks/mdf_v3.py b/src/asammdf/blocks/mdf_v3.py index a8704a7bb..07af9969a 100644 --- a/src/asammdf/blocks/mdf_v3.py +++ b/src/asammdf/blocks/mdf_v3.py @@ -3009,7 +3009,7 @@ def get( size = byte_size vals_dtype = vals.dtype.kind - if vals_dtype not in "ui" and (bit_offset or not bits == size * 8): + if vals_dtype not in "ui" and (bit_offset or bits != size * 8): vals = self._get_not_byte_aligned_data(data_bytes, grp, ch_nr) else: dtype_ = vals.dtype @@ -3285,7 +3285,7 @@ def get_master( if time_b: t += time_b - if not t.dtype == float64: + if t.dtype != float64: t = t.astype(float64) self._master_channel_metadata[index] = metadata diff --git a/src/asammdf/blocks/mdf_v4.py b/src/asammdf/blocks/mdf_v4.py index 6a36b8405..aee630350 100644 --- a/src/asammdf/blocks/mdf_v4.py +++ b/src/asammdf/blocks/mdf_v4.py @@ -155,7 +155,7 @@ COMMON_SHORT_u = v4c.COMMON_SHORT_u VALID_DATA_TYPES = v4c.VALID_DATA_TYPES -EMPTY_TUPLE = tuple() +EMPTY_TUPLE = () # 100 extra steps for the sorting, 1 step after sorting and 1 step at finish SORT_STEPS = 102 @@ -8288,7 +8288,7 @@ def get_master( self._master_channel_metadata[index] = metadata - if not t.dtype == float64: + if t.dtype != float64: t = t.astype(float64) if raster and t.size: diff --git a/src/asammdf/blocks/utils.py b/src/asammdf/blocks/utils.py index 3c6c337a8..e17c904ca 100644 --- a/src/asammdf/blocks/utils.py +++ b/src/asammdf/blocks/utils.py @@ -120,7 +120,7 @@ def detect(text: bytes) -> DetectDict: BLK_COMMON_uf = Struct("<4s4xQ").unpack_from BLK_COMMON_u = Struct("<4s4xQ8x").unpack -EMPTY_TUPLE = tuple() +EMPTY_TUPLE = () _xmlns_pattern = re.compile(' xmlns="[^"]*"') diff --git a/src/asammdf/blocks/v2_v3_blocks.py b/src/asammdf/blocks/v2_v3_blocks.py index 1c53d8129..0038c2b8a 100644 --- a/src/asammdf/blocks/v2_v3_blocks.py +++ b/src/asammdf/blocks/v2_v3_blocks.py @@ -985,7 +985,7 @@ def __init__(self, **kwargs) -> None: if conv_type == v23c.CONVERSION_TYPE_LINEAR: (self.b, self.a) = unpack_from("<2d", block, v23c.CC_COMMON_SHORT_SIZE) - if not size == v23c.CC_LIN_BLOCK_SIZE: + if size != v23c.CC_LIN_BLOCK_SIZE: self.CANapeHiddenExtra = block[v23c.CC_LIN_BLOCK_SIZE - 4 :] size = len(self.CANapeHiddenExtra) nr = size // 40 @@ -1151,7 +1151,7 @@ def __init__(self, **kwargs) -> None: self.ref_param_nr = 2 self.b = kwargs.get("b", 0) self.a = kwargs.get("a", 1) - if not self.block_len == v23c.CC_LIN_BLOCK_SIZE: + if self.block_len != v23c.CC_LIN_BLOCK_SIZE: self.CANapeHiddenExtra = kwargs["CANapeHiddenExtra"] elif kwargs["conversion_type"] in ( @@ -1323,7 +1323,7 @@ def metadata(self, indent: str = "") -> str: keys = v23c.KEYS_CONVERSION_FORMULA elif conv == v23c.CONVERSION_TYPE_LINEAR: keys = v23c.KEYS_CONVERSION_LINEAR - if not self.block_len == v23c.CC_LIN_BLOCK_SIZE: + if self.block_len != v23c.CC_LIN_BLOCK_SIZE: keys += ("CANapeHiddenExtra",) nr = self.ref_param_nr @@ -1640,7 +1640,7 @@ def __bytes__(self) -> bytes: fmt = v23c.FMT_CONVERSION_FORMULA.format(self.block_len - v23c.CC_COMMON_BLOCK_SIZE) elif conv == v23c.CONVERSION_TYPE_LINEAR: fmt = v23c.FMT_CONVERSION_LINEAR - if not self.block_len == v23c.CC_LIN_BLOCK_SIZE: + if self.block_len != v23c.CC_LIN_BLOCK_SIZE: fmt += f"{self.block_len - v23c.CC_LIN_BLOCK_SIZE}s" elif conv in (v23c.CONVERSION_TYPE_POLY, v23c.CONVERSION_TYPE_RAT): fmt = v23c.FMT_CONVERSION_POLY_RAT @@ -1662,7 +1662,7 @@ def __bytes__(self) -> bytes: keys = v23c.KEYS_CONVERSION_FORMULA elif conv == v23c.CONVERSION_TYPE_LINEAR: keys = v23c.KEYS_CONVERSION_LINEAR - if not self.block_len == v23c.CC_LIN_BLOCK_SIZE: + if self.block_len != v23c.CC_LIN_BLOCK_SIZE: keys += ("CANapeHiddenExtra",) elif conv in (v23c.CONVERSION_TYPE_POLY, v23c.CONVERSION_TYPE_RAT): keys = v23c.KEYS_CONVERSION_POLY_RAT diff --git a/src/asammdf/gui/dialogs/bus_database_manager.py b/src/asammdf/gui/dialogs/bus_database_manager.py index 6cd89f409..4e8a1c79a 100644 --- a/src/asammdf/gui/dialogs/bus_database_manager.py +++ b/src/asammdf/gui/dialogs/bus_database_manager.py @@ -25,13 +25,13 @@ def __init__( buses = can_databases[::2] dbs = can_databases[1::2] - databases["CAN"] = [(bus, database) for bus, database in zip(buses, dbs)] + databases["CAN"] = list(zip(buses, dbs)) lin_databases = self._settings.value("lin_databases", []) buses = lin_databases[::2] dbs = lin_databases[1::2] - databases["LIN"] = [(bus, database) for bus, database in zip(buses, dbs)] + databases["LIN"] = list(zip(buses, dbs)) self.widget = BusDatabaseManager(databases) diff --git a/src/asammdf/gui/dialogs/multi_search.py b/src/asammdf/gui/dialogs/multi_search.py index 6bb868d59..9f135bcb9 100644 --- a/src/asammdf/gui/dialogs/multi_search.py +++ b/src/asammdf/gui/dialogs/multi_search.py @@ -82,9 +82,9 @@ def search_text_changed(self): def _add(self, event): count = self.selection.count() - names = set(self.selection.item(i).text() for i in range(count)) + names = {self.selection.item(i).text() for i in range(count)} - to_add = set(item.text() for item in self.matches.selectedItems()) + to_add = {item.text() for item in self.matches.selectedItems()} names = names | to_add diff --git a/src/asammdf/gui/utils.py b/src/asammdf/gui/utils.py index 2cc229b01..5a5d2a205 100644 --- a/src/asammdf/gui/utils.py +++ b/src/asammdf/gui/utils.py @@ -504,7 +504,7 @@ def compute_signal( samples = [] for values in zip(*signals): try: - current_sample = func(**{arg_name: arg_val for arg_name, arg_val in zip(names, values)}) + current_sample = func(**dict(zip(names, values))) except: current_sample = COMPUTED_FUNCTION_ERROR_VALUE samples.append(current_sample) @@ -536,7 +536,7 @@ def compute_signal( names.extend(not_found) signals.extend(not_found_signals) - samples = func(**{arg_name: arg_signal for arg_name, arg_signal in zip(names, signals)}) + samples = func(**dict(zip(names, signals))) if len(samples) != len(common_timebase): common_timebase = common_timebase[-len(samples) :] diff --git a/src/asammdf/gui/widgets/batch.py b/src/asammdf/gui/widgets/batch.py index 646eab71e..832199e16 100644 --- a/src/asammdf/gui/widgets/batch.py +++ b/src/asammdf/gui/widgets/batch.py @@ -144,13 +144,13 @@ def __init__( buses = can_databases[::2] dbs = can_databases[1::2] - databases["CAN"] = [(bus, database) for bus, database in zip(buses, dbs)] + databases["CAN"] = list(zip(buses, dbs)) lin_databases = self._settings.value("lin_databases", []) buses = lin_databases[::2] dbs = lin_databases[1::2] - databases["LIN"] = [(bus, database) for bus, database in zip(buses, dbs)] + databases["LIN"] = list(zip(buses, dbs)) for bus, database in databases["CAN"]: item = QtWidgets.QListWidgetItem() diff --git a/src/asammdf/gui/widgets/cursor.py b/src/asammdf/gui/widgets/cursor.py index 0cd9ade3b..7a804940a 100644 --- a/src/asammdf/gui/widgets/cursor.py +++ b/src/asammdf/gui/widgets/cursor.py @@ -426,17 +426,17 @@ def __init__( # note LinearRegionItem.Horizontal and LinearRegionItem.Vertical # are kept for backward compatibility. - lineKwds = dict( - movable=movable, - bounds=bounds, - span=span, - pen=pen, - hoverPen=hoverPen, - show_circle=show_circle, - show_horizontal_line=show_horizontal_line, - line_width=line_width, - color=pen, - ) + lineKwds = { + "movable": movable, + "bounds": bounds, + "span": span, + "pen": pen, + "hoverPen": hoverPen, + "show_circle": show_circle, + "show_horizontal_line": show_horizontal_line, + "line_width": line_width, + "color": pen, + } self.lines = [ Cursor(QtCore.QPointF(values[0], 0), angle=90, **lineKwds), diff --git a/src/asammdf/gui/widgets/file.py b/src/asammdf/gui/widgets/file.py index 5ff969e3b..8465b1633 100644 --- a/src/asammdf/gui/widgets/file.py +++ b/src/asammdf/gui/widgets/file.py @@ -212,7 +212,7 @@ def __init__( try: float(units[0]) except: - units = {name: unit for name, unit in zip(names, units)} + units = dict(zip(names, units)) else: csv.seek(0) csv.readline() @@ -476,13 +476,13 @@ def __init__( buses = can_databases[::2] dbs = can_databases[1::2] - databases["CAN"] = [(bus, database) for bus, database in zip(buses, dbs)] + databases["CAN"] = list(zip(buses, dbs)) lin_databases = self._settings.value("lin_databases", []) buses = lin_databases[::2] dbs = lin_databases[1::2] - databases["LIN"] = [(bus, database) for bus, database in zip(buses, dbs)] + databases["LIN"] = list(zip(buses, dbs)) for bus, database in databases["CAN"]: item = QtWidgets.QListWidgetItem() @@ -836,7 +836,7 @@ def search(self, event=None): iterator += 1 - names = set((_name, *entry) for entry, _name in result.items()) + names = {(_name, *entry) for entry, _name in result.items()} signals = signals | names @@ -2475,9 +2475,9 @@ def autofit_sub_plots(self): geometry = window.geometry() geometries.append(geometry) - if len(set((g.width(), g.x()) for g in geometries)) == 1: + if len({(g.width(), g.x()) for g in geometries}) == 1: self.mdi_area.tile_vertically() - elif len(set((g.height(), g.y()) for g in geometries)) == 1: + elif len({(g.height(), g.y()) for g in geometries}) == 1: self.mdi_area.tile_horizontally() else: self.mdi_area.tileSubWindows() diff --git a/src/asammdf/gui/widgets/functions_manager.py b/src/asammdf/gui/widgets/functions_manager.py index 3f0365b36..8e08cdadd 100644 --- a/src/asammdf/gui/widgets/functions_manager.py +++ b/src/asammdf/gui/widgets/functions_manager.py @@ -133,7 +133,7 @@ def check_syntax(self, silent=False): def definitions_deleted(self, deleted): count = self.functions_list.count() - names = set(self.functions_list.item(row).text() for row in range(count)) + names = {self.functions_list.item(row).text() for row in range(count)} deleted = [name for name in self.definitions if name not in names] diff --git a/src/asammdf/gui/widgets/mdi_area.py b/src/asammdf/gui/widgets/mdi_area.py index c3074a92f..5885ea50e 100644 --- a/src/asammdf/gui/widgets/mdi_area.py +++ b/src/asammdf/gui/widgets/mdi_area.py @@ -697,7 +697,7 @@ def add_new_channels(self, names, widget, mime_data=None): entries = get_flatten_entries_from_mime(mime_data) - uuids = set(entry["origin_uuid"] for entry in entries) + uuids = {entry["origin_uuid"] for entry in entries} for uuid in uuids: if self.file_by_uuid(uuid): break @@ -709,7 +709,7 @@ def add_new_channels(self, names, widget, mime_data=None): computed = [entry for entry in entries if (entry["group_index"], entry["channel_index"]) == (-1, -1)] - uuids = set(entry["origin_uuid"] for entry in entries) + uuids = {entry["origin_uuid"] for entry in entries} if isinstance(widget, Tabular): dfs = [] @@ -1873,7 +1873,7 @@ def _add_numeric_window(self, names): else: flatten_entries = get_flatten_entries_from_mime(names) - uuids = set(entry["origin_uuid"] for entry in flatten_entries) + uuids = {entry["origin_uuid"] for entry in flatten_entries} for uuid in uuids: if self.file_by_uuid(uuid): @@ -1883,12 +1883,12 @@ def _add_numeric_window(self, names): flatten_entries = get_flatten_entries_from_mime(names) signals_ = [ - entry for entry in flatten_entries if tuple((entry["group_index"], entry["channel_index"])) != (-1, -1) + entry for entry in flatten_entries if (entry["group_index"], entry["channel_index"]) != (-1, -1) ] signals_ = natsorted(signals_) - uuids = set(entry["origin_uuid"] for entry in signals_) + uuids = {entry["origin_uuid"] for entry in signals_} signals = [] @@ -2070,7 +2070,7 @@ def _add_plot_window(self, signals, disable_new_channels=False): mime_data = signals flatten_entries = get_flatten_entries_from_mime(mime_data) - uuids = set(entry["origin_uuid"] for entry in flatten_entries) + uuids = {entry["origin_uuid"] for entry in flatten_entries} for uuid in uuids: if self.file_by_uuid(uuid): @@ -2100,7 +2100,7 @@ def _add_plot_window(self, signals, disable_new_channels=False): if (entry["group_index"], entry["channel_index"]) == (-1, -1) } - uuids = set(entry["origin_uuid"] for entry in signals_.values()) + uuids = {entry["origin_uuid"] for entry in signals_.values()} signals = {} @@ -2502,7 +2502,7 @@ def _add_tabular_window(self, names): else: flatten_entries = get_flatten_entries_from_mime(names) - uuids = set(entry["origin_uuid"] for entry in flatten_entries) + uuids = {entry["origin_uuid"] for entry in flatten_entries} for uuid in uuids: if self.file_by_uuid(uuid): @@ -2514,12 +2514,12 @@ def _add_tabular_window(self, names): signals_ = [ entry for entry in flatten_entries - if tuple((entry["group_index"], entry["channel_index"])) != (NOT_FOUND, NOT_FOUND) + if (entry["group_index"], entry["channel_index"]) != (NOT_FOUND, NOT_FOUND) ] signals_ = natsorted(signals_) - uuids = set(entry["origin_uuid"] for entry in signals_) + uuids = {entry["origin_uuid"] for entry in signals_} dfs = [] ranges = {} @@ -2875,8 +2875,8 @@ def _load_numeric_window(self, window_info): signals = natsorted(signals, key=lambda x: x.name) - found = set(sig.name for sig in signals) - required = set(description["name"] for description in required) + found = {sig.name for sig in signals} + required = {description["name"] for description in required} not_found = [Signal([], [], name=name) for name in sorted(required - found)] uuid = os.urandom(6).hex() for sig in not_found: @@ -2940,7 +2940,7 @@ def _load_numeric_window(self, window_info): sections_width = window_info["configuration"].get("header_sections_width", []) if sections_width: - sections_width = reversed([(i, width) for i, width in enumerate(sections_width)]) + sections_width = reversed(list(enumerate(sections_width))) for column_index, width in sections_width: numeric.channels.columnHeader.setColumnWidth(column_index, width) numeric.channels.dataView.setColumnWidth( @@ -3126,7 +3126,7 @@ def _load_plot_window(self, window_info): plot_signals[sig_uuid] = signal - measured_signals.update({name: sig for name, sig in new_matrix_signals.items()}) + measured_signals.update(new_matrix_signals) if measured_signals: all_timebase = np.unique(np.concatenate([sig.timestamps for sig in measured_signals.values()])) @@ -3785,7 +3785,7 @@ def update_functions(self, original_definitions, modified_definitions): for info in new_functions: self.functions[info["name"]] = info["definition"] - new = set(info["name"] for info in new_functions) + new = {info["name"] for info in new_functions} # changed definitions translation = {} diff --git a/src/asammdf/gui/widgets/numeric.py b/src/asammdf/gui/widgets/numeric.py index 201439879..856491f22 100644 --- a/src/asammdf/gui/widgets/numeric.py +++ b/src/asammdf/gui/widgets/numeric.py @@ -594,7 +594,7 @@ def set_format(self, fmt, indexes): self.format = fmt - rows = set(index.row() for index in indexes) + rows = {index.row() for index in indexes} self.backend.set_format(fmt, rows) @@ -648,7 +648,7 @@ def keyPressEvent(self, event): modifiers = event.modifiers() if key == QtCore.Qt.Key.Key_Delete and modifiers == QtCore.Qt.KeyboardModifier.NoModifier: - selected_items = set(index.row() for index in self.selectedIndexes() if index.isValid()) + selected_items = {index.row() for index in self.selectedIndexes() if index.isValid()} for row in reversed(list(selected_items)): signal = self.backend.signals.pop(row) @@ -657,7 +657,7 @@ def keyPressEvent(self, event): self.backend.update() elif key == QtCore.Qt.Key.Key_R and modifiers == QtCore.Qt.KeyboardModifier.ControlModifier: - selected_items = set(index.row() for index in self.selectedIndexes() if index.isValid()) + selected_items = {index.row() for index in self.selectedIndexes() if index.isValid()} if selected_items: ranges = [] @@ -687,7 +687,7 @@ def keyPressEvent(self, event): modifiers == (QtCore.Qt.KeyboardModifier.ControlModifier | QtCore.Qt.KeyboardModifier.ShiftModifier) and key == QtCore.Qt.Key.Key_C ): - selected_items = set(index.row() for index in self.selectedIndexes() if index.isValid()) + selected_items = {index.row() for index in self.selectedIndexes() if index.isValid()} if not selected_items: return @@ -711,7 +711,7 @@ def keyPressEvent(self, event): and key == QtCore.Qt.Key.Key_V ): info = QtWidgets.QApplication.instance().clipboard().text() - selected_items = set(index.row() for index in self.selectedIndexes() if index.isValid()) + selected_items = {index.row() for index in self.selectedIndexes() if index.isValid()} if not selected_items: return diff --git a/src/asammdf/gui/widgets/plot.py b/src/asammdf/gui/widgets/plot.py index f395a04f9..91010d486 100644 --- a/src/asammdf/gui/widgets/plot.py +++ b/src/asammdf/gui/widgets/plot.py @@ -1719,69 +1719,64 @@ def __init__( self.channel_selection.itemExpanded.connect(self.update_current_values) self.channel_selection.verticalScrollBar().valueChanged.connect(self.update_current_values) - self.keyboard_events = ( - set( - [ - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.NoModifier, - QtCore.Qt.Key.Key_M, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.NoModifier, - QtCore.Qt.Key.Key_C, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ControlModifier, - QtCore.Qt.Key.Key_C, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ControlModifier, - QtCore.Qt.Key.Key_B, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ControlModifier, - QtCore.Qt.Key.Key_H, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ControlModifier, - QtCore.Qt.Key.Key_P, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ControlModifier, - QtCore.Qt.Key.Key_T, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ControlModifier, - QtCore.Qt.Key.Key_G, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.NoModifier, - QtCore.Qt.Key.Key_2, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.NoModifier, - QtCore.Qt.Key.Key_BracketLeft, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.NoModifier, - QtCore.Qt.Key.Key_BracketRight, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.NoModifier, - QtCore.Qt.Key.Key_Backspace, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ShiftModifier, - QtCore.Qt.Key.Key_Backspace, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ShiftModifier, - QtCore.Qt.Key.Key_W, - ).toCombined(), - ] - ) - | self.plot.keyboard_events - ) + self.keyboard_events = { + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.NoModifier, + QtCore.Qt.Key.Key_M, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.NoModifier, + QtCore.Qt.Key.Key_C, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ControlModifier, + QtCore.Qt.Key.Key_C, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ControlModifier, + QtCore.Qt.Key.Key_B, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ControlModifier, + QtCore.Qt.Key.Key_H, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ControlModifier, + QtCore.Qt.Key.Key_P, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ControlModifier, + QtCore.Qt.Key.Key_T, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ControlModifier, + QtCore.Qt.Key.Key_G, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.NoModifier, + QtCore.Qt.Key.Key_2, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.NoModifier, + QtCore.Qt.Key.Key_BracketLeft, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.NoModifier, + QtCore.Qt.Key.Key_BracketRight, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.NoModifier, + QtCore.Qt.Key.Key_Backspace, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ShiftModifier, + QtCore.Qt.Key.Key_Backspace, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ShiftModifier, + QtCore.Qt.Key.Key_W, + ).toCombined(), + } | self.plot.keyboard_events self.splitter.splitterMoved.connect(self.set_splitter) @@ -3731,118 +3726,116 @@ def plot_item_mouseReleaseEvent(event): self.viewbox.sigXRangeChanged.connect(self.xrange_changed.emit) - self.keyboard_events = set( - [ - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.NoModifier, - QtCore.Qt.Key.Key_F, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ShiftModifier, - QtCore.Qt.Key.Key_F, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.NoModifier, - QtCore.Qt.Key.Key_G, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ShiftModifier, - QtCore.Qt.Key.Key_G, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.NoModifier, - QtCore.Qt.Key.Key_I, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.NoModifier, - QtCore.Qt.Key.Key_O, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ShiftModifier, - QtCore.Qt.Key.Key_I, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ShiftModifier, - QtCore.Qt.Key.Key_O, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.NoModifier, - QtCore.Qt.Key.Key_X, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.NoModifier, - QtCore.Qt.Key.Key_R, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ControlModifier, - QtCore.Qt.Key.Key_S, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.NoModifier, - QtCore.Qt.Key.Key_S, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ShiftModifier, - QtCore.Qt.Key.Key_S, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.NoModifier, - QtCore.Qt.Key.Key_Y, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.NoModifier, - QtCore.Qt.Key.Key_Left, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.NoModifier, - QtCore.Qt.Key.Key_Right, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ShiftModifier, - QtCore.Qt.Key.Key_Left, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ShiftModifier, - QtCore.Qt.Key.Key_Right, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ControlModifier, - QtCore.Qt.Key.Key_Left, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ControlModifier, - QtCore.Qt.Key.Key_Right, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ShiftModifier, - QtCore.Qt.Key.Key_Up, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ShiftModifier, - QtCore.Qt.Key.Key_Down, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ShiftModifier, - QtCore.Qt.Key.Key_PageUp, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.ShiftModifier, - QtCore.Qt.Key.Key_PageDown, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.NoModifier, - QtCore.Qt.Key.Key_H, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.NoModifier, - QtCore.Qt.Key.Key_W, - ).toCombined(), - QtCore.QKeyCombination( - QtCore.Qt.KeyboardModifier.NoModifier, - QtCore.Qt.Key.Key_Insert, - ).toCombined(), - ] - ) + self.keyboard_events = { + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.NoModifier, + QtCore.Qt.Key.Key_F, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ShiftModifier, + QtCore.Qt.Key.Key_F, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.NoModifier, + QtCore.Qt.Key.Key_G, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ShiftModifier, + QtCore.Qt.Key.Key_G, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.NoModifier, + QtCore.Qt.Key.Key_I, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.NoModifier, + QtCore.Qt.Key.Key_O, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ShiftModifier, + QtCore.Qt.Key.Key_I, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ShiftModifier, + QtCore.Qt.Key.Key_O, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.NoModifier, + QtCore.Qt.Key.Key_X, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.NoModifier, + QtCore.Qt.Key.Key_R, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ControlModifier, + QtCore.Qt.Key.Key_S, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.NoModifier, + QtCore.Qt.Key.Key_S, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ShiftModifier, + QtCore.Qt.Key.Key_S, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.NoModifier, + QtCore.Qt.Key.Key_Y, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.NoModifier, + QtCore.Qt.Key.Key_Left, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.NoModifier, + QtCore.Qt.Key.Key_Right, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ShiftModifier, + QtCore.Qt.Key.Key_Left, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ShiftModifier, + QtCore.Qt.Key.Key_Right, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ControlModifier, + QtCore.Qt.Key.Key_Left, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ControlModifier, + QtCore.Qt.Key.Key_Right, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ShiftModifier, + QtCore.Qt.Key.Key_Up, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ShiftModifier, + QtCore.Qt.Key.Key_Down, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ShiftModifier, + QtCore.Qt.Key.Key_PageUp, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.ShiftModifier, + QtCore.Qt.Key.Key_PageDown, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.NoModifier, + QtCore.Qt.Key.Key_H, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.NoModifier, + QtCore.Qt.Key.Key_W, + ).toCombined(), + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier.NoModifier, + QtCore.Qt.Key.Key_Insert, + ).toCombined(), + } events = events or [] @@ -4969,11 +4962,11 @@ def keyPressEvent(self, event): ): parent = self.parent().parent() uuids = list( - set( + { item.uuid for item in parent.channel_selection.selectedItems() if item.type() == ChannelsTreeItem.Channel - ) + } ) if not uuids: @@ -5000,11 +4993,11 @@ def keyPressEvent(self, event): ): parent = self.parent().parent() uuids = list( - set( + { item.uuid for item in parent.channel_selection.selectedItems() if item.type() == ChannelsTreeItem.Channel - ) + } ) if not uuids: diff --git a/src/asammdf/gui/widgets/tabular_base.py b/src/asammdf/gui/widgets/tabular_base.py index 4a249b8cf..7b8aa6e49 100644 --- a/src/asammdf/gui/widgets/tabular_base.py +++ b/src/asammdf/gui/widgets/tabular_base.py @@ -462,7 +462,7 @@ def keyPressEvent(self, event): modifiers = event.modifiers() if key == QtCore.Qt.Key.Key_R and modifiers == QtCore.Qt.KeyboardModifier.ControlModifier: - selected_items = set(index.column() for index in self.selectedIndexes() if index.isValid()) + selected_items = {index.column() for index in self.selectedIndexes() if index.isValid()} if selected_items: ranges = [] @@ -1454,10 +1454,7 @@ def add_new_channels(self, signals, mime_data=None): signals.set_index(index, inplace=True) dropped = {} - ranges = { - name: channel_ranges - for name, channel_ranges in zip(self.tree.pgdf.df_unfiltered.columns, self.ranges.values()) - } + ranges = dict(zip(self.tree.pgdf.df_unfiltered.columns, self.ranges.values())) for name_ in signals.columns: col = signals[name_] diff --git a/src/asammdf/mdf.py b/src/asammdf/mdf.py index 27c2b4db8..ffec0e482 100644 --- a/src/asammdf/mdf.py +++ b/src/asammdf/mdf.py @@ -4004,17 +4004,14 @@ def iter_to_dataframe( for gp_index, channel_indexes in self.included_channels(group_index)[group_index].items() for ch_index in channel_indexes ] - signals = [ - signal - for signal in self.select( - channels, - raw=True, - copy_master=False, - record_offset=record_offset, - record_count=record_count, - validate=False, - ) - ] + signals = self.select( + channels, + raw=True, + copy_master=False, + record_offset=record_offset, + record_count=record_count, + validate=False, + ) if not signals: continue @@ -4395,7 +4392,7 @@ def to_dataframe( if ch_index != self.masters_db.get(gp_index, None) ] - signals = [signal for signal in self.select(channels, raw=True, copy_master=False, validate=False)] + signals = self.select(channels, raw=True, copy_master=False, validate=False) if not signals: continue @@ -4791,7 +4788,7 @@ def _extract_can_logging( for i, group in enumerate(self.groups): if ( not group.channel_group.flags & v4c.FLAG_CG_BUS_EVENT - or not group.channel_group.acq_source.bus_type == v4c.BUS_TYPE_CAN + or group.channel_group.acq_source.bus_type != v4c.BUS_TYPE_CAN or not "CAN_DataFrame" in [ch.name for ch in group.channels] ): continue @@ -5129,7 +5126,7 @@ def _extract_lin_logging( for i, group in enumerate(self.groups): if ( not group.channel_group.flags & v4c.FLAG_CG_BUS_EVENT - or not group.channel_group.acq_source.bus_type == v4c.BUS_TYPE_LIN + or group.channel_group.acq_source.bus_type != v4c.BUS_TYPE_LIN or not "LIN_Frame" in [ch.name for ch in group.channels] ): continue @@ -5171,7 +5168,7 @@ def _extract_lin_logging( unique_ids = np.unique(np.core.records.fromarrays([bus_msg_ids, bus_msg_ids])) - total_unique_ids = total_unique_ids | set(tuple(int(e) for e in f) for f in unique_ids) + total_unique_ids = total_unique_ids | {tuple(int(e) for e in f) for f in unique_ids} buses = np.unique(bus_ids) diff --git a/test/asammdf/gui/widgets/test_BaseFileWidget.py b/test/asammdf/gui/widgets/test_BaseFileWidget.py index 17a39e2c5..a9e44708e 100644 --- a/test/asammdf/gui/widgets/test_BaseFileWidget.py +++ b/test/asammdf/gui/widgets/test_BaseFileWidget.py @@ -47,7 +47,7 @@ def setUpFileWidget(self, *args, measurement_file, default): self.widget.showNormal() self.processEvents() - def create_window(self, window_type, channels_names=tuple(), channels_indexes=tuple()): + def create_window(self, window_type, channels_names=(), channels_indexes=()): channel_tree = self.widget.channels_tree channel_tree.clearSelection() for channel in channels_names: @@ -83,12 +83,7 @@ def find_channel(channel_tree, channel_name=None, channel_index=None): return selected_channel def get_subwindows(self): - widget_types = sorted( - map( - lambda w: w.widget().__class__.__name__, - self.widget.mdi_area.subWindowList(), - ) - ) + widget_types = sorted(w.widget().__class__.__name__ for w in self.widget.mdi_area.subWindowList()) return widget_types def load_display_file(self, display_file): diff --git a/test/asammdf/gui/widgets/test_FileWidget_TabChannels.py b/test/asammdf/gui/widgets/test_FileWidget_TabChannels.py index 9aa369920..8c10aa929 100644 --- a/test/asammdf/gui/widgets/test_FileWidget_TabChannels.py +++ b/test/asammdf/gui/widgets/test_FileWidget_TabChannels.py @@ -418,12 +418,7 @@ def test_PushButton_SaveOfflineWindows(self): # Event self.load_display_file(display_file=saved_dspf) self.assertEqual(len(self.widget.mdi_area.subWindowList()), 2) - widget_types = set( - map( - lambda w: w.widget().__class__.__name__, - self.widget.mdi_area.subWindowList(), - ) - ) + widget_types = {w.widget().__class__.__name__ for w in self.widget.mdi_area.subWindowList()} self.assertSetEqual({"Plot"}, widget_types) def test_PushButton_SelectAll(self): diff --git a/test/asammdf/gui/widgets/test_FileWidget_TabModifyAndExport.py b/test/asammdf/gui/widgets/test_FileWidget_TabModifyAndExport.py index 971b4345d..7145b6c5e 100644 --- a/test/asammdf/gui/widgets/test_FileWidget_TabModifyAndExport.py +++ b/test/asammdf/gui/widgets/test_FileWidget_TabModifyAndExport.py @@ -129,4 +129,4 @@ def test_ExportMDF(self): channels = list(self.widget.mdf.channels_db) selected_channels.append("time") - self.assertListEqual(sorted(selected_channels), sorted(list(channels))) + self.assertListEqual(sorted(selected_channels), sorted(channels)) diff --git a/test/test_mdf.py b/test/test_mdf.py index 86e32cca8..9e5efe646 100644 --- a/test/test_mdf.py +++ b/test/test_mdf.py @@ -708,7 +708,7 @@ def test_select(self): selected_signals = input_file.select(channel_list) - target_names = set(s.name for s in selected_signals) + target_names = {s.name for s in selected_signals} self.assertFalse(set(target_names) - set(channel_list)) From c5d14dda45fe53b88af8923e2f7ad1999c6e6c7e Mon Sep 17 00:00:00 2001 From: zariiii9003 <52598363+zariiii9003@users.noreply.github.com> Date: Tue, 12 Dec 2023 19:37:26 +0100 Subject: [PATCH 2/5] activate Ruff-specific rules --- pyproject.toml | 3 +++ setup.py | 2 +- src/asammdf/blocks/mdf_v4.py | 4 ++-- src/asammdf/blocks/v2_v3_constants.py | 2 +- src/asammdf/blocks/v4_constants.py | 4 ++-- src/asammdf/gui/utils.py | 2 +- src/asammdf/gui/widgets/list.py | 2 +- src/asammdf/gui/widgets/mdi_area.py | 2 +- src/asammdf/gui/widgets/tree.py | 2 +- 9 files changed, 13 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 926812ab2..74e01d180 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,11 +28,14 @@ select = [ "F", # pyflakes "UP", # pyupgrade "I", # isort + "RUF", # Ruff-specific rules ] ignore = [ "B007", # unused-loop-control-variable "F401", # unused-import "F841", # unused-variable + "RUF012", # mutable-class-default + "RUF015", # unnecessary-iterable-allocation-for-first-element ] exclude = ["./src/asammdf/gui/ui"] target-version = "py38" diff --git a/setup.py b/setup.py index 5caa64e98..7897a908d 100644 --- a/setup.py +++ b/setup.py @@ -129,7 +129,7 @@ def _get_ext_modules(): include_package_data=True, # Although 'package_data' is the preferred approach, in some case you may # need to place data files outside of your packages. See: - # http://docs.python.org/3.4/distutils/setupscript.html#installing-additional-files # noqa + # http://docs.python.org/3.4/distutils/setupscript.html#installing-additional-files # In this case, 'data_file' will be installed into '/my_data' # data_files=[('my_data', ['data/data_file'])], # To provide executable scripts, use entry points in preference to the diff --git a/src/asammdf/blocks/mdf_v4.py b/src/asammdf/blocks/mdf_v4.py index aee630350..921b7d1a9 100644 --- a/src/asammdf/blocks/mdf_v4.py +++ b/src/asammdf/blocks/mdf_v4.py @@ -4443,7 +4443,7 @@ def _append_dataframe( acq_name: str | None = None, acq_source: Source | None = None, comment: str | None = None, - units: dict[str, str | bytes] = None, + units: dict[str, str | bytes] | None = None, ) -> None: """ Appends a new data group from a Pandas data frame. @@ -6927,7 +6927,7 @@ def _get_array( shape = (shape[0],) + shape[1:][::-1] vals = vals.reshape(shape) - axes = (0,) + tuple(range(len(shape) - 1, 0, -1)) + axes = (0, *tuple(range(len(shape) - 1, 0, -1))) vals = transpose(vals, axes=axes) cycles_nr = len(vals) diff --git a/src/asammdf/blocks/v2_v3_constants.py b/src/asammdf/blocks/v2_v3_constants.py index a26396bf8..805d02df6 100644 --- a/src/asammdf/blocks/v2_v3_constants.py +++ b/src/asammdf/blocks/v2_v3_constants.py @@ -296,7 +296,7 @@ "max_raw_value", "sampling_rate", ) -KEYS_CHANNEL_LONGNAME = KEYS_CHANNEL_SHORT + ("long_name_addr",) +KEYS_CHANNEL_LONGNAME = (*KEYS_CHANNEL_SHORT, "long_name_addr") FMT_CHANNEL_GROUP = "<2sH3I3HI" KEYS_CHANNEL_GROUP = ( diff --git a/src/asammdf/blocks/v4_constants.py b/src/asammdf/blocks/v4_constants.py index d86839316..b06bab822 100644 --- a/src/asammdf/blocks/v4_constants.py +++ b/src/asammdf/blocks/v4_constants.py @@ -657,7 +657,7 @@ FMT_CONVERSION_LINEAR = FMT_CONVERSION_NONE + "2d" CONVERSION_LINEAR_PACK = struct.Struct(FMT_CONVERSION_LINEAR).pack -KEYS_CONVERSION_LINEAR = KEYS_CONVERSION_NONE + ("b", "a") +KEYS_CONVERSION_LINEAR = (*KEYS_CONVERSION_NONE, "b", "a") FMT_CONVERSION_LINEAR_INIT = "<4Q2B3H4d" CONVERSION_LINEAR_INIT_u = struct.Struct(FMT_CONVERSION_LINEAR_INIT).unpack CONVERSION_LINEAR_INIT_uf = struct.Struct(FMT_CONVERSION_LINEAR_INIT).unpack_from @@ -686,7 +686,7 @@ FMT_CONVERSION_RAT = FMT_CONVERSION_NONE + "6d" CONVERSION_RAT_PACK = struct.Struct(FMT_CONVERSION_RAT).pack -KEYS_CONVERSION_RAT = KEYS_CONVERSION_NONE + ("P1", "P2", "P3", "P4", "P5", "P6") +KEYS_CONVERSION_RAT = (*KEYS_CONVERSION_NONE, "P1", "P2", "P3", "P4", "P5", "P6") FMT_CONVERSION_RAT_INIT = "<4Q2B3H8d" diff --git a/src/asammdf/gui/utils.py b/src/asammdf/gui/utils.py index 5a5d2a205..deff25c92 100644 --- a/src/asammdf/gui/utils.py +++ b/src/asammdf/gui/utils.py @@ -444,7 +444,7 @@ def compute_signal( if found_numeric: break - names = found_args + ["t"] + names = [*found_args, "t"] triggering = description.get("triggering", "triggering_on_all") if triggering == "triggering_on_all": diff --git a/src/asammdf/gui/widgets/list.py b/src/asammdf/gui/widgets/list.py index bf696ff29..106ba87e6 100644 --- a/src/asammdf/gui/widgets/list.py +++ b/src/asammdf/gui/widgets/list.py @@ -351,7 +351,7 @@ def open_menu(self, position): widget = self.itemWidget(item) if item in selected_items: uuids.append(widget.uuid) - self.set_time_offset.emit([absolute, offset] + uuids) + self.set_time_offset.emit([absolute, offset, *uuids]) elif action.text() == "Delete (Del)": event = QtGui.QKeyEvent( diff --git a/src/asammdf/gui/widgets/mdi_area.py b/src/asammdf/gui/widgets/mdi_area.py index 5885ea50e..779ea69b9 100644 --- a/src/asammdf/gui/widgets/mdi_area.py +++ b/src/asammdf/gui/widgets/mdi_area.py @@ -3535,7 +3535,7 @@ def _load_tabular_window(self, window_info): w.setWindowTitle(generate_window_title(w, window_info["type"], window_info["title"])) filter_count = 0 - available_columns = [signals.index.name] + list(signals.columns) + available_columns = [signals.index.name, *signals.columns] for filter_info in window_info["configuration"]["filters"]: if filter_info["column"] in available_columns: tabular.add_filter() diff --git a/src/asammdf/gui/widgets/tree.py b/src/asammdf/gui/widgets/tree.py index 819f739a1..0d771ecaf 100644 --- a/src/asammdf/gui/widgets/tree.py +++ b/src/asammdf/gui/widgets/tree.py @@ -1285,7 +1285,7 @@ def open_menu(self): if item.type() == ChannelsTreeItem.Channel: uuids.append(item.uuid) - self.set_time_offset.emit([absolute, offset] + uuids) + self.set_time_offset.emit([absolute, offset, *uuids]) elif action_text == "Delete [Del]": event = QtGui.QKeyEvent( From 01c9769356105a9fbcd896561efa58cd12323c05 Mon Sep 17 00:00:00 2001 From: zariiii9003 <52598363+zariiii9003@users.noreply.github.com> Date: Tue, 12 Dec 2023 19:46:24 +0100 Subject: [PATCH 3/5] activate flake8-pie --- pyproject.toml | 1 + src/asammdf/blocks/mdf_v4.py | 1 - src/asammdf/gui/widgets/batch.py | 34 +++++++++++++++----------------- src/asammdf/gui/widgets/file.py | 34 +++++++++++++++----------------- src/asammdf/gui/widgets/gps.py | 1 - src/asammdf/mdf.py | 2 +- 6 files changed, 34 insertions(+), 39 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 74e01d180..c027ca56f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,6 +28,7 @@ select = [ "F", # pyflakes "UP", # pyupgrade "I", # isort + "PIE", # flake8-pie "RUF", # Ruff-specific rules ] ignore = [ diff --git a/src/asammdf/blocks/mdf_v4.py b/src/asammdf/blocks/mdf_v4.py index 921b7d1a9..09887d9b5 100644 --- a/src/asammdf/blocks/mdf_v4.py +++ b/src/asammdf/blocks/mdf_v4.py @@ -8028,7 +8028,6 @@ def _yield_selected_signals( signals.append(signal) - pass else: for channel_index in channels: signal, invalidation_bits = self.get( diff --git a/src/asammdf/gui/widgets/batch.py b/src/asammdf/gui/widgets/batch.py index 832199e16..8d230ed1b 100644 --- a/src/asammdf/gui/widgets/batch.py +++ b/src/asammdf/gui/widgets/batch.py @@ -557,24 +557,22 @@ def extract_bus_csv_logging_thread( ) result = mdf_.export( - **{ - "fmt": "csv", - "filename": file_name, - "single_time_base": single_time_base, - "time_from_zero": time_from_zero, - "empty_channels": empty_channels, - "raster": raster or None, - "time_as_date": time_as_date, - "ignore_value2text_conversions": self.ignore_value2text_conversions, - "delimiter": delimiter, - "doublequote": doublequote, - "escapechar": escapechar, - "lineterminator": lineterminator, - "quotechar": quotechar, - "quoting": quoting, - "add_units": add_units, - "progress": progress, - } + fmt="csv", + filename=file_name, + single_time_base=single_time_base, + time_from_zero=time_from_zero, + empty_channels=empty_channels, + raster=raster or None, + time_as_date=time_as_date, + ignore_value2text_conversions=self.ignore_value2text_conversions, + delimiter=delimiter, + doublequote=doublequote, + escapechar=escapechar, + lineterminator=lineterminator, + quotechar=quotechar, + quoting=quoting, + add_units=add_units, + progress=progress, ) if result is TERMINATED: return diff --git a/src/asammdf/gui/widgets/file.py b/src/asammdf/gui/widgets/file.py index 8465b1633..d179376ca 100644 --- a/src/asammdf/gui/widgets/file.py +++ b/src/asammdf/gui/widgets/file.py @@ -2026,24 +2026,22 @@ def extract_bus_csv_logging_thread( ) result = mdf.export( - **{ - "fmt": "csv", - "filename": file_name, - "single_time_base": single_time_base, - "time_from_zero": time_from_zero, - "empty_channels": empty_channels, - "raster": raster or None, - "time_as_date": time_as_date, - "ignore_value2text_conversions": self.ignore_value2text_conversions, - "delimiter": delimiter, - "doublequote": doublequote, - "escapechar": escapechar, - "lineterminator": lineterminator, - "quotechar": quotechar, - "quoting": quoting, - "add_units": add_units, - "progress": progress, - } + fmt="csv", + filename=file_name, + single_time_base=single_time_base, + time_from_zero=time_from_zero, + empty_channels=empty_channels, + raster=raster or None, + time_as_date=time_as_date, + ignore_value2text_conversions=self.ignore_value2text_conversions, + delimiter=delimiter, + doublequote=doublequote, + escapechar=escapechar, + lineterminator=lineterminator, + quotechar=quotechar, + quoting=quoting, + add_units=add_units, + progress=progress, ) if result is TERMINATED: diff --git a/src/asammdf/gui/widgets/gps.py b/src/asammdf/gui/widgets/gps.py index abf379939..fa5c042a5 100644 --- a/src/asammdf/gui/widgets/gps.py +++ b/src/asammdf/gui/widgets/gps.py @@ -9,7 +9,6 @@ except: print(format_exc()) - pass from ..ui.gps import Ui_GPSDisplay diff --git a/src/asammdf/mdf.py b/src/asammdf/mdf.py index ffec0e482..5428d445d 100644 --- a/src/asammdf/mdf.py +++ b/src/asammdf/mdf.py @@ -2408,7 +2408,7 @@ def concatenate( f"internal structure of file <{mdf.name}> is different; different channel groups count" ) else: - cg_translations = dict.fromkeys(range(0, groups_nr)) + cg_translations = dict.fromkeys(range(groups_nr)) make_translation = False From 6a45c893e30dcd6caa929aeac39565d3cc7f3769 Mon Sep 17 00:00:00 2001 From: zariiii9003 <52598363+zariiii9003@users.noreply.github.com> Date: Tue, 12 Dec 2023 20:05:00 +0100 Subject: [PATCH 4/5] activate F401 --- pyproject.toml | 1 - src/asammdf/__init__.py | 2 +- src/asammdf/blocks/utils.py | 1 - src/asammdf/gui/utils.py | 2 +- src/asammdf/gui/widgets/batch.py | 16 +++++++--------- src/asammdf/gui/widgets/file.py | 8 ++++---- src/asammdf/gui/widgets/plot.py | 2 +- src/asammdf/gui/widgets/tree.py | 4 ++-- src/asammdf/gui/widgets/tree_item.py | 2 +- src/asammdf/mdf.py | 2 +- 10 files changed, 18 insertions(+), 22 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c027ca56f..f1f6c9633 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,7 +33,6 @@ select = [ ] ignore = [ "B007", # unused-loop-control-variable - "F401", # unused-import "F841", # unused-variable "RUF012", # mutable-class-default "RUF015", # unnecessary-iterable-allocation-for-first-element diff --git a/src/asammdf/__init__.py b/src/asammdf/__init__.py index 028ab1a8d..437e2a8a3 100644 --- a/src/asammdf/__init__.py +++ b/src/asammdf/__init__.py @@ -22,7 +22,7 @@ from .version import __version__ try: - from .blocks import cutils + from .blocks import cutils # noqa: F401 __cextension__ = True except ImportError: diff --git a/src/asammdf/blocks/utils.py b/src/asammdf/blocks/utils.py index e17c904ca..fdbf8cb54 100644 --- a/src/asammdf/blocks/utils.py +++ b/src/asammdf/blocks/utils.py @@ -6,7 +6,6 @@ from collections.abc import Iterator from copy import deepcopy -from enum import IntFlag from functools import lru_cache from io import StringIO import json diff --git a/src/asammdf/gui/utils.py b/src/asammdf/gui/utils.py index deff25c92..6d7d63131 100644 --- a/src/asammdf/gui/utils.py +++ b/src/asammdf/gui/utils.py @@ -10,7 +10,7 @@ import sys from textwrap import indent from threading import Thread -from time import perf_counter, sleep +from time import sleep import traceback from traceback import format_exc from typing import Dict, Union diff --git a/src/asammdf/gui/widgets/batch.py b/src/asammdf/gui/widgets/batch.py index 8d230ed1b..dd9b8ee25 100644 --- a/src/asammdf/gui/widgets/batch.py +++ b/src/asammdf/gui/widgets/batch.py @@ -19,8 +19,6 @@ BUS_TYPE_FLEXRAY, BUS_TYPE_LIN, BUS_TYPE_USB, - FLAG_AT_TO_STRING, - FLAG_CG_BUS_EVENT, ) from ...mdf import MDF, SUPPORTED_VERSIONS from ..dialogs.advanced_search import AdvancedSearch @@ -119,7 +117,7 @@ def __init__( self.empty_channels_mat.insertItems(0, ("skip", "zeros")) self.empty_channels_csv.insertItems(0, ("skip", "zeros")) try: - import scipy + import scipy # noqa: F401 self.mat_format.insertItems(0, ("4", "5", "7.3")) except: @@ -1307,7 +1305,7 @@ def apply_processing(self, event): if output_format == "HDF5": try: - from h5py import File as HDF5 + from h5py import File as HDF5 # noqa: F401 except ImportError: MessageBox.critical( self, @@ -1329,7 +1327,7 @@ def apply_processing(self, event): return else: try: - from scipy.io import savemat + from scipy.io import savemat # noqa: F401 except ImportError: MessageBox.critical( self, @@ -1340,7 +1338,7 @@ def apply_processing(self, event): elif output_format == "Parquet": try: - from fastparquet import write as write_parquet + from fastparquet import write as write_parquet # noqa: F401 except ImportError: MessageBox.critical( self, @@ -1374,18 +1372,18 @@ def apply_processing_thread(self, progress): if output_format == "HDF5": suffix = ".hdf" - from h5py import File as HDF5 + from h5py import File as HDF5 # noqa: F401 elif output_format == "MAT": suffix = ".mat" if opts.mat_format == "7.3": from hdf5storage import savemat else: - from scipy.io import savemat + from scipy.io import savemat # noqa: F401 elif output_format == "Parquet": suffix = ".parquet" - from fastparquet import write as write_parquet + from fastparquet import write as write_parquet # noqa: F401 elif output_format == "CSV": suffix = ".csv" diff --git a/src/asammdf/gui/widgets/file.py b/src/asammdf/gui/widgets/file.py index d179376ca..ae2c89c28 100644 --- a/src/asammdf/gui/widgets/file.py +++ b/src/asammdf/gui/widgets/file.py @@ -328,7 +328,7 @@ def __init__( self.empty_channels_mat.insertItems(0, ("skip", "zeros")) self.empty_channels_csv.insertItems(0, ("skip", "zeros")) try: - import scipy + import scipy # noqa: F401 self.mat_format.insertItems(0, ("4", "5", "7.3")) except: @@ -2603,7 +2603,7 @@ def apply_processing(self, event): if output_format == "HDF5": try: - from h5py import File as HDF5 + from h5py import File as HDF5 # noqa: F401 except ImportError: MessageBox.critical( self, @@ -2625,7 +2625,7 @@ def apply_processing(self, event): return else: try: - from scipy.io import savemat + from scipy.io import savemat # noqa: F401 except ImportError: MessageBox.critical( self, @@ -2636,7 +2636,7 @@ def apply_processing(self, event): elif output_format == "Parquet": try: - from fastparquet import write as write_parquet + from fastparquet import write as write_parquet # noqa: F401 except ImportError: MessageBox.critical( self, diff --git a/src/asammdf/gui/widgets/plot.py b/src/asammdf/gui/widgets/plot.py index 91010d486..6d16ca646 100644 --- a/src/asammdf/gui/widgets/plot.py +++ b/src/asammdf/gui/widgets/plot.py @@ -5984,7 +5984,7 @@ def set_precision(self, precision): try: - import scipy + import scipy # noqa: F401 from .fft_window import FFTWindow except ImportError: diff --git a/src/asammdf/gui/widgets/tree.py b/src/asammdf/gui/widgets/tree.py index 0d771ecaf..22407d2f6 100644 --- a/src/asammdf/gui/widgets/tree.py +++ b/src/asammdf/gui/widgets/tree.py @@ -26,7 +26,7 @@ unique_ranges, value_as_str, ) -from .tree_item import MinimalTreeItem, TreeItem +from .tree_item import MinimalTreeItem NOT_FOUND = 0xFFFFFFFF @@ -937,7 +937,7 @@ def open_menu(self): submenu.addAction(self.tr("Set time base start offset")) try: - import scipy + import scipy # noqa: F401 menu.addAction(self.tr("Compute FFT")) except ImportError: diff --git a/src/asammdf/gui/widgets/tree_item.py b/src/asammdf/gui/widgets/tree_item.py index 3be89bb5d..7ce035716 100644 --- a/src/asammdf/gui/widgets/tree_item.py +++ b/src/asammdf/gui/widgets/tree_item.py @@ -1,6 +1,6 @@ from time import perf_counter -from PySide6 import QtCore, QtWidgets +from PySide6 import QtWidgets from ..utils import get_colors_using_ranges diff --git a/src/asammdf/mdf.py b/src/asammdf/mdf.py index 5428d445d..1637d5655 100644 --- a/src/asammdf/mdf.py +++ b/src/asammdf/mdf.py @@ -1245,7 +1245,7 @@ def export( if compression == "SNAPPY": try: - import snappy + import snappy # noqa: F401 except ImportError: logger.warning("snappy compressor is not installed; compression will be set to GZIP") compression = "GZIP" From 7589e2e14ab21a4a8e998e865598f336df020365 Mon Sep 17 00:00:00 2001 From: zariiii9003 <52598363+zariiii9003@users.noreply.github.com> Date: Tue, 12 Dec 2023 20:10:14 +0100 Subject: [PATCH 5/5] simplify --- src/asammdf/blocks/mdf_v4.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/asammdf/blocks/mdf_v4.py b/src/asammdf/blocks/mdf_v4.py index 09887d9b5..ba0b3999f 100644 --- a/src/asammdf/blocks/mdf_v4.py +++ b/src/asammdf/blocks/mdf_v4.py @@ -6927,7 +6927,7 @@ def _get_array( shape = (shape[0],) + shape[1:][::-1] vals = vals.reshape(shape) - axes = (0, *tuple(range(len(shape) - 1, 0, -1))) + axes = (0, *reversed(range(1, len(shape)))) vals = transpose(vals, axes=axes) cycles_nr = len(vals)