audformat 1.3.1__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.
- {audformat-1.3.1 → audformat-1.3.2}/.github/workflows/publish.yml +1 -1
- {audformat-1.3.1 → audformat-1.3.2}/.github/workflows/test.yml +8 -4
- {audformat-1.3.1 → audformat-1.3.2}/.pre-commit-config.yaml +2 -2
- {audformat-1.3.1 → audformat-1.3.2}/CHANGELOG.rst +18 -0
- {audformat-1.3.1 → audformat-1.3.2}/CONTRIBUTING.rst +1 -1
- {audformat-1.3.1 → audformat-1.3.2}/PKG-INFO +5 -2
- {audformat-1.3.1 → audformat-1.3.2}/audformat/core/attachment.py +1 -2
- {audformat-1.3.1 → audformat-1.3.2}/audformat/core/column.py +36 -26
- {audformat-1.3.1 → audformat-1.3.2}/audformat/core/common.py +10 -7
- {audformat-1.3.1 → audformat-1.3.2}/audformat/core/conftest.py +16 -0
- {audformat-1.3.1 → audformat-1.3.2}/audformat/core/database.py +81 -43
- {audformat-1.3.1 → audformat-1.3.2}/audformat/core/errors.py +4 -4
- {audformat-1.3.1 → audformat-1.3.2}/audformat/core/index.py +8 -8
- {audformat-1.3.1 → audformat-1.3.2}/audformat/core/media.py +2 -2
- {audformat-1.3.1 → audformat-1.3.2}/audformat/core/scheme.py +15 -17
- {audformat-1.3.1 → audformat-1.3.2}/audformat/core/table.py +24 -33
- {audformat-1.3.1 → audformat-1.3.2}/audformat/core/testing.py +17 -27
- {audformat-1.3.1 → audformat-1.3.2}/audformat/core/typing.py +2 -0
- {audformat-1.3.1 → audformat-1.3.2}/audformat/core/utils.py +65 -52
- {audformat-1.3.1 → audformat-1.3.2}/audformat.egg-info/PKG-INFO +5 -2
- {audformat-1.3.1 → audformat-1.3.2}/audformat.egg-info/SOURCES.txt +1 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/accessing-data.rst +17 -18
- audformat-1.3.2/docs/combine-tables.rst +199 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/conf.py +0 -1
- audformat-1.3.2/docs/conftest.py +24 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/create-database.rst +65 -18
- {audformat-1.3.1 → audformat-1.3.2}/docs/data-conventions.rst +115 -29
- audformat-1.3.2/docs/data-example.rst +143 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/data-header.rst +114 -101
- {audformat-1.3.1 → audformat-1.3.2}/docs/data-misc-tables.rst +35 -42
- audformat-1.3.2/docs/data-tables.rst +200 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/emodb-example.rst +132 -47
- audformat-1.3.2/docs/map-scheme.rst +148 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/requirements.txt +0 -2
- {audformat-1.3.1 → audformat-1.3.2}/docs/update-database.rst +89 -14
- {audformat-1.3.1 → audformat-1.3.2}/pyproject.toml +3 -2
- {audformat-1.3.1 → audformat-1.3.2}/tests/requirements.txt +1 -1
- {audformat-1.3.1 → audformat-1.3.2}/tests/test_database.py +36 -1
- {audformat-1.3.1 → audformat-1.3.2}/tests/test_database_get.py +270 -0
- {audformat-1.3.1 → audformat-1.3.2}/tests/test_misc_table.py +3 -3
- {audformat-1.3.1 → audformat-1.3.2}/tests/test_scheme.py +80 -23
- {audformat-1.3.1 → audformat-1.3.2}/tests/test_table.py +4 -3
- audformat-1.3.1/docs/combine-tables.rst +0 -132
- audformat-1.3.1/docs/data-example.rst +0 -50
- audformat-1.3.1/docs/data-tables.rst +0 -187
- audformat-1.3.1/docs/map-scheme.rst +0 -124
- {audformat-1.3.1 → audformat-1.3.2}/.github/workflows/doc.yml +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/.github/workflows/linter.yml +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/.gitignore +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/LICENSE +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/README.rst +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/audformat/__init__.py +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/audformat/core/__init__.py +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/audformat/core/define.py +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/audformat/core/rater.py +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/audformat/core/split.py +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/audformat/define/__init__.py +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/audformat/errors/__init__.py +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/audformat/testing/__init__.py +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/audformat/utils/__init__.py +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/audformat.egg-info/dependency_links.txt +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/audformat.egg-info/requires.txt +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/audformat.egg-info/top_level.txt +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/benchmarks/benchmark_union.py +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/api/audformat.define.rst +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/api/audformat.errors.rst +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/api/audformat.rst +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/api/audformat.testing.rst +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/api/audformat.utils.rst +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/api-src/audformat.define.rst +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/api-src/audformat.errors.rst +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/api-src/audformat.rst +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/api-src/audformat.testing.rst +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/api-src/audformat.utils.rst +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/changelog.rst +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/contributing.rst +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/data-format.rst +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/data-introduction.rst +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/genindex.rst +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/index.rst +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/install.rst +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/pics/audformat-database.dot +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/pics/audformat-misc-table.dot +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/docs/pics/audformat-table.dot +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/requirements.txt +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/setup.cfg +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/tests/conftest.py +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/tests/test_attachment.py +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/tests/test_column.py +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/tests/test_common.py +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/tests/test_eq.py +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/tests/test_errors.py +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/tests/test_index.py +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/tests/test_utils.py +0 -0
- {audformat-1.3.1 → audformat-1.3.2}/tests/test_utils_concat.py +0 -0
|
@@ -12,13 +12,17 @@ jobs:
|
|
|
12
12
|
runs-on: ${{ matrix.os }}
|
|
13
13
|
strategy:
|
|
14
14
|
matrix:
|
|
15
|
-
os: [ ubuntu-
|
|
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'
|
|
@@ -34,7 +38,7 @@ jobs:
|
|
|
34
38
|
with:
|
|
35
39
|
path: emodb-src
|
|
36
40
|
key: emodb-ubuntu
|
|
37
|
-
if: matrix.os == 'ubuntu-
|
|
41
|
+
if: matrix.os == 'ubuntu-latest'
|
|
38
42
|
|
|
39
43
|
- name: Set up Python ${{ matrix.python-version }}
|
|
40
44
|
uses: actions/setup-python@v5
|
|
@@ -45,7 +49,7 @@ jobs:
|
|
|
45
49
|
run: |
|
|
46
50
|
sudo apt-get update
|
|
47
51
|
sudo apt-get install --no-install-recommends --yes libsndfile1
|
|
48
|
-
if: matrix.os == 'ubuntu-latest'
|
|
52
|
+
if: matrix.os == 'ubuntu-latest'
|
|
49
53
|
|
|
50
54
|
- name: Install dependencies
|
|
51
55
|
run: |
|
|
@@ -76,4 +80,4 @@ jobs:
|
|
|
76
80
|
with:
|
|
77
81
|
token: ${{ secrets.CODECOV_TOKEN }}
|
|
78
82
|
file: ./coverage.xml
|
|
79
|
-
if: matrix.os == 'ubuntu-
|
|
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.
|
|
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.
|
|
22
|
+
rev: v2.3.0
|
|
23
23
|
hooks:
|
|
24
24
|
- id: codespell
|
|
25
25
|
additional_dependencies:
|
|
@@ -7,6 +7,24 @@ 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
|
+
|
|
10
28
|
Version 1.3.1 (2024-09-16)
|
|
11
29
|
--------------------------
|
|
12
30
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: audformat
|
|
3
|
-
Version: 1.3.
|
|
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,6 +45,8 @@ 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
|
|
@@ -57,6 +59,7 @@ 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
|
-
) ->
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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"{
|
|
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) ->
|
|
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) ->
|
|
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:
|
|
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:
|
|
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:
|
|
76
|
-
set_callback:
|
|
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:
|
|
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:
|
|
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:
|
|
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) ->
|
|
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:
|
|
154
|
+
languages: str | Sequence[str] = None,
|
|
150
155
|
description: str = None,
|
|
151
156
|
author: str = None,
|
|
152
157
|
organization: str = None,
|
|
153
|
-
license:
|
|
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) ->
|
|
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:
|
|
296
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
442
|
+
additional_schemes: str | Sequence = [],
|
|
442
443
|
*,
|
|
443
|
-
tables:
|
|
444
|
-
splits:
|
|
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:
|
|
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",
|
|
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:
|
|
882
|
-
num_workers:
|
|
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:
|
|
914
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
-
) ->
|
|
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:
|
|
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:
|
|
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
|
|
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
|
-
) ->
|
|
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:
|
|
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
|
-
) ->
|
|
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:
|
|
1353
|
-
) ->
|
|
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:
|
|
1384
|
+
num_workers: int | None = 1,
|
|
1381
1385
|
verbose: bool = False,
|
|
1382
|
-
) ->
|
|
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
|
|
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) ->
|
|
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:
|
|
1619
|
-
) ->
|
|
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
|