audformat 1.4.0__tar.gz → 1.4.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. {audformat-1.4.0 → audformat-1.4.2}/.github/workflows/doc.yml +1 -1
  2. {audformat-1.4.0 → audformat-1.4.2}/.github/workflows/publish.yml +1 -1
  3. {audformat-1.4.0 → audformat-1.4.2}/.github/workflows/test.yml +1 -2
  4. {audformat-1.4.0 → audformat-1.4.2}/CHANGELOG.rst +28 -0
  5. {audformat-1.4.0 → audformat-1.4.2}/PKG-INFO +2 -2
  6. {audformat-1.4.0 → audformat-1.4.2}/audformat/core/table.py +18 -6
  7. {audformat-1.4.0 → audformat-1.4.2}/audformat.egg-info/PKG-INFO +2 -2
  8. {audformat-1.4.0 → audformat-1.4.2}/audformat.egg-info/requires.txt +1 -1
  9. audformat-1.4.2/audformat.egg-info/top_level.txt +1 -0
  10. {audformat-1.4.0 → audformat-1.4.2}/pyproject.toml +5 -1
  11. {audformat-1.4.0 → audformat-1.4.2}/tests/test_index.py +69 -0
  12. {audformat-1.4.0 → audformat-1.4.2}/tests/test_misc_table.py +52 -2
  13. {audformat-1.4.0 → audformat-1.4.2}/tests/test_table.py +81 -0
  14. audformat-1.4.0/audformat.egg-info/top_level.txt +0 -6
  15. {audformat-1.4.0 → audformat-1.4.2}/.github/workflows/linter.yml +0 -0
  16. {audformat-1.4.0 → audformat-1.4.2}/.gitignore +0 -0
  17. {audformat-1.4.0 → audformat-1.4.2}/.pre-commit-config.yaml +0 -0
  18. {audformat-1.4.0 → audformat-1.4.2}/CONTRIBUTING.rst +0 -0
  19. {audformat-1.4.0 → audformat-1.4.2}/LICENSE +0 -0
  20. {audformat-1.4.0 → audformat-1.4.2}/README.rst +0 -0
  21. {audformat-1.4.0 → audformat-1.4.2}/audformat/__init__.py +0 -0
  22. {audformat-1.4.0 → audformat-1.4.2}/audformat/core/__init__.py +0 -0
  23. {audformat-1.4.0 → audformat-1.4.2}/audformat/core/attachment.py +0 -0
  24. {audformat-1.4.0 → audformat-1.4.2}/audformat/core/column.py +0 -0
  25. {audformat-1.4.0 → audformat-1.4.2}/audformat/core/common.py +0 -0
  26. {audformat-1.4.0 → audformat-1.4.2}/audformat/core/conftest.py +0 -0
  27. {audformat-1.4.0 → audformat-1.4.2}/audformat/core/database.py +0 -0
  28. {audformat-1.4.0 → audformat-1.4.2}/audformat/core/define.py +0 -0
  29. {audformat-1.4.0 → audformat-1.4.2}/audformat/core/errors.py +0 -0
  30. {audformat-1.4.0 → audformat-1.4.2}/audformat/core/index.py +0 -0
  31. {audformat-1.4.0 → audformat-1.4.2}/audformat/core/media.py +0 -0
  32. {audformat-1.4.0 → audformat-1.4.2}/audformat/core/rater.py +0 -0
  33. {audformat-1.4.0 → audformat-1.4.2}/audformat/core/scheme.py +0 -0
  34. {audformat-1.4.0 → audformat-1.4.2}/audformat/core/split.py +0 -0
  35. {audformat-1.4.0 → audformat-1.4.2}/audformat/core/testing.py +0 -0
  36. {audformat-1.4.0 → audformat-1.4.2}/audformat/core/typing.py +0 -0
  37. {audformat-1.4.0 → audformat-1.4.2}/audformat/core/utils.py +0 -0
  38. {audformat-1.4.0 → audformat-1.4.2}/audformat/define/__init__.py +0 -0
  39. {audformat-1.4.0 → audformat-1.4.2}/audformat/errors/__init__.py +0 -0
  40. {audformat-1.4.0 → audformat-1.4.2}/audformat/testing/__init__.py +0 -0
  41. {audformat-1.4.0 → audformat-1.4.2}/audformat/utils/__init__.py +0 -0
  42. {audformat-1.4.0 → audformat-1.4.2}/audformat.egg-info/SOURCES.txt +0 -0
  43. {audformat-1.4.0 → audformat-1.4.2}/audformat.egg-info/dependency_links.txt +0 -0
  44. {audformat-1.4.0 → audformat-1.4.2}/benchmarks/benchmark_hash.py +0 -0
  45. {audformat-1.4.0 → audformat-1.4.2}/benchmarks/benchmark_union.py +0 -0
  46. {audformat-1.4.0 → audformat-1.4.2}/docs/accessing-data.rst +0 -0
  47. {audformat-1.4.0 → audformat-1.4.2}/docs/api/audformat.define.rst +0 -0
  48. {audformat-1.4.0 → audformat-1.4.2}/docs/api/audformat.errors.rst +0 -0
  49. {audformat-1.4.0 → audformat-1.4.2}/docs/api/audformat.rst +0 -0
  50. {audformat-1.4.0 → audformat-1.4.2}/docs/api/audformat.testing.rst +0 -0
  51. {audformat-1.4.0 → audformat-1.4.2}/docs/api/audformat.utils.rst +0 -0
  52. {audformat-1.4.0 → audformat-1.4.2}/docs/api-src/audformat.define.rst +0 -0
  53. {audformat-1.4.0 → audformat-1.4.2}/docs/api-src/audformat.errors.rst +0 -0
  54. {audformat-1.4.0 → audformat-1.4.2}/docs/api-src/audformat.rst +0 -0
  55. {audformat-1.4.0 → audformat-1.4.2}/docs/api-src/audformat.testing.rst +0 -0
  56. {audformat-1.4.0 → audformat-1.4.2}/docs/api-src/audformat.utils.rst +0 -0
  57. {audformat-1.4.0 → audformat-1.4.2}/docs/changelog.rst +0 -0
  58. {audformat-1.4.0 → audformat-1.4.2}/docs/combine-tables.rst +0 -0
  59. {audformat-1.4.0 → audformat-1.4.2}/docs/conf.py +0 -0
  60. {audformat-1.4.0 → audformat-1.4.2}/docs/conftest.py +0 -0
  61. {audformat-1.4.0 → audformat-1.4.2}/docs/contributing.rst +0 -0
  62. {audformat-1.4.0 → audformat-1.4.2}/docs/create-database.rst +0 -0
  63. {audformat-1.4.0 → audformat-1.4.2}/docs/data-conventions.rst +0 -0
  64. {audformat-1.4.0 → audformat-1.4.2}/docs/data-example.rst +0 -0
  65. {audformat-1.4.0 → audformat-1.4.2}/docs/data-format.rst +0 -0
  66. {audformat-1.4.0 → audformat-1.4.2}/docs/data-header.rst +0 -0
  67. {audformat-1.4.0 → audformat-1.4.2}/docs/data-introduction.rst +0 -0
  68. {audformat-1.4.0 → audformat-1.4.2}/docs/data-misc-tables.rst +0 -0
  69. {audformat-1.4.0 → audformat-1.4.2}/docs/data-tables.rst +0 -0
  70. {audformat-1.4.0 → audformat-1.4.2}/docs/emodb-example.rst +0 -0
  71. {audformat-1.4.0 → audformat-1.4.2}/docs/genindex.rst +0 -0
  72. {audformat-1.4.0 → audformat-1.4.2}/docs/index.rst +0 -0
  73. {audformat-1.4.0 → audformat-1.4.2}/docs/install.rst +0 -0
  74. {audformat-1.4.0 → audformat-1.4.2}/docs/map-scheme.rst +0 -0
  75. {audformat-1.4.0 → audformat-1.4.2}/docs/pics/audformat-database.dot +0 -0
  76. {audformat-1.4.0 → audformat-1.4.2}/docs/pics/audformat-misc-table.dot +0 -0
  77. {audformat-1.4.0 → audformat-1.4.2}/docs/pics/audformat-table.dot +0 -0
  78. {audformat-1.4.0 → audformat-1.4.2}/docs/update-database.rst +0 -0
  79. {audformat-1.4.0 → audformat-1.4.2}/setup.cfg +0 -0
  80. {audformat-1.4.0 → audformat-1.4.2}/tests/conftest.py +0 -0
  81. {audformat-1.4.0 → audformat-1.4.2}/tests/test_attachment.py +0 -0
  82. {audformat-1.4.0 → audformat-1.4.2}/tests/test_column.py +0 -0
  83. {audformat-1.4.0 → audformat-1.4.2}/tests/test_common.py +0 -0
  84. {audformat-1.4.0 → audformat-1.4.2}/tests/test_database.py +0 -0
  85. {audformat-1.4.0 → audformat-1.4.2}/tests/test_database_get.py +0 -0
  86. {audformat-1.4.0 → audformat-1.4.2}/tests/test_eq.py +0 -0
  87. {audformat-1.4.0 → audformat-1.4.2}/tests/test_errors.py +0 -0
  88. {audformat-1.4.0 → audformat-1.4.2}/tests/test_scheme.py +0 -0
  89. {audformat-1.4.0 → audformat-1.4.2}/tests/test_utils.py +0 -0
  90. {audformat-1.4.0 → audformat-1.4.2}/tests/test_utils_concat.py +0 -0
@@ -28,7 +28,7 @@ jobs:
28
28
  uses: actions/cache@v4
29
29
  with:
30
30
  path: emodb-src
31
- key: emodb-ubuntu
31
+ key: emodb-src
32
32
 
33
33
  - name: Set up Python ${{ matrix.python-version }}
34
34
  uses: actions/setup-python@v5
@@ -24,7 +24,7 @@ jobs:
24
24
  uses: actions/cache@v4
25
25
  with:
26
26
  path: emodb-src
27
- key: emodb-ubuntu
27
+ key: emodb-src
28
28
 
29
29
  - name: Set up Python
30
30
  uses: actions/setup-python@v5
@@ -40,8 +40,7 @@ jobs:
40
40
  uses: actions/cache@v4
41
41
  with:
42
42
  path: emodb-src
43
- key: emodb-ubuntu
44
- if: matrix.os == 'ubuntu-latest'
43
+ key: emodb-src
45
44
 
46
45
  - name: Set up Python ${{ matrix.python-version }}
47
46
  uses: actions/setup-python@v5
@@ -7,6 +7,34 @@ The format is based on `Keep a Changelog`_,
7
7
  and this project adheres to `Semantic Versioning`_.
8
8
 
9
9
 
10
+ Version 1.4.2 (2026-05-12)
11
+ --------------------------
12
+
13
+ * Changed: exclude ``tests/`` and ``docs/`` folders from the Python package
14
+ * Fixed: ensure ``pandas>=3.0.3`` works with ``audformat``
15
+
16
+
17
+ Version 1.4.1 (2026-04-13)
18
+ --------------------------
19
+
20
+ * Added: include table ID in error messages in the methods
21
+ ``drop_index()``,
22
+ ``extend_index()``,
23
+ ``pick_index()``,
24
+ ``update()``
25
+ of ``audformat.Table``
26
+ and ``audformat.MiscTable``
27
+ if the receiving table is assigned to a database
28
+ * Changed: black list ``pandas``
29
+ versions 3.0.0, 3.0.1, and 3.0.2
30
+ as those contain a serious issue in ``pd.to_timedelta()``
31
+ (`pandas#65150 <https://github.com/pandas-dev/pandas/issues/65150>`_)
32
+ * Fixed: avoid warning when loading a table
33
+ with data points not matching scheme labels.
34
+ As before those points are set to ``None``.
35
+ This is now documented in ``audformat.Table.load()``
36
+
37
+
10
38
  Version 1.4.0 (2026-04-08)
11
39
  --------------------------
12
40
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: audformat
3
- Version: 1.4.0
3
+ Version: 1.4.2
4
4
  Summary: Python implementation of audformat
5
5
  Author: Johannes Wagner, BahaEddine Abrougui
6
6
  Author-email: Hagen Wierstorf <hwierstorf@audeering.com>, Christian Geng <cgeng@audeering.com>
@@ -28,7 +28,7 @@ Requires-Dist: audiofile>=0.4.0
28
28
  Requires-Dist: iso639-lang
29
29
  Requires-Dist: iso3166
30
30
  Requires-Dist: oyaml
31
- Requires-Dist: pandas>=2.1.0
31
+ Requires-Dist: pandas!=3.0.0,!=3.0.1,!=3.0.2,>=2.1.0
32
32
  Requires-Dist: pyarrow>=10.0.1
33
33
  Requires-Dist: pyyaml>=5.4.1
34
34
  Dynamic: license-file
@@ -319,7 +319,7 @@ class Base(HeaderBase):
319
319
  table = self if inplace else self.copy()
320
320
 
321
321
  index = _maybe_convert_dtype_to_string(index)
322
- _assert_table_index(table, index, "drop rows from")
322
+ _assert_table_index(self, index, "drop rows from")
323
323
 
324
324
  index = utils.intersect([table.index, index])
325
325
  new_index = utils.difference([table.index, index])
@@ -356,7 +356,7 @@ class Base(HeaderBase):
356
356
  table = self if inplace else self.copy()
357
357
 
358
358
  index = _maybe_convert_dtype_to_string(index)
359
- _assert_table_index(table, index, "extend")
359
+ _assert_table_index(self, index, "extend")
360
360
 
361
361
  new_index = utils.union([table.index, index])
362
362
  table._df = table.df.reindex(new_index)
@@ -461,6 +461,9 @@ class Base(HeaderBase):
461
461
  otherwise it will raise an error
462
462
  and ask to delete one of the files.
463
463
 
464
+ If a scheme with labels is assigned to a table column,
465
+ values not matching those labels are set to ``None``.
466
+
464
467
  Args:
465
468
  path: file path without extension
466
469
 
@@ -575,7 +578,7 @@ class Base(HeaderBase):
575
578
  table = self if inplace else self.copy()
576
579
 
577
580
  index = _maybe_convert_dtype_to_string(index)
578
- _assert_table_index(table, index, "pick rows from")
581
+ _assert_table_index(self, index, "pick rows from")
579
582
 
580
583
  new_index = utils.intersect([table.index, index])
581
584
  table._df = table.df.reindex(new_index)
@@ -1053,7 +1056,10 @@ class Base(HeaderBase):
1053
1056
  ``"bool"``, and ``"int"`` audformat dtypes
1054
1057
 
1055
1058
  Returns:
1056
- dataframe with converted dtypes
1059
+ dataframe with converted dtypes.
1060
+ For columns with scheme labels,
1061
+ values not in the scheme's labels
1062
+ are set to NaN
1057
1063
 
1058
1064
  """
1059
1065
  # Collect columns with dtypes,
@@ -1116,6 +1122,9 @@ class Base(HeaderBase):
1116
1122
  scheme = self.db.schemes[self.columns[column].scheme_id]
1117
1123
  labels = scheme._labels_to_list()
1118
1124
  dtype = to_categorical_dtype(labels)
1125
+ # Set values not in scheme labels to NaN
1126
+ # https://github.com/audeering/audformat/issues/525
1127
+ df[column] = df[column].where(df[column].isin(labels))
1119
1128
  df[column] = df[column].astype(dtype)
1120
1129
  return df
1121
1130
 
@@ -1922,11 +1931,14 @@ def _assert_table_index(
1922
1931
  operation: str,
1923
1932
  ):
1924
1933
  r"""Raise error if index does not match table."""
1934
+ table_id = getattr(table, "_id", None)
1935
+ table_ref = f" '{table_id}'" if table_id is not None else ""
1925
1936
  if isinstance(table, Table):
1926
1937
  input_type = index_type(index)
1927
1938
  if table.type != input_type:
1928
1939
  raise ValueError(
1929
- f"Cannot {operation} a {table.type} table with a {input_type} index."
1940
+ f"Cannot {operation} a {table.type} "
1941
+ f"table{table_ref} with a {input_type} index."
1930
1942
  )
1931
1943
  elif not utils.is_index_alike([table.index, index]):
1932
1944
  want = (
@@ -1946,7 +1958,7 @@ def _assert_table_index(
1946
1958
  raise ValueError(
1947
1959
  f"Cannot "
1948
1960
  f"{operation} "
1949
- f"table if input index and table index are not alike.\n"
1961
+ f"table{table_ref} if input index and table index are not alike.\n"
1950
1962
  f"Expected index:\n"
1951
1963
  f"\t{want}"
1952
1964
  f"\nbut yours is:\n"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: audformat
3
- Version: 1.4.0
3
+ Version: 1.4.2
4
4
  Summary: Python implementation of audformat
5
5
  Author: Johannes Wagner, BahaEddine Abrougui
6
6
  Author-email: Hagen Wierstorf <hwierstorf@audeering.com>, Christian Geng <cgeng@audeering.com>
@@ -28,7 +28,7 @@ Requires-Dist: audiofile>=0.4.0
28
28
  Requires-Dist: iso639-lang
29
29
  Requires-Dist: iso3166
30
30
  Requires-Dist: oyaml
31
- Requires-Dist: pandas>=2.1.0
31
+ Requires-Dist: pandas!=3.0.0,!=3.0.1,!=3.0.2,>=2.1.0
32
32
  Requires-Dist: pyarrow>=10.0.1
33
33
  Requires-Dist: pyyaml>=5.4.1
34
34
  Dynamic: license-file
@@ -3,6 +3,6 @@ audiofile>=0.4.0
3
3
  iso639-lang
4
4
  iso3166
5
5
  oyaml
6
- pandas>=2.1.0
6
+ pandas!=3.0.0,!=3.0.1,!=3.0.2,>=2.1.0
7
7
  pyarrow>=10.0.1
8
8
  pyyaml>=5.4.1
@@ -0,0 +1 @@
1
+ audformat
@@ -38,7 +38,10 @@ dependencies = [
38
38
  'iso639-lang',
39
39
  'iso3166',
40
40
  'oyaml',
41
- 'pandas >=2.1.0', # for pyarrow -> timedelta conversion
41
+ # >=2.1.0 for pyarrow -> timedelta conversion
42
+ # !=3.0.0, !=3.0.1, !=3.0.2 for pandas timedelta issue
43
+ # (https://github.com/audeering/audformat/issues/529)
44
+ 'pandas >=2.1.0, !=3.0.0, !=3.0.1, !=3.0.2',
42
45
  'pyarrow >=10.0.1', # for pyarrow strings in pandas
43
46
  'pyyaml >=5.4.1',
44
47
  ]
@@ -226,6 +229,7 @@ convention = 'google'
226
229
  #
227
230
  # Find all (sub-)modules of the Python package
228
231
  [tool.setuptools.packages.find]
232
+ include = ['audformat*']
229
233
 
230
234
  # ----- setuptools_scm ----------------------------------------------------
231
235
  #
@@ -1,3 +1,4 @@
1
+ import numpy as np
1
2
  import pandas as pd
2
3
  import pytest
3
4
 
@@ -316,6 +317,74 @@ def test_segmented_index_dtype(files, starts, ends):
316
317
  assert index.get_level_values("end").dtype == "timedelta64[ns]"
317
318
 
318
319
 
320
+ @pytest.mark.parametrize(
321
+ "files, starts, ends",
322
+ [
323
+ (["f1.wav"] * 2, [1.0, 2.0], [2.0, 3.0]),
324
+ (["f1.wav"] * 2, [1.01, 2.0], [1.02, 3.0]),
325
+ (["f1.wav"] * 2, [1.0, 2.01], [2.0, 3.01]),
326
+ (["f1.wav"] * 2, [1, 2.01], [2, 3.01]),
327
+ ],
328
+ )
329
+ def test_segmented_index_seconds(files, starts, ends):
330
+ """Check that the total seconds of the segmented index are correct.
331
+
332
+ See https://github.com/audeering/audformat/issues/529
333
+ """
334
+ index = audformat.segmented_index(files, starts=starts, ends=ends)
335
+ np.testing.assert_almost_equal(
336
+ index.get_level_values("start").to_series().dt.total_seconds().to_numpy(),
337
+ np.array(starts, dtype=float),
338
+ )
339
+ np.testing.assert_almost_equal(
340
+ index.get_level_values("end").to_series().dt.total_seconds().to_numpy(),
341
+ np.array(ends, dtype=float),
342
+ )
343
+
344
+
345
+ @pytest.mark.parametrize(
346
+ "times, expected_seconds",
347
+ [
348
+ # numeric scalars are interpreted as seconds
349
+ (1, 1.0),
350
+ (1.5, 1.5),
351
+ (0.01, 0.01),
352
+ # numeric iterables are interpreted as seconds
353
+ ([1.0, 2.0], [1.0, 2.0]),
354
+ ([1.0, 1.01], [1.0, 1.01]), # see issue #529
355
+ ([1, 2], [1.0, 2.0]),
356
+ ((1.0, 2.0), [1.0, 2.0]),
357
+ (np.array([1.0, 1.01]), [1.0, 1.01]),
358
+ (pd.Series([1.0, 1.01]), [1.0, 1.01]),
359
+ (pd.Index([1.0, 1.01]), [1.0, 1.01]),
360
+ # string inputs use pandas unit parsing (fallback path)
361
+ ("1s", 1.0),
362
+ ("500ms", 0.5),
363
+ (["1s", "500ms"], [1.0, 0.5]),
364
+ # empty iterable
365
+ ([], []),
366
+ ],
367
+ )
368
+ def test_to_timedelta(times, expected_seconds):
369
+ """Check audformat.core.index.to_timedelta() helper.
370
+
371
+ The helper must always return ``timedelta64[ns]`` resolution
372
+ and treat numeric inputs as seconds.
373
+
374
+ """
375
+ result = audformat.core.index.to_timedelta(times)
376
+ if np.isscalar(expected_seconds):
377
+ assert isinstance(result, pd.Timedelta)
378
+ assert result.unit == "ns"
379
+ assert result.total_seconds() == pytest.approx(expected_seconds)
380
+ else:
381
+ assert result.dtype == "timedelta64[ns]"
382
+ np.testing.assert_almost_equal(
383
+ pd.Series(result).dt.total_seconds().to_numpy(),
384
+ np.array(expected_seconds, dtype=float),
385
+ )
386
+
387
+
319
388
  @pytest.mark.parametrize(
320
389
  "index, index_type",
321
390
  [
@@ -1,3 +1,5 @@
1
+ import os
2
+
1
3
  import numpy as np
2
4
  import pandas as pd
3
5
  import pytest
@@ -1096,6 +1098,51 @@ def test_drop_and_pick_index():
1096
1098
  pytest.DB[table_id].pick_index(index).get()
1097
1099
 
1098
1100
 
1101
+ def test_index_mismatch_error_includes_table_id():
1102
+ # See https://github.com/audeering/audformat/issues/524
1103
+ # When the misc table is assigned to a database,
1104
+ # the error message should reference the table id
1105
+ # so the user can identify which table is affected.
1106
+ db = audformat.testing.create_db(minimal=True)
1107
+ db["misc"] = audformat.MiscTable(pd.Index([0, 1], name="id", dtype="Int64"))
1108
+ bad_index = pd.Index(["a"], name="file", dtype="string")
1109
+
1110
+ # Table assigned to db: id appears in the error message
1111
+ with pytest.raises(
1112
+ ValueError,
1113
+ match=r"Cannot extend table 'misc' "
1114
+ r"if input index and table index are not alike\.",
1115
+ ):
1116
+ db["misc"].extend_index(bad_index)
1117
+ with pytest.raises(
1118
+ ValueError,
1119
+ match=r"Cannot drop rows from table 'misc' "
1120
+ r"if input index and table index are not alike\.",
1121
+ ):
1122
+ db["misc"].drop_index(bad_index)
1123
+ with pytest.raises(
1124
+ ValueError,
1125
+ match=r"Cannot pick rows from table 'misc' "
1126
+ r"if input index and table index are not alike\.",
1127
+ ):
1128
+ db["misc"].pick_index(bad_index)
1129
+ db["other"] = audformat.MiscTable(bad_index)
1130
+ with pytest.raises(
1131
+ ValueError,
1132
+ match=r"Cannot update table 'misc' "
1133
+ r"if input index and table index are not alike\.",
1134
+ ):
1135
+ db["misc"].update(db["other"])
1136
+
1137
+ # Standalone table: no id reference, no spurious quotes
1138
+ standalone = audformat.MiscTable(pd.Index([0, 1], name="id", dtype="Int64"))
1139
+ with pytest.raises(
1140
+ ValueError,
1141
+ match=r"Cannot extend table if input index and table index are not alike\.",
1142
+ ):
1143
+ standalone.extend_index(bad_index)
1144
+
1145
+
1099
1146
  def test_drop_extend_and_pick_index_order():
1100
1147
  # Ensure order of index is preserved.
1101
1148
  index = pd.Index([4, 3, 2, 1], name="idx")
@@ -1348,12 +1395,15 @@ def test_load_old_pickle(tmpdir):
1348
1395
  db.schemes["column"] = audformat.Scheme(audformat.define.DataType.OBJECT)
1349
1396
  db["misc"]["column"] = audformat.Column(scheme_id="column")
1350
1397
  db["misc"]["column"].set(y.values)
1351
- db_root = tmpdir.join("db")
1352
- db.save(db_root, storage_format="pkl")
1398
+ db_root = str(tmpdir.join("db"))
1353
1399
 
1354
1400
  # Change scheme dtype to string and store header again
1401
+ # and write bare DataFrame pickle
1402
+ # (simulating pre-1.4.0 format without version wrapper)
1355
1403
  db.schemes["column"] = audformat.Scheme(audformat.define.DataType.STRING)
1356
1404
  db.save(db_root, header_only=True)
1405
+ df = pd.DataFrame({"column": y}, index=index)
1406
+ df.to_pickle(os.path.join(db_root, "db.misc.pkl"), protocol=4)
1357
1407
 
1358
1408
  # Load and check that dtype is string
1359
1409
  db_new = audformat.Database.load(db_root)
@@ -2,6 +2,7 @@ import os
2
2
  import random
3
3
  import re
4
4
  import time
5
+ import warnings
5
6
 
6
7
  import numpy as np
7
8
  import pandas as pd
@@ -554,6 +555,49 @@ def test_drop_and_pick_index():
554
555
  pytest.DB["files"].pick_index(index).get()
555
556
 
556
557
 
558
+ def test_index_mismatch_error_includes_table_id():
559
+ # See https://github.com/audeering/audformat/issues/524
560
+ # When the table is assigned to a database,
561
+ # the error message should reference the table id
562
+ # so the user can identify which table is affected.
563
+ db = audformat.testing.create_db(minimal=True)
564
+ db["files"] = audformat.Table(audformat.filewise_index(["f1.wav"]))
565
+ bad_index = audformat.segmented_index(files=["f1.wav"], starts=["0s"], ends=["1s"])
566
+
567
+ # Table assigned to db: id appears in the error message
568
+ with pytest.raises(
569
+ ValueError,
570
+ match=r"Cannot extend a filewise table 'files' with a segmented index\.",
571
+ ):
572
+ db["files"].extend_index(bad_index)
573
+ with pytest.raises(
574
+ ValueError,
575
+ match=r"Cannot drop rows from a filewise table 'files' "
576
+ r"with a segmented index\.",
577
+ ):
578
+ db["files"].drop_index(bad_index)
579
+ with pytest.raises(
580
+ ValueError,
581
+ match=r"Cannot pick rows from a filewise table 'files' "
582
+ r"with a segmented index\.",
583
+ ):
584
+ db["files"].pick_index(bad_index)
585
+ db["segments"] = audformat.Table(bad_index)
586
+ with pytest.raises(
587
+ ValueError,
588
+ match=r"Cannot update a filewise table 'files' with a segmented index\.",
589
+ ):
590
+ db["files"].update(db["segments"])
591
+
592
+ # Standalone table: no id reference, no spurious quotes
593
+ standalone = audformat.Table(audformat.filewise_index(["f1.wav"]))
594
+ with pytest.raises(
595
+ ValueError,
596
+ match=r"Cannot extend a filewise table with a segmented index\.",
597
+ ):
598
+ standalone.extend_index(bad_index)
599
+
600
+
557
601
  def test_drop_extend_and_pick_index_order():
558
602
  # Ensure order of index is preserved.
559
603
  index = audformat.filewise_index(["f4", "f3", "f2", "f1"])
@@ -1823,6 +1867,43 @@ def test_save_and_load(tmpdir, storage_format):
1823
1867
  pd.testing.assert_frame_equal(db[table_id].df, expected_df)
1824
1868
 
1825
1869
 
1870
+ @pytest.mark.parametrize("storage_format", ["csv", "parquet"])
1871
+ def test_save_and_load_labels_removed(tmpdir, storage_format):
1872
+ r"""Test loading table after labels were removed from scheme.
1873
+
1874
+ When a table is saved with labels ``["a", "b", "c"]``
1875
+ but the scheme is later changed to ``["a", "b"]``,
1876
+ loading should not raise a warning
1877
+ about values not in the categorical dtype's categories,
1878
+ but values should be replaced with ``None``.
1879
+
1880
+ """
1881
+ db = audformat.Database("test")
1882
+ db.schemes["label"] = audformat.Scheme(labels=["a", "b", "c"])
1883
+ index = audformat.filewise_index(["f1", "f2", "f3"])
1884
+ db["table"] = audformat.Table(index)
1885
+ db["table"]["col"] = audformat.Column(scheme_id="label")
1886
+ db["table"]["col"].set(["a", "b", "c"])
1887
+
1888
+ path = os.path.join(tmpdir, "table")
1889
+ db["table"].save(path, storage_format=storage_format)
1890
+
1891
+ # Remove label "c" from scheme
1892
+ db.schemes["label"] = audformat.Scheme(labels=["a", "b"])
1893
+
1894
+ with warnings.catch_warnings():
1895
+ warnings.simplefilter("error")
1896
+ db["table"].load(path)
1897
+
1898
+ # "c" was removed from labels and should now be NaN
1899
+ categories = pd.Index(["a", "b"], dtype="object")
1900
+ expected = pd.DataFrame(
1901
+ {"col": pd.Categorical(["a", "b", None], categories=categories)},
1902
+ index=audformat.filewise_index(["f1", "f2", "f3"]),
1903
+ )
1904
+ pd.testing.assert_frame_equal(db["table"].df, expected)
1905
+
1906
+
1826
1907
  @pytest.mark.parametrize(
1827
1908
  "storage_format, expected_error, expected_error_msg",
1828
1909
  [
@@ -1,6 +0,0 @@
1
- audformat
2
- benchmarks
3
- dist
4
- docs
5
- emodb-src
6
- tests
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes