Skip to content

Commit

Permalink
black and ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhrisca committed Jan 26, 2024
1 parent d68adcc commit 2ca3e23
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 67 deletions.
1 change: 1 addition & 0 deletions benchmarks/bench.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
benchmark asammdf vs mdfreader
"""

import argparse
from io import StringIO
import multiprocessing
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
asammdf
"""

from pathlib import Path

from numpy import get_include
Expand Down
8 changes: 5 additions & 3 deletions src/asammdf/blocks/conversion_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,11 @@ def from_dict(conversion: dict[str, Any]) -> v4b.ChannelConversion:
"conversion_type": v4c.CONVERSION_TYPE_RTABX,
f"upper_{nr}": conversion[f"upper_{nr}"],
f"lower_{nr}": conversion[f"lower_{nr}"],
f"text_{nr}": conversion[f"text_{nr}"]
if isinstance(conversion[f"text_{nr}"], bytes)
else conversion[f"text_{nr}"].encode("utf-8"),
f"text_{nr}": (
conversion[f"text_{nr}"]
if isinstance(conversion[f"text_{nr}"], bytes)
else conversion[f"text_{nr}"].encode("utf-8")
),
"default": b"",
}
conversion[f"text_{nr}"] = from_dict(partial_conversion)
Expand Down
1 change: 0 additions & 1 deletion src/asammdf/blocks/mdf_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

# MDF versions 2 and 3 share the same implementation
class MDF2(MDF3):

"""shared implementation for mdf version 2 and 3"""

def __init__(
Expand Down
6 changes: 2 additions & 4 deletions src/asammdf/blocks/mdf_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2710,8 +2710,7 @@ def get(
record_offset: int = ...,
record_count: int | None = ...,
skip_channel_validation: bool = ...,
) -> Signal:
...
) -> Signal: ...

@overload
def get(
Expand All @@ -2727,8 +2726,7 @@ def get(
record_offset: int = ...,
record_count: int | None = ...,
skip_channel_validation: bool = ...,
) -> tuple[NDArray[Any], None]:
...
) -> tuple[NDArray[Any], None]: ...

def get(
self,
Expand Down
25 changes: 19 additions & 6 deletions src/asammdf/blocks/mdf_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -4744,7 +4744,15 @@ def _append_structure_composition(
invalidation_bytes_nr: int,
inval_bits: list[NDArray[Any]],
inval_cntr: int,
) -> tuple[int, int, int, tuple[int, int], list[NDArray[Any]], list[tuple[str, dtype[Any], tuple[int, ...]]], int,]:
) -> tuple[
int,
int,
int,
tuple[int, int],
list[NDArray[Any]],
list[tuple[str, dtype[Any], tuple[int, ...]]],
int,
]:
si_map = self._si_map

fields = []
Expand Down Expand Up @@ -5163,7 +5171,14 @@ def _append_structure_composition_column_oriented(
dg_cntr: int,
ch_cntr: int,
defined_texts: dict[str, int],
) -> tuple[int, int, int, tuple[int, int], list[NDArray[Any]], list[tuple[str, dtype[Any], tuple[int, ...]]],]:
) -> tuple[
int,
int,
int,
tuple[int, int],
list[NDArray[Any]],
list[tuple[str, dtype[Any], tuple[int, ...]]],
]:
si_map = self._si_map

fields = []
Expand Down Expand Up @@ -6307,8 +6322,7 @@ def get(
record_offset: int = ...,
record_count: int | None = ...,
skip_channel_validation: bool = ...,
) -> Signal:
...
) -> Signal: ...

@overload
def get(
Expand All @@ -6324,8 +6338,7 @@ def get(
record_offset: int = ...,
record_count: int | None = ...,
skip_channel_validation: bool = ...,
) -> tuple[NDArray[Any], NDArray[Any]]:
...
) -> tuple[NDArray[Any], NDArray[Any]]: ...

def get(
self,
Expand Down
12 changes: 4 additions & 8 deletions src/asammdf/blocks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ def get_text_v3(
stream: ReadableBufferType,
mapped: bool = ...,
decode: Literal[True] = ...,
) -> str:
...
) -> str: ...


@overload
Expand All @@ -252,8 +251,7 @@ def get_text_v3(
stream: ReadableBufferType,
mapped: bool = ...,
decode: Literal[False] = ...,
) -> bytes:
...
) -> bytes: ...


def get_text_v3(address: int, stream: ReadableBufferType, mapped: bool = False, decode: bool = True) -> str | bytes:
Expand Down Expand Up @@ -310,8 +308,7 @@ def get_text_v4(
stream: ReadableBufferType,
mapped: bool = ...,
decode: Literal[True] = ...,
) -> str:
...
) -> str: ...


@overload
Expand All @@ -320,8 +317,7 @@ def get_text_v4(
stream: ReadableBufferType,
mapped: bool = ...,
decode: Literal[False] = ...,
) -> bytes:
...
) -> bytes: ...


def get_text_v4(address: int, stream: ReadableBufferType, mapped: bool = False, decode: bool = True) -> str | bytes:
Expand Down
1 change: 1 addition & 0 deletions src/asammdf/blocks/v2_v3_constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" MDF v2 and v3 constants """

import struct

# byte order
Expand Down
8 changes: 5 additions & 3 deletions src/asammdf/blocks/v4_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3839,9 +3839,11 @@ def convert(self, values, as_object=False, as_bytes=False, ignore_value2text_con
masks = np.array([self[f"mask_{i}"] for i in range(nr)], dtype="u8")

phys = [
conv
if isinstance(conv, bytes)
else ((f"{conv.name}=".encode(), conv) if conv.name else (b"", conv))
(
conv
if isinstance(conv, bytes)
else ((f"{conv.name}=".encode(), conv) if conv.name else (b"", conv))
)
for conv in phys
]

Expand Down
1 change: 1 addition & 0 deletions src/asammdf/blocks/v4_constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" MDF v4 constants """

import re
import struct
import sys
Expand Down
16 changes: 10 additions & 6 deletions src/asammdf/gui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,16 @@ def get_data(name, t=0, interpolated=False):
signals[name]
.interp(
[t],
integer_interpolation_mode=IntegerInterpolation.REPEAT_PREVIOUS_SAMPLE
if not interpolated
else IntegerInterpolation.LINEAR_INTERPOLATION,
float_interpolation_mode=FloatInterpolation.REPEAT_PREVIOUS_SAMPLE
if not interpolated
else FloatInterpolation.LINEAR_INTERPOLATION,
integer_interpolation_mode=(
IntegerInterpolation.REPEAT_PREVIOUS_SAMPLE
if not interpolated
else IntegerInterpolation.LINEAR_INTERPOLATION
),
float_interpolation_mode=(
FloatInterpolation.REPEAT_PREVIOUS_SAMPLE
if not interpolated
else FloatInterpolation.LINEAR_INTERPOLATION
),
)
.samples
)
Expand Down
8 changes: 5 additions & 3 deletions src/asammdf/gui/widgets/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3266,9 +3266,11 @@ def item_to_config(tree, root):
pattern["ranges"] = ranges

config = {
"channels": item_to_config(self.channel_selection, self.channel_selection.invisibleRootItem())
if not self.pattern
else [],
"channels": (
item_to_config(self.channel_selection, self.channel_selection.invisibleRootItem())
if not self.pattern
else []
),
"pattern": pattern,
"splitter": [int(e) for e in self.splitter.sizes()[:2]]
+ [
Expand Down
8 changes: 5 additions & 3 deletions src/asammdf/gui/widgets/tabular_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1541,9 +1541,11 @@ def to_config(self):
"sorted": True,
"channels": list(self.tree.pgdf.df_unfiltered.columns) if not self.pattern else [],
"filtered": bool(self.query.toPlainText()),
"filters": [self.filters.itemWidget(self.filters.item(i)).to_config() for i in range(count)]
if not self.pattern
else [],
"filters": (
[self.filters.itemWidget(self.filters.item(i)).to_config() for i in range(count)]
if not self.pattern
else []
),
"time_as_date": self.time_as_date.checkState() == QtCore.Qt.CheckState.Checked,
"pattern": pattern,
"format": self.format,
Expand Down
48 changes: 26 additions & 22 deletions src/asammdf/mdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2103,8 +2103,7 @@ def iter_get(
raster: float | None = ...,
samples_only: Literal[False] = ...,
raw: bool = ...,
) -> Iterator[Signal]:
...
) -> Iterator[Signal]: ...

@overload
def iter_get(
Expand All @@ -2115,8 +2114,7 @@ def iter_get(
raster: float | None = ...,
samples_only: Literal[True] = ...,
raw: bool = ...,
) -> Iterator[tuple[NDArray[Any], NDArray[Any] | None]]:
...
) -> Iterator[tuple[NDArray[Any], NDArray[Any] | None]]: ...

def iter_get(
self,
Expand Down Expand Up @@ -2768,9 +2766,9 @@ def stack(

if dg_cntr is not None:
for index in range(dg_cntr, len(stacked.groups)):
stacked.groups[
index
].channel_group.comment = f'stacked from channel group {i} of "{mdf.name.parent}"'
stacked.groups[index].channel_group.comment = (
f'stacked from channel group {i} of "{mdf.name.parent}"'
)

if progress is not None:
if callable(progress):
Expand Down Expand Up @@ -4059,13 +4057,15 @@ def iter_to_dataframe(
cycles = len(group_master)

signals = [
signal.interp(
master,
integer_interpolation_mode=self._integer_interpolation,
float_interpolation_mode=self._float_interpolation,
(
signal.interp(
master,
integer_interpolation_mode=self._integer_interpolation,
float_interpolation_mode=self._float_interpolation,
)
if not same_master or len(signal) != cycles
else signal
)
if not same_master or len(signal) != cycles
else signal
for signal in signals
]

Expand Down Expand Up @@ -4437,13 +4437,15 @@ def to_dataframe(
cycles = len(group_master)

signals = [
signal.interp(
master,
integer_interpolation_mode=self._integer_interpolation,
float_interpolation_mode=self._float_interpolation,
(
signal.interp(
master,
integer_interpolation_mode=self._integer_interpolation,
float_interpolation_mode=self._float_interpolation,
)
if not same_master or len(signal) != cycles
else signal
)
if not same_master or len(signal) != cycles
else signal
for signal in signals
]

Expand Down Expand Up @@ -4768,9 +4770,11 @@ def _extract_can_logging(

current_not_found = {
(
(message.arbitration_id.id, message.arbitration_id.extended)
if not message.is_j1939 and not global_is_j1939
else message.arbitration_id.pgn,
(
(message.arbitration_id.id, message.arbitration_id.extended)
if not message.is_j1939 and not global_is_j1939
else message.arbitration_id.pgn
),
message.name,
)
for msg_id, message in messages.items()
Expand Down
20 changes: 12 additions & 8 deletions src/asammdf/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,12 @@ def cut(
start: float | None = None,
stop: float | None = None,
include_ends: bool = True,
integer_interpolation_mode: IntInterpolationModeType
| IntegerInterpolation = IntegerInterpolation.REPEAT_PREVIOUS_SAMPLE,
float_interpolation_mode: FloatInterpolationModeType
| FloatInterpolation = FloatInterpolation.LINEAR_INTERPOLATION,
integer_interpolation_mode: (
IntInterpolationModeType | IntegerInterpolation
) = IntegerInterpolation.REPEAT_PREVIOUS_SAMPLE,
float_interpolation_mode: (
FloatInterpolationModeType | FloatInterpolation
) = FloatInterpolation.LINEAR_INTERPOLATION,
) -> Signal:
"""
Cuts the signal according to the *start* and *stop* values, by using
Expand Down Expand Up @@ -856,10 +858,12 @@ def extend(self, other: Signal) -> Signal:
def interp(
self,
new_timestamps: NDArray[Any],
integer_interpolation_mode: IntInterpolationModeType
| IntegerInterpolation = IntegerInterpolation.REPEAT_PREVIOUS_SAMPLE,
float_interpolation_mode: FloatInterpolationModeType
| FloatInterpolation = FloatInterpolation.LINEAR_INTERPOLATION,
integer_interpolation_mode: (
IntInterpolationModeType | IntegerInterpolation
) = IntegerInterpolation.REPEAT_PREVIOUS_SAMPLE,
float_interpolation_mode: (
FloatInterpolationModeType | FloatInterpolation
) = FloatInterpolation.LINEAR_INTERPOLATION,
) -> Signal:
"""returns a new *Signal* interpolated using the *new_timestamps*

Expand Down

0 comments on commit 2ca3e23

Please sign in to comment.