From ac90b50d5ab01460634f07c1a048243a07ba3a72 Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Mon, 3 Nov 2025 08:54:16 +0100 Subject: [PATCH 1/2] TST: update ruff and codespell versions --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 010253ff..20d92ca1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,13 +13,13 @@ default_language_version: repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.0 + rev: v0.13.3 hooks: - id: ruff args: [ --fix ] - id: ruff-format - repo: https://github.com/codespell-project/codespell - rev: v2.3.0 + rev: v2.4.1 hooks: - id: codespell additional_dependencies: From f55a696f984dc7effdf53b173971a6606f5d8275 Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Mon, 3 Nov 2025 08:57:02 +0100 Subject: [PATCH 2/2] Fix linter --- audformat/core/attachment.py | 2 +- audformat/core/column.py | 11 +++-------- audformat/core/database.py | 4 +++- audformat/core/errors.py | 16 ++++++---------- audformat/core/scheme.py | 13 +++++++------ audformat/core/table.py | 16 +++++----------- audformat/core/utils.py | 17 ++++------------- benchmarks/benchmark_union.py | 2 +- tests/test_attachment.py | 3 +-- tests/test_database.py | 3 +-- tests/test_misc_table.py | 4 ++-- tests/test_scheme.py | 12 ++++++------ tests/test_utils.py | 9 ++++----- tests/test_utils_concat.py | 3 +-- 14 files changed, 45 insertions(+), 70 deletions(-) diff --git a/audformat/core/attachment.py b/audformat/core/attachment.py index 2c70b9e1..8f251aac 100644 --- a/audformat/core/attachment.py +++ b/audformat/core/attachment.py @@ -135,7 +135,7 @@ def _check_overlap( or other.path.startswith(self.path) ): raise RuntimeError( - f"Attachments '{self.path}' and '{other.path}' " "are nested." + f"Attachments '{self.path}' and '{other.path}' are nested." ) def _check_path( diff --git a/audformat/core/column.py b/audformat/core/column.py index 572fb7e1..2c749b15 100644 --- a/audformat/core/column.py +++ b/audformat/core/column.py @@ -249,7 +249,7 @@ def get( if not any(labels.values()): raise ValueError( - f"Scheme '{self.scheme_id}' provides no mapping " "for its labels." + f"Scheme '{self.scheme_id}' provides no mapping for its labels." ) # Check that at least one key is available for map @@ -261,12 +261,7 @@ def get( keys = sorted(list(set(keys))) if len(keys) > 0 and map not in keys: raise ValueError( - f"Cannot map " - f"'{self._id}' " - f"to " - f"'{map}'. " - f"Expected one of " - f"{list(keys)}." + f"Cannot map '{self._id}' to '{map}'. Expected one of {list(keys)}." ) mapping = {} @@ -355,7 +350,7 @@ def set( return self.set(values, index=index) else: raise ValueError( - "Cannot set values of a filewise column " "using a segmented index." + "Cannot set values of a filewise column using a segmented index." ) else: if is_scalar(values): diff --git a/audformat/core/database.py b/audformat/core/database.py index eea8f366..601cf63c 100644 --- a/audformat/core/database.py +++ b/audformat/core/database.py @@ -586,7 +586,9 @@ def get( Limit to a particular table or split. - >>> db.get("emotion", tables=["emotion.categories.train.gold_standard"]).head() + >>> db.get( + ... "emotion", tables=["emotion.categories.train.gold_standard"] + ... ).head() emotion file wav/03a01Fa.wav happiness diff --git a/audformat/core/errors.py b/audformat/core/errors.py index eac310da..8d43b4f9 100644 --- a/audformat/core/errors.py +++ b/audformat/core/errors.py @@ -13,10 +13,10 @@ class BadIdError(ValueError): def __init__(self, name: str, invalid_id: str, dictionary: dict): if not dictionary: - message = f"Bad {name} ID '{invalid_id}', " f"no {name} objects defined yet" + message = f"Bad {name} ID '{invalid_id}', no {name} objects defined yet" else: message = ( - f"Bad {name} ID '{invalid_id}', " f"expected one of {list(dictionary)}" + f"Bad {name} ID '{invalid_id}', expected one of {list(dictionary)}" ) super().__init__(message) @@ -31,7 +31,7 @@ class BadKeyError(KeyError): """ def __init__(self, invalid_key: str, valid_keys: Sequence[str]): - message = f"Bad key '{invalid_key}', " f"expected one of {list(valid_keys)}" + message = f"Bad key '{invalid_key}', expected one of {list(valid_keys)}" super().__init__(message) @@ -45,7 +45,7 @@ class BadTypeError(TypeError): """ def __init__(self, invalid_value: object, expected_type: type): - message = f"Bad type '{type(invalid_value)}', " f"expected '{expected_type}'" + message = f"Bad type '{type(invalid_value)}', expected '{expected_type}'" super().__init__(message) @@ -59,9 +59,7 @@ class BadValueError(ValueError): """ def __init__(self, invalid_value: str, valid_values: Sequence[str]): - message = ( - f"Bad value '{invalid_value}', " f"expected one of {list(valid_values)}" - ) + message = f"Bad value '{invalid_value}', expected one of {list(valid_values)}" super().__init__(message) @@ -75,6 +73,4 @@ class TableExistsError(KeyError): """ def __init__(self, table_type: str, table_id: str): - KeyError( - f"There is already a " f"{table_type} " f"table with ID " f"'{table_id}'." - ) + KeyError(f"There is already a {table_type} table with ID '{table_id}'.") diff --git a/audformat/core/scheme.py b/audformat/core/scheme.py index 56f11152..71a42f3a 100644 --- a/audformat/core/scheme.py +++ b/audformat/core/scheme.py @@ -76,7 +76,9 @@ class Scheme(common.HeaderBase): >>> # Use index of misc table as labels >>> import audformat >>> db = audformat.Database("mydb") - >>> db["speaker"] = audformat.MiscTable(pd.Index(["spk1", "spk2"], name="speaker")) + >>> db["speaker"] = audformat.MiscTable( + ... pd.Index(["spk1", "spk2"], name="speaker") + ... ) >>> Scheme("str", labels="speaker") {dtype: str, labels: speaker} @@ -132,12 +134,11 @@ def __init__( # Labels from misc table if dtype is None: raise ValueError( - "'dtype' has to be provided " - "when using a misc table as labels." + "'dtype' has to be provided when using a misc table as labels." ) if dtype == define.DataType.BOOL: raise ValueError( - "'dtype' cannot be 'bool' " "when using a misc table as labels." + "'dtype' cannot be 'bool' when using a misc table as labels." ) else: # Labels from list or dictionary @@ -352,7 +353,7 @@ def replace_labels( """ if self.labels is None: raise ValueError( - "Cannot replace labels when " "scheme does not define labels." + "Cannot replace labels when scheme does not define labels." ) self._check_labels(labels) @@ -391,7 +392,7 @@ def _check_labels( r"""Raise label related errors.""" if not isinstance(labels, (dict, list, str)): raise ValueError( - "Labels must be passed " "as a dictionary, list or ID of a misc table." + "Labels must be passed as a dictionary, list or ID of a misc table." ) if self._db is not None and isinstance(labels, str): diff --git a/audformat/core/table.py b/audformat/core/table.py index 64df413d..2d564fdb 100644 --- a/audformat/core/table.py +++ b/audformat/core/table.py @@ -414,7 +414,7 @@ def get( if map is not None: if self.db is None: raise RuntimeError( - "Cannot map schemes, " "table is not assigned to a database." + "Cannot map schemes, table is not assigned to a database." ) if not result_is_copy: @@ -742,7 +742,7 @@ def raise_error( left: HeaderDict | None, right: HeaderDict | None, ): - raise ValueError(f"{msg}:\n" f"{left}\n" "!=\n" f"{right}") + raise ValueError(f"{msg}:\n{left}\n!=\n{right}") def assert_equal( msg: str, @@ -762,13 +762,13 @@ def assert_equal( for other in others: assert_equal( - "Media of table " f"'{other._id}' " "does not match", + f"Media of table '{other._id}' does not match", self.media, other.media, ) assert_equal( - "Split of table " f"'{other._id}' " "does not match", + f"Split of table '{other._id}' does not match", self.split, other.split, ) @@ -1859,13 +1859,7 @@ def _assert_table_index( input_type = index_type(index) if table.type != input_type: raise ValueError( - f"Cannot " - f"{operation} " - f"a " - f"{table.type} " - f"table with a " - f"{input_type} " - f"index." + f"Cannot {operation} a {table.type} table with a {input_type} index." ) elif not utils.is_index_alike([table.index, index]): want = ( diff --git a/audformat/core/utils.py b/audformat/core/utils.py index fa500280..3d820574 100644 --- a/audformat/core/utils.py +++ b/audformat/core/utils.py @@ -239,7 +239,7 @@ def concat( allowed_values = ["overlap", "mismatch"] if aggregate_strategy not in allowed_values: raise ValueError( - "aggregate_strategy needs to be one of: " f"{', '.join(allowed_values)}" + f"aggregate_strategy needs to be one of: {', '.join(allowed_values)}" ) if not objs: @@ -1107,10 +1107,7 @@ def join_labels( dtypes = sorted(list({str(type(x)) for x in items})) if len(dtypes) > 1: raise ValueError( - f"Elements or keys must " - f"have the same dtype, " - f"but yours have " - f"{dtypes}.", + f"Elements or keys must have the same dtype, but yours have {dtypes}.", ) if isinstance(labels[0], dict): @@ -1511,9 +1508,7 @@ def set_index_dtypes( levels = index.names if isinstance(index, pd.MultiIndex) else [index.name] if len(set(levels)) != len(levels): - raise ValueError( - f"Got index with levels " f"{levels}, " f"but names must be unique." - ) + raise ValueError(f"Got index with levels {levels}, but names must be unique.") if not isinstance(dtypes, dict): dtypes = {level: dtypes for level in levels} @@ -1521,11 +1516,7 @@ def set_index_dtypes( for name in dtypes: if name not in levels: raise ValueError( - f"A level with name " - f"'{name}' " - f"does not exist. " - f"Level names are: " - f"{levels}." + f"A level with name '{name}' does not exist. Level names are: {levels}." ) if len(dtypes) == 0: diff --git a/benchmarks/benchmark_union.py b/benchmarks/benchmark_union.py index 31861d69..fb9a2367 100644 --- a/benchmarks/benchmark_union.py +++ b/benchmarks/benchmark_union.py @@ -64,7 +64,7 @@ def main(): for segmented in [False, True]: print() - print(f'{"segmented" if segmented else "filewise"} index') + print(f"{'segmented' if segmented else 'filewise'} index") y = benchmark( segmented, diff --git a/tests/test_attachment.py b/tests/test_attachment.py index d2730744..aef5d369 100644 --- a/tests/test_attachment.py +++ b/tests/test_attachment.py @@ -165,8 +165,7 @@ def test_attachment_files_errors(tmpdir): db = audformat.Database("db") db.attachments["attachment"] = attachment error_msg = ( - "The database needs to be saved to disk " - "before attachment files can be listed." + "The database needs to be saved to disk before attachment files can be listed." ) with pytest.raises(RuntimeError, match=error_msg): attachment.files diff --git a/tests/test_database.py b/tests/test_database.py index c43ebdd4..48daa3ca 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -735,8 +735,7 @@ def test_update(tmpdir): other_bad = audformat.testing.create_db(minimal=True) other_bad.schemes["misc"] = audformat.Scheme("str") error_msg = ( - "Cannot join scheme 'misc' when one " - "is using a misc table and the other is not." + "Cannot join scheme 'misc' when one is using a misc table and the other is not." ) with pytest.raises(ValueError, match=error_msg): db.update(other_bad) diff --git a/tests/test_misc_table.py b/tests/test_misc_table.py index d019cd29..9c81e521 100644 --- a/tests/test_misc_table.py +++ b/tests/test_misc_table.py @@ -736,7 +736,7 @@ def test_dtype_index( @pytest.mark.parametrize( - "index_values, index_dtype, " "expected_pandas_dtype, expected_audformat_dtype", + "index_values, index_dtype, expected_pandas_dtype, expected_audformat_dtype", [ ( [], @@ -920,7 +920,7 @@ def test_dtype_multiindex( @pytest.mark.parametrize( - "index_values, index_dtype, " "expected_pandas_dtype, expected_audformat_dtype", + "index_values, index_dtype, expected_pandas_dtype, expected_audformat_dtype", [ ( [], diff --git a/tests/test_scheme.py b/tests/test_scheme.py index 19de30a0..313ab47d 100644 --- a/tests/test_scheme.py +++ b/tests/test_scheme.py @@ -318,7 +318,7 @@ def test_scheme_errors(): db = audformat.Database("test") # dtype mismatch - error_msg = "Data type is set to 'str', " "but data type of labels is 'int'." + error_msg = "Data type is set to 'str', but data type of labels is 'int'." with pytest.raises(ValueError, match=error_msg): audformat.Scheme( audformat.define.DataType.STRING, @@ -335,7 +335,7 @@ def test_scheme_errors(): audformat.Scheme("bad") # labels not list or dictionary - error_msg = "Labels must be passed " "as a dictionary, list or ID of a misc table." + error_msg = "Labels must be passed as a dictionary, list or ID of a misc table." with pytest.raises(ValueError, match=error_msg): audformat.Scheme(labels={1, 2, 3}) @@ -345,13 +345,13 @@ def test_scheme_errors(): audformat.Scheme(labels=[1, "2", 3]) # update labels when scheme has no label - error_msg = "Cannot replace labels when " "scheme does not define labels." + error_msg = "Cannot replace labels when scheme does not define labels." with pytest.raises(ValueError, match=error_msg): scheme = audformat.Scheme(audformat.define.DataType.INTEGER) scheme.replace_labels(["a", "b"]) # misc table needs to define data type - error_msg = "'dtype' has to be provided " "when using a misc table as labels." + error_msg = "'dtype' has to be provided when using a misc table as labels." with pytest.raises(ValueError, match=error_msg): audformat.Scheme(labels="misc") @@ -365,7 +365,7 @@ def test_scheme_errors(): db.schemes["misc"] = scheme # filewise table used instead of misc table - error_msg = "The table 'table' used as scheme labels " "needs to be a misc table." + error_msg = "The table 'table' used as scheme labels needs to be a misc table." db["table"] = audformat.Table(audformat.filewise_index(["f1"])) scheme = audformat.Scheme(labels="table", dtype="str") with pytest.raises(ValueError, match=error_msg): @@ -373,7 +373,7 @@ def test_scheme_errors(): # misc table has different dtype error_msg = ( - "Data type is set to 'str', " "but data type of labels in misc table is 'int'." + "Data type is set to 'str', but data type of labels in misc table is 'int'." ) db["misc"] = audformat.MiscTable(pd.Index([0], name="misc")) scheme = audformat.Scheme(labels="misc", dtype="str") diff --git a/tests/test_utils.py b/tests/test_utils.py index 9a1917bf..63852410 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1218,7 +1218,7 @@ def test_intersect(objs, expected): names=["l1", "l2"], ), ], - "Found different level dtypes: " "[('object', 'int'), ('int', 'object')]", + "Found different level dtypes: [('object', 'int'), ('int', 'object')]", ), ( [ @@ -1237,15 +1237,14 @@ def test_intersect(objs, expected): names=["l1", "l2"], ), ], - "Found different level dtypes: " - "[('object', 'int'), ('object', 'object')]", + "Found different level dtypes: [('object', 'int'), ('object', 'object')]", ), ( [ pd.MultiIndex.from_arrays([[], []], names=["l1", "l2"]), pd.MultiIndex.from_arrays([[], []]), ], - "Found different level names: " "[('l1', 'l2'), (None, None)]", + "Found different level names: [('l1', 'l2'), (None, None)]", ), ( [ @@ -1264,7 +1263,7 @@ def test_intersect(objs, expected): names=["L1", "L2"], ), ], - "Found different level names: " "[('l1', 'l2'), ('L1', 'L2')]", + "Found different level names: [('l1', 'l2'), ('L1', 'L2')]", ), ( [ diff --git a/tests/test_utils_concat.py b/tests/test_utils_concat.py index 83323f70..55c96c45 100644 --- a/tests/test_utils_concat.py +++ b/tests/test_utils_concat.py @@ -1596,8 +1596,7 @@ def test_concat_overwrite_aggregate_function( @pytest.mark.parametrize( - "objs, aggregate_function, aggregate_strategy, " - "expected_error, expected_error_msg", + "objs, aggregate_function, aggregate_strategy, expected_error, expected_error_msg", [ # wrong aggregate_strategy argument (