audformat 1.3.0__tar.gz → 1.3.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 (95) hide show
  1. {audformat-1.3.0 → audformat-1.3.2}/.github/workflows/publish.yml +1 -1
  2. {audformat-1.3.0 → audformat-1.3.2}/.github/workflows/test.yml +11 -4
  3. {audformat-1.3.0 → audformat-1.3.2}/.pre-commit-config.yaml +2 -2
  4. {audformat-1.3.0 → audformat-1.3.2}/CHANGELOG.rst +26 -0
  5. {audformat-1.3.0 → audformat-1.3.2}/CONTRIBUTING.rst +1 -1
  6. {audformat-1.3.0 → audformat-1.3.2}/PKG-INFO +6 -3
  7. {audformat-1.3.0 → audformat-1.3.2}/audformat/core/attachment.py +1 -2
  8. {audformat-1.3.0 → audformat-1.3.2}/audformat/core/column.py +36 -26
  9. {audformat-1.3.0 → audformat-1.3.2}/audformat/core/common.py +10 -7
  10. {audformat-1.3.0 → audformat-1.3.2}/audformat/core/conftest.py +16 -0
  11. {audformat-1.3.0 → audformat-1.3.2}/audformat/core/database.py +81 -43
  12. {audformat-1.3.0 → audformat-1.3.2}/audformat/core/errors.py +4 -4
  13. {audformat-1.3.0 → audformat-1.3.2}/audformat/core/index.py +8 -8
  14. {audformat-1.3.0 → audformat-1.3.2}/audformat/core/media.py +2 -2
  15. {audformat-1.3.0 → audformat-1.3.2}/audformat/core/scheme.py +15 -17
  16. {audformat-1.3.0 → audformat-1.3.2}/audformat/core/table.py +24 -33
  17. {audformat-1.3.0 → audformat-1.3.2}/audformat/core/testing.py +17 -27
  18. {audformat-1.3.0 → audformat-1.3.2}/audformat/core/typing.py +2 -0
  19. {audformat-1.3.0 → audformat-1.3.2}/audformat/core/utils.py +71 -76
  20. {audformat-1.3.0 → audformat-1.3.2}/audformat.egg-info/PKG-INFO +6 -3
  21. {audformat-1.3.0 → audformat-1.3.2}/audformat.egg-info/SOURCES.txt +1 -0
  22. {audformat-1.3.0 → audformat-1.3.2}/audformat.egg-info/requires.txt +1 -1
  23. {audformat-1.3.0 → audformat-1.3.2}/docs/accessing-data.rst +17 -18
  24. audformat-1.3.2/docs/combine-tables.rst +199 -0
  25. {audformat-1.3.0 → audformat-1.3.2}/docs/conf.py +0 -1
  26. audformat-1.3.2/docs/conftest.py +24 -0
  27. {audformat-1.3.0 → audformat-1.3.2}/docs/create-database.rst +65 -18
  28. {audformat-1.3.0 → audformat-1.3.2}/docs/data-conventions.rst +115 -29
  29. audformat-1.3.2/docs/data-example.rst +143 -0
  30. {audformat-1.3.0 → audformat-1.3.2}/docs/data-header.rst +114 -101
  31. {audformat-1.3.0 → audformat-1.3.2}/docs/data-misc-tables.rst +35 -42
  32. audformat-1.3.2/docs/data-tables.rst +200 -0
  33. {audformat-1.3.0 → audformat-1.3.2}/docs/emodb-example.rst +132 -47
  34. audformat-1.3.2/docs/map-scheme.rst +148 -0
  35. {audformat-1.3.0 → audformat-1.3.2}/docs/requirements.txt +0 -2
  36. {audformat-1.3.0 → audformat-1.3.2}/docs/update-database.rst +89 -14
  37. {audformat-1.3.0 → audformat-1.3.2}/pyproject.toml +4 -3
  38. {audformat-1.3.0 → audformat-1.3.2}/tests/requirements.txt +1 -1
  39. {audformat-1.3.0 → audformat-1.3.2}/tests/test_database.py +36 -1
  40. {audformat-1.3.0 → audformat-1.3.2}/tests/test_database_get.py +270 -0
  41. {audformat-1.3.0 → audformat-1.3.2}/tests/test_misc_table.py +3 -3
  42. {audformat-1.3.0 → audformat-1.3.2}/tests/test_scheme.py +80 -23
  43. {audformat-1.3.0 → audformat-1.3.2}/tests/test_table.py +4 -3
  44. audformat-1.3.0/docs/combine-tables.rst +0 -132
  45. audformat-1.3.0/docs/data-example.rst +0 -50
  46. audformat-1.3.0/docs/data-tables.rst +0 -187
  47. audformat-1.3.0/docs/map-scheme.rst +0 -124
  48. {audformat-1.3.0 → audformat-1.3.2}/.github/workflows/doc.yml +0 -0
  49. {audformat-1.3.0 → audformat-1.3.2}/.github/workflows/linter.yml +0 -0
  50. {audformat-1.3.0 → audformat-1.3.2}/.gitignore +0 -0
  51. {audformat-1.3.0 → audformat-1.3.2}/LICENSE +0 -0
  52. {audformat-1.3.0 → audformat-1.3.2}/README.rst +0 -0
  53. {audformat-1.3.0 → audformat-1.3.2}/audformat/__init__.py +0 -0
  54. {audformat-1.3.0 → audformat-1.3.2}/audformat/core/__init__.py +0 -0
  55. {audformat-1.3.0 → audformat-1.3.2}/audformat/core/define.py +0 -0
  56. {audformat-1.3.0 → audformat-1.3.2}/audformat/core/rater.py +0 -0
  57. {audformat-1.3.0 → audformat-1.3.2}/audformat/core/split.py +0 -0
  58. {audformat-1.3.0 → audformat-1.3.2}/audformat/define/__init__.py +0 -0
  59. {audformat-1.3.0 → audformat-1.3.2}/audformat/errors/__init__.py +0 -0
  60. {audformat-1.3.0 → audformat-1.3.2}/audformat/testing/__init__.py +0 -0
  61. {audformat-1.3.0 → audformat-1.3.2}/audformat/utils/__init__.py +0 -0
  62. {audformat-1.3.0 → audformat-1.3.2}/audformat.egg-info/dependency_links.txt +0 -0
  63. {audformat-1.3.0 → audformat-1.3.2}/audformat.egg-info/top_level.txt +0 -0
  64. {audformat-1.3.0 → audformat-1.3.2}/benchmarks/benchmark_union.py +0 -0
  65. {audformat-1.3.0 → audformat-1.3.2}/docs/api/audformat.define.rst +0 -0
  66. {audformat-1.3.0 → audformat-1.3.2}/docs/api/audformat.errors.rst +0 -0
  67. {audformat-1.3.0 → audformat-1.3.2}/docs/api/audformat.rst +0 -0
  68. {audformat-1.3.0 → audformat-1.3.2}/docs/api/audformat.testing.rst +0 -0
  69. {audformat-1.3.0 → audformat-1.3.2}/docs/api/audformat.utils.rst +0 -0
  70. {audformat-1.3.0 → audformat-1.3.2}/docs/api-src/audformat.define.rst +0 -0
  71. {audformat-1.3.0 → audformat-1.3.2}/docs/api-src/audformat.errors.rst +0 -0
  72. {audformat-1.3.0 → audformat-1.3.2}/docs/api-src/audformat.rst +0 -0
  73. {audformat-1.3.0 → audformat-1.3.2}/docs/api-src/audformat.testing.rst +0 -0
  74. {audformat-1.3.0 → audformat-1.3.2}/docs/api-src/audformat.utils.rst +0 -0
  75. {audformat-1.3.0 → audformat-1.3.2}/docs/changelog.rst +0 -0
  76. {audformat-1.3.0 → audformat-1.3.2}/docs/contributing.rst +0 -0
  77. {audformat-1.3.0 → audformat-1.3.2}/docs/data-format.rst +0 -0
  78. {audformat-1.3.0 → audformat-1.3.2}/docs/data-introduction.rst +0 -0
  79. {audformat-1.3.0 → audformat-1.3.2}/docs/genindex.rst +0 -0
  80. {audformat-1.3.0 → audformat-1.3.2}/docs/index.rst +0 -0
  81. {audformat-1.3.0 → audformat-1.3.2}/docs/install.rst +0 -0
  82. {audformat-1.3.0 → audformat-1.3.2}/docs/pics/audformat-database.dot +0 -0
  83. {audformat-1.3.0 → audformat-1.3.2}/docs/pics/audformat-misc-table.dot +0 -0
  84. {audformat-1.3.0 → audformat-1.3.2}/docs/pics/audformat-table.dot +0 -0
  85. {audformat-1.3.0 → audformat-1.3.2}/requirements.txt +0 -0
  86. {audformat-1.3.0 → audformat-1.3.2}/setup.cfg +0 -0
  87. {audformat-1.3.0 → audformat-1.3.2}/tests/conftest.py +0 -0
  88. {audformat-1.3.0 → audformat-1.3.2}/tests/test_attachment.py +0 -0
  89. {audformat-1.3.0 → audformat-1.3.2}/tests/test_column.py +0 -0
  90. {audformat-1.3.0 → audformat-1.3.2}/tests/test_common.py +0 -0
  91. {audformat-1.3.0 → audformat-1.3.2}/tests/test_eq.py +0 -0
  92. {audformat-1.3.0 → audformat-1.3.2}/tests/test_errors.py +0 -0
  93. {audformat-1.3.0 → audformat-1.3.2}/tests/test_index.py +0 -0
  94. {audformat-1.3.0 → audformat-1.3.2}/tests/test_utils.py +0 -0
  95. {audformat-1.3.0 → audformat-1.3.2}/tests/test_utils_concat.py +0 -0
@@ -43,7 +43,7 @@ jobs:
43
43
  - name: Publish Python package to PyPI
44
44
  uses: pypa/gh-action-pypi-publish@release/v1
45
45
 
46
- # Docuemntation
46
+ # Documentation
47
47
  - name: Prepare Ubuntu
48
48
  run: |
49
49
  sudo apt-get update
@@ -12,26 +12,33 @@ jobs:
12
12
  runs-on: ${{ matrix.os }}
13
13
  strategy:
14
14
  matrix:
15
- os: [ ubuntu-20.04, windows-latest, macOS-latest ]
15
+ os: [ ubuntu-latest, windows-latest, macOS-latest ]
16
16
  python-version: [ '3.10' ]
17
17
  include:
18
18
  - os: ubuntu-latest
19
19
  python-version: '3.9'
20
20
  - os: ubuntu-latest
21
21
  python-version: '3.11'
22
+ - os: ubuntu-latest
23
+ python-version: '3.12'
24
+ - os: ubuntu-latest
25
+ python-version: '3.13'
22
26
  - os: ubuntu-latest
23
27
  python-version: '3.9'
24
28
  requirements: 'minimum'
25
29
 
26
30
  steps:
27
31
  - uses: actions/checkout@v4
32
+ with:
33
+ fetch-tags: true
34
+ fetch-depth: 50
28
35
 
29
36
  - name: Cache emodb
30
37
  uses: actions/cache@v4
31
38
  with:
32
39
  path: emodb-src
33
40
  key: emodb-ubuntu
34
- if: matrix.os == 'ubuntu-20.04'
41
+ if: matrix.os == 'ubuntu-latest'
35
42
 
36
43
  - name: Set up Python ${{ matrix.python-version }}
37
44
  uses: actions/setup-python@v5
@@ -42,7 +49,7 @@ jobs:
42
49
  run: |
43
50
  sudo apt-get update
44
51
  sudo apt-get install --no-install-recommends --yes libsndfile1
45
- if: matrix.os == 'ubuntu-latest' || matrix.os == 'ubuntu-20.04'
52
+ if: matrix.os == 'ubuntu-latest'
46
53
 
47
54
  - name: Install dependencies
48
55
  run: |
@@ -73,4 +80,4 @@ jobs:
73
80
  with:
74
81
  token: ${{ secrets.CODECOV_TOKEN }}
75
82
  file: ./coverage.xml
76
- if: matrix.os == 'ubuntu-20.04'
83
+ if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10'
@@ -13,13 +13,13 @@ default_language_version:
13
13
 
14
14
  repos:
15
15
  - repo: https://github.com/astral-sh/ruff-pre-commit
16
- rev: v0.1.8
16
+ rev: v0.7.0
17
17
  hooks:
18
18
  - id: ruff
19
19
  args: [ --fix ]
20
20
  - id: ruff-format
21
21
  - repo: https://github.com/codespell-project/codespell
22
- rev: v2.2.4
22
+ rev: v2.3.0
23
23
  hooks:
24
24
  - id: codespell
25
25
  additional_dependencies:
@@ -7,6 +7,32 @@ The format is based on `Keep a Changelog`_,
7
7
  and this project adheres to `Semantic Versioning`_.
8
8
 
9
9
 
10
+ Version 1.3.2 (2025-05-27)
11
+ --------------------------
12
+
13
+ * Added: support for Python 3.13
14
+ * Added: support for Python 3.12
15
+ * Fixed: ``audformat.Database.update()`` for misc tables
16
+ * Fixed: ``audformat.Database.get()``
17
+ if ``scheme`` is stored in a segmented table,
18
+ and ``additional_schemes`` are stored in filewise tables.
19
+ Before,
20
+ values of the additional schemes were set to ``<NA>``
21
+ * Fixed: if ``audformat.Column.set()`` assigns values
22
+ to a column with scheme labels
23
+ given by a misc table,
24
+ the misc table is only converted once to a dictionary
25
+ instead of once for each value
26
+
27
+
28
+ Version 1.3.1 (2024-09-16)
29
+ --------------------------
30
+
31
+ * Changed: replace unmaintained ``iso-639`` dependency
32
+ with ``iso639-lang``
33
+ * Fixed: ensure ``poetry`` can manage ``audformat``
34
+
35
+
10
36
  Version 1.3.0 (2024-07-18)
11
37
  --------------------------
12
38
 
@@ -97,7 +97,7 @@ It is also possible to automatically check if all links are still valid::
97
97
 
98
98
  python -m sphinx docs/ build/sphinx/html -b linkcheck
99
99
 
100
- .. _Sphinx: http://sphinx-doc.org
100
+ .. _Sphinx: https://www.sphinx-doc.org
101
101
 
102
102
 
103
103
  Running the Tests
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: audformat
3
- Version: 1.3.0
3
+ Version: 1.3.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>
@@ -45,18 +45,21 @@ Classifier: Programming Language :: Python :: 3
45
45
  Classifier: Programming Language :: Python :: 3.9
46
46
  Classifier: Programming Language :: Python :: 3.10
47
47
  Classifier: Programming Language :: Python :: 3.11
48
+ Classifier: Programming Language :: Python :: 3.12
49
+ Classifier: Programming Language :: Python :: 3.13
48
50
  Classifier: Topic :: Scientific/Engineering
49
51
  Requires-Python: >=3.9
50
52
  Description-Content-Type: text/x-rst
51
53
  License-File: LICENSE
52
54
  Requires-Dist: audeer>=2.0.0
53
55
  Requires-Dist: audiofile>=0.4.0
54
- Requires-Dist: iso-639
56
+ Requires-Dist: iso639-lang
55
57
  Requires-Dist: iso3166
56
58
  Requires-Dist: oyaml
57
59
  Requires-Dist: pandas>=2.1.0
58
60
  Requires-Dist: pyarrow>=10.0.1
59
61
  Requires-Dist: pyyaml>=5.4.1
62
+ Dynamic: license-file
60
63
 
61
64
  =========
62
65
  audformat
@@ -1,5 +1,4 @@
1
1
  import os
2
- import typing
3
2
 
4
3
  import audeer
5
4
 
@@ -62,7 +61,7 @@ class Attachment(HeaderBase):
62
61
  @property
63
62
  def files(
64
63
  self,
65
- ) -> typing.List[str]:
64
+ ) -> list[str]:
66
65
  r"""List all files that are part of the attachment.
67
66
 
68
67
  List recursively the relative path
@@ -1,5 +1,6 @@
1
- from __future__ import annotations # allow typing without string
1
+ from __future__ import annotations
2
2
 
3
+ import itertools
3
4
  import typing
4
5
  import warnings
5
6
 
@@ -29,7 +30,7 @@ def assert_values(
29
30
  scheme: Scheme,
30
31
  ):
31
32
  r"""Raise error if values do not match scheme."""
32
- bad_values = []
33
+ error_msg = ""
33
34
 
34
35
  if (
35
36
  scheme.labels is not None
@@ -40,29 +41,38 @@ def assert_values(
40
41
  values = [values]
41
42
  elif isinstance(values, pd.Series):
42
43
  values = values.values
43
- elif isinstance(values, np.ndarray):
44
- if scheme.is_numeric:
45
- # Support type object with None entries,
46
- # which need to be converted to NaN
47
- # to support min/max
48
- values = values.astype(float)
49
- values = [
50
- np.nanmin(values),
51
- np.nanmax(values),
52
- ]
53
- # Get unique values and preserve order
54
- values = list(dict.fromkeys(values))
55
- bad_values = [value for value in values if value not in scheme]
56
-
57
- if len(bad_values) > 0:
58
- max_display = 10
59
- values = str(bad_values[:max_display])[1:-1]
60
- if len(bad_values) > max_display:
61
- values += ", ..."
44
+ values = [v for v in values if v is not None and not pd.isna(v)]
45
+ if not values:
46
+ return
47
+
48
+ if scheme.labels is not None:
49
+ bad_values = set(values) - set(scheme.labels_as_list)
50
+ if len(bad_values) > 0:
51
+ # Convert only `max_display` entries from set to list
52
+ max_display = 10
53
+ show_bad_values = sorted(
54
+ [v for v in itertools.islice(bad_values, max_display)]
55
+ )
56
+ error_msg = str(show_bad_values)[1:-1]
57
+ if len(bad_values) > max_display:
58
+ error_msg += ", ..."
59
+ error_msg += "\n"
60
+
61
+ if scheme.is_numeric:
62
+ if scheme.minimum is not None:
63
+ min_value = min(values)
64
+ if float(min_value) < scheme.minimum:
65
+ error_msg += f"minimum {min_value} smaller than scheme minimum\n"
66
+ if scheme.maximum is not None:
67
+ max_value = max(values)
68
+ if float(max_value) > scheme.maximum:
69
+ error_msg += f"maximum {max_value} larger than scheme maximum\n"
70
+
71
+ if error_msg:
62
72
  raise ValueError(
63
73
  f"Some value(s) do not match scheme\n{scheme}\n"
64
74
  f"with scheme ID '{scheme._id}':\n"
65
- f"{values}"
75
+ f"{error_msg}"
66
76
  )
67
77
 
68
78
 
@@ -103,7 +113,7 @@ class Column(HeaderBase):
103
113
  self._id = None
104
114
 
105
115
  @property
106
- def rater(self) -> typing.Optional[Rater]:
116
+ def rater(self) -> Rater | None:
107
117
  r"""Rater object.
108
118
 
109
119
  Returns:
@@ -118,7 +128,7 @@ class Column(HeaderBase):
118
128
  return self.table.db.raters[self.rater_id]
119
129
 
120
130
  @property
121
- def scheme(self) -> typing.Optional[Scheme]:
131
+ def scheme(self) -> Scheme | None:
122
132
  r"""Scheme object.
123
133
 
124
134
  Returns:
@@ -151,7 +161,7 @@ class Column(HeaderBase):
151
161
  as_segmented: bool = False,
152
162
  allow_nat: bool = True,
153
163
  root: str = None,
154
- num_workers: typing.Optional[int] = 1,
164
+ num_workers: int | None = 1,
155
165
  verbose: bool = False,
156
166
  ) -> pd.Series:
157
167
  r"""Get labels.
@@ -377,7 +387,7 @@ class Column(HeaderBase):
377
387
 
378
388
  def __eq__(
379
389
  self,
380
- other: "Column",
390
+ other: Column,
381
391
  ) -> bool:
382
392
  r"""Compare if column equals another column."""
383
393
  if self.dump() != other.dump():
@@ -1,8 +1,11 @@
1
+ from __future__ import annotations
2
+
1
3
  from collections import OrderedDict
4
+ from collections.abc import Callable
5
+ from collections.abc import Sequence
2
6
  import inspect
3
7
  import os
4
8
  import textwrap
5
- import typing
6
9
 
7
10
  import oyaml as yaml
8
11
  import pandas as pd
@@ -72,8 +75,8 @@ class HeaderDict(OrderedDict):
72
75
  *args,
73
76
  sort_by_key: bool = True,
74
77
  value_type: type = None,
75
- get_callback: typing.Callable = None,
76
- set_callback: typing.Callable = None,
78
+ get_callback: Callable = None,
79
+ set_callback: Callable = None,
77
80
  **kwargs,
78
81
  ):
79
82
  self.sort_by_key = sort_by_key
@@ -223,7 +226,7 @@ class HeaderBase:
223
226
  def from_dict(
224
227
  self,
225
228
  d: dict,
226
- ignore_keys: typing.Sequence[str] = None,
229
+ ignore_keys: Sequence[str] = None,
227
230
  ):
228
231
  r"""Deserialize object from dictionary.
229
232
 
@@ -267,7 +270,7 @@ class HeaderBase:
267
270
 
268
271
  def __eq__(
269
272
  self,
270
- other: "HeaderBase",
273
+ other: HeaderBase,
271
274
  ) -> bool:
272
275
  return self.dump() == other.dump()
273
276
 
@@ -328,7 +331,7 @@ def series_to_html(self): # pragma: no cover
328
331
  return df.to_html()
329
332
 
330
333
 
331
- def to_audformat_dtype(dtype: typing.Union[str, typing.Type]) -> str:
334
+ def to_audformat_dtype(dtype: str | type) -> str:
332
335
  r"""Convert pandas to audformat dtype."""
333
336
  # bool
334
337
  if pd.api.types.is_bool_dtype(dtype):
@@ -359,7 +362,7 @@ def to_audformat_dtype(dtype: typing.Union[str, typing.Type]) -> str:
359
362
  return define.DataType.OBJECT
360
363
 
361
364
 
362
- def to_pandas_dtype(dtype: str) -> typing.Optional[str]:
365
+ def to_pandas_dtype(dtype: str) -> str | None:
363
366
  r"""Convert audformat to pandas dtype.
364
367
 
365
368
  We use ``"Int64"`` instead of ``"int64"``,
@@ -1,8 +1,13 @@
1
+ from doctest import ELLIPSIS
2
+ from doctest import NORMALIZE_WHITESPACE
1
3
  import os
2
4
  import tempfile
3
5
 
4
6
  import numpy as np
5
7
  import pytest
8
+ import sybil
9
+ from sybil.parsers.rest import DocTestParser
10
+ from sybil.parsers.rest import SkipParser
6
11
 
7
12
  import audiofile
8
13
 
@@ -22,3 +27,14 @@ def prepare_docstring_tests(doctest_namespace):
22
27
  yield
23
28
 
24
29
  os.chdir(current_dir)
30
+
31
+
32
+ parsers = [
33
+ DocTestParser(optionflags=ELLIPSIS + NORMALIZE_WHITESPACE),
34
+ SkipParser(),
35
+ ]
36
+ pytest_collect_file = sybil.Sybil(
37
+ parsers=parsers,
38
+ pattern="*.py",
39
+ fixtures=["prepare_docstring_tests"],
40
+ ).pytest()
@@ -1,8 +1,11 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Callable
4
+ from collections.abc import Sequence
1
5
  import datetime
2
6
  import itertools
3
7
  import os
4
8
  import shutil
5
- import typing
6
9
 
7
10
  import oyaml as yaml
8
11
 
@@ -27,6 +30,8 @@ from audformat.core.errors import BadIdError
27
30
  from audformat.core.errors import BadKeyError
28
31
  from audformat.core.errors import TableExistsError
29
32
  from audformat.core.index import filewise_index
33
+ from audformat.core.index import is_filewise_index
34
+ from audformat.core.index import is_segmented_index
30
35
  from audformat.core.media import Media
31
36
  from audformat.core.rater import Rater
32
37
  from audformat.core.scheme import Scheme
@@ -146,11 +151,11 @@ class Database(HeaderBase):
146
151
  usage: str = define.Usage.UNRESTRICTED,
147
152
  *,
148
153
  expires: datetime.date = None,
149
- languages: typing.Union[str, typing.Sequence[str]] = None,
154
+ languages: str | Sequence[str] = None,
150
155
  description: str = None,
151
156
  author: str = None,
152
157
  organization: str = None,
153
- license: typing.Union[str, define.License] = None,
158
+ license: str | define.License = None,
154
159
  license_url: str = None,
155
160
  meta: dict = None,
156
161
  ):
@@ -264,7 +269,7 @@ class Database(HeaderBase):
264
269
  return all(is_relative_path(f) for f in self.files)
265
270
 
266
271
  @property
267
- def root(self) -> typing.Optional[str]:
272
+ def root(self) -> str | None:
268
273
  r"""Database root directory.
269
274
 
270
275
  Returns ``None`` if database has not been stored yet.
@@ -292,12 +297,8 @@ class Database(HeaderBase):
292
297
 
293
298
  def drop_files(
294
299
  self,
295
- files: typing.Union[
296
- str,
297
- typing.Sequence[str],
298
- typing.Callable[[str], bool],
299
- ],
300
- num_workers: typing.Optional[int] = 1,
300
+ files: (str | Sequence[str] | Callable[[str], bool]),
301
+ num_workers: int | None = 1,
301
302
  verbose: bool = False,
302
303
  ):
303
304
  r"""Drop files from tables.
@@ -323,7 +324,7 @@ class Database(HeaderBase):
323
324
 
324
325
  def drop_tables(
325
326
  self,
326
- table_ids: typing.Union[str, typing.Sequence[str]],
327
+ table_ids: str | Sequence[str],
327
328
  ):
328
329
  r"""Drop (miscellaneous) tables by ID.
329
330
 
@@ -363,7 +364,7 @@ class Database(HeaderBase):
363
364
 
364
365
  def files_duration(
365
366
  self,
366
- files: typing.Union[str, typing.Sequence[str]],
367
+ files: str | Sequence[str],
367
368
  *,
368
369
  root: str = None,
369
370
  ) -> pd.Series:
@@ -438,14 +439,14 @@ class Database(HeaderBase):
438
439
  def get(
439
440
  self,
440
441
  scheme: str,
441
- additional_schemes: typing.Union[str, typing.Sequence] = [],
442
+ additional_schemes: str | Sequence = [],
442
443
  *,
443
- tables: typing.Union[str, typing.Sequence] = None,
444
- splits: typing.Union[str, typing.Sequence] = None,
444
+ tables: str | Sequence = None,
445
+ splits: str | Sequence = None,
445
446
  strict: bool = False,
446
447
  map: bool = True,
447
448
  original_column_names: bool = False,
448
- aggregate_function: typing.Callable[[pd.Series], typing.Any] = None,
449
+ aggregate_function: Callable[[pd.Series], object] = None,
449
450
  aggregate_strategy: str = "mismatch",
450
451
  ) -> pd.DataFrame:
451
452
  r"""Get labels by scheme.
@@ -541,7 +542,11 @@ class Database(HeaderBase):
541
542
 
542
543
  >>> import audb
543
544
  >>> db = audb.load(
544
- ... "emodb", version="1.4.1", only_metadata=True, full_path=False, verbose=False
545
+ ... "emodb",
546
+ ... version="1.4.1",
547
+ ... only_metadata=True,
548
+ ... full_path=False,
549
+ ... verbose=False,
545
550
  ... )
546
551
  >>> db.get("emotion").head()
547
552
  emotion
@@ -867,6 +872,9 @@ class Database(HeaderBase):
867
872
  original_column_names=original_column_names,
868
873
  aggregate_function=aggregate_function,
869
874
  )
875
+ if is_segmented_index(obj) and is_filewise_index(additional_obj):
876
+ # https://github.com/audeering/audformat/issues/460
877
+ additional_obj = self._expand_filewise_to_segmented(obj, additional_obj)
870
878
  objs.append(additional_obj)
871
879
  if len(objs) > 1:
872
880
  obj = utils.concat(objs)
@@ -878,8 +886,8 @@ class Database(HeaderBase):
878
886
 
879
887
  def map_files(
880
888
  self,
881
- func: typing.Callable[[str], str],
882
- num_workers: typing.Optional[int] = 1,
889
+ func: Callable[[str], str],
890
+ num_workers: int | None = 1,
883
891
  verbose: bool = False,
884
892
  ):
885
893
  r"""Apply function to file names in all tables.
@@ -910,12 +918,8 @@ class Database(HeaderBase):
910
918
 
911
919
  def pick_files(
912
920
  self,
913
- files: typing.Union[
914
- str,
915
- typing.Sequence[str],
916
- typing.Callable[[str], bool],
917
- ],
918
- num_workers: typing.Optional[int] = 1,
921
+ files: (str | Sequence[str] | Callable[[str], bool]),
922
+ num_workers: int | None = 1,
919
923
  verbose: bool = False,
920
924
  ):
921
925
  r"""Pick files from tables.
@@ -941,7 +945,7 @@ class Database(HeaderBase):
941
945
 
942
946
  def pick_tables(
943
947
  self,
944
- table_ids: typing.Union[str, typing.Sequence[str]],
948
+ table_ids: str | Sequence[str],
945
949
  ):
946
950
  r"""Pick (miscellaneous) tables by ID.
947
951
 
@@ -973,7 +977,7 @@ class Database(HeaderBase):
973
977
  storage_format: str = define.TableStorageFormat.PARQUET,
974
978
  update_other_formats: bool = True,
975
979
  header_only: bool = False,
976
- num_workers: typing.Optional[int] = 1,
980
+ num_workers: int | None = 1,
977
981
  verbose: bool = False,
978
982
  ):
979
983
  r"""Save database to disk.
@@ -1034,12 +1038,12 @@ class Database(HeaderBase):
1034
1038
 
1035
1039
  def update(
1036
1040
  self,
1037
- others: typing.Union["Database", typing.Sequence["Database"]],
1041
+ others: Database | Sequence[Database],
1038
1042
  *,
1039
1043
  copy_attachments: bool = False,
1040
1044
  copy_media: bool = False,
1041
1045
  overwrite: bool = False,
1042
- ) -> "Database":
1046
+ ) -> Database:
1043
1047
  r"""Update database with other database(s).
1044
1048
 
1045
1049
  In order to :ref:`update a database <update-a-database>`,
@@ -1117,7 +1121,7 @@ class Database(HeaderBase):
1117
1121
 
1118
1122
  def join_dict(
1119
1123
  field: str,
1120
- ds: typing.Sequence[dict],
1124
+ ds: Sequence[dict],
1121
1125
  ):
1122
1126
  r"""Join list of dictionaries.
1123
1127
 
@@ -1144,7 +1148,7 @@ class Database(HeaderBase):
1144
1148
  def join_field(
1145
1149
  other: Database,
1146
1150
  field: str,
1147
- op: typing.Callable,
1151
+ op: Callable,
1148
1152
  ):
1149
1153
  r"""Join two fields of db header."""
1150
1154
  value1 = self.__dict__[field]
@@ -1246,7 +1250,7 @@ class Database(HeaderBase):
1246
1250
  for other in others:
1247
1251
  for table_id in list(other.misc_tables) + list(other.tables):
1248
1252
  table = other[table_id]
1249
- if table_id in self.tables:
1253
+ if table_id in list(self):
1250
1254
  self[table_id].update(table, overwrite=overwrite)
1251
1255
  else:
1252
1256
  self[table_id] = table.copy()
@@ -1308,7 +1312,7 @@ class Database(HeaderBase):
1308
1312
  def __getitem__(
1309
1313
  self,
1310
1314
  table_id: str,
1311
- ) -> typing.Union[MiscTable, Table]:
1315
+ ) -> MiscTable | Table:
1312
1316
  r"""Get (miscellaneous) table from database.
1313
1317
 
1314
1318
  Args:
@@ -1330,7 +1334,7 @@ class Database(HeaderBase):
1330
1334
 
1331
1335
  def __eq__(
1332
1336
  self,
1333
- other: "Database",
1337
+ other: Database,
1334
1338
  ) -> bool:
1335
1339
  r"""Comparison if database equals another database."""
1336
1340
  if self.dump() != other.dump():
@@ -1342,15 +1346,15 @@ class Database(HeaderBase):
1342
1346
 
1343
1347
  def __iter__(
1344
1348
  self,
1345
- ) -> typing.Union[MiscTable, Table]:
1349
+ ) -> MiscTable | Table:
1346
1350
  r"""Iterate over (miscellaneous) tables of database."""
1347
1351
  yield from sorted(list(self.tables) + list(self.misc_tables))
1348
1352
 
1349
1353
  def __setitem__(
1350
1354
  self,
1351
1355
  table_id: str,
1352
- table: typing.Union[MiscTable, Table],
1353
- ) -> typing.Union[MiscTable, Table]:
1356
+ table: MiscTable | Table,
1357
+ ) -> MiscTable | Table:
1354
1358
  r"""Add table to database.
1355
1359
 
1356
1360
  Args:
@@ -1377,9 +1381,9 @@ class Database(HeaderBase):
1377
1381
  *,
1378
1382
  name: str = "db",
1379
1383
  load_data: bool = False,
1380
- num_workers: typing.Optional[int] = 1,
1384
+ num_workers: int | None = 1,
1381
1385
  verbose: bool = False,
1382
- ) -> "Database":
1386
+ ) -> Database:
1383
1387
  r"""Load database from disk.
1384
1388
 
1385
1389
  Expects a header ``<root>/<name>.yaml``
@@ -1420,7 +1424,7 @@ class Database(HeaderBase):
1420
1424
  if not os.path.exists(path):
1421
1425
  raise FileNotFoundError(path)
1422
1426
 
1423
- with open(path, "r") as fp:
1427
+ with open(path) as fp:
1424
1428
  header = yaml.load(fp, Loader=Loader)
1425
1429
  db = Database.load_header_from_yaml(header)
1426
1430
 
@@ -1463,7 +1467,7 @@ class Database(HeaderBase):
1463
1467
  return db
1464
1468
 
1465
1469
  @staticmethod
1466
- def load_header_from_yaml(header: dict) -> "Database":
1470
+ def load_header_from_yaml(header: dict) -> Database:
1467
1471
  r"""Load database header from YAML.
1468
1472
 
1469
1473
  Args:
@@ -1615,8 +1619,8 @@ class Database(HeaderBase):
1615
1619
  def _set_table(
1616
1620
  self,
1617
1621
  table_id: str,
1618
- table: typing.Union[MiscTable, Table],
1619
- ) -> typing.Union[MiscTable, Table]:
1622
+ table: MiscTable | Table,
1623
+ ) -> MiscTable | Table:
1620
1624
  if isinstance(table, MiscTable) and table_id in self.tables:
1621
1625
  raise TableExistsError(self[table_id].type, table_id)
1622
1626
  elif isinstance(table, Table) and table_id in self.misc_tables:
@@ -1628,3 +1632,37 @@ class Database(HeaderBase):
1628
1632
  table._db = self
1629
1633
  table._id = table_id
1630
1634
  return table
1635
+
1636
+ @staticmethod
1637
+ def _expand_filewise_to_segmented(
1638
+ df_segmented: pd.DataFrame, df_filewise: pd.DataFrame
1639
+ ) -> pd.DataFrame:
1640
+ """Expand filewise dataframe to segments.
1641
+
1642
+ We want to add a column from ``df_filewise`` to ``df_segmented``.
1643
+ As ``df_segmented`` represents a segmented table,
1644
+ we need to convert ``df_filewise`` to a segmented table as well as
1645
+ mapping the filewise labels to each segment.
1646
+
1647
+ Afterwards ``df_segmented`` and ``df_filewise`` can be easily concatenated.
1648
+ ``df_filewise`` is changed in place.
1649
+
1650
+ Args:
1651
+ df_segmented: dataframe representing a segmented table
1652
+ df_filewise: dataframe representing a filewise table
1653
+
1654
+ Returns:
1655
+ dataframe ``df_filewise`` converted to represent a segmented table
1656
+ matching the index of ``df_segmented``
1657
+
1658
+ """
1659
+ # Problem of utils.intersect():
1660
+ # squeezes [f1, f1, f2] to [f1, f2]
1661
+ # so we need to separate intersection from listing files
1662
+ files = df_segmented.index.get_level_values(define.IndexField.FILE)
1663
+ common_files = utils.intersect([df_filewise.index, files])
1664
+ files = files.where(files.isin(common_files)).dropna()
1665
+ # Select matching labels and replace filewise with segmented index
1666
+ df_filewise = df_filewise.loc[files]
1667
+ df_filewise.index = df_segmented.loc[files.drop_duplicates()].index
1668
+ return df_filewise