audformat 1.3.2__tar.gz → 1.3.4__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 (92) hide show
  1. {audformat-1.3.2 → audformat-1.3.4}/.github/workflows/doc.yml +12 -11
  2. {audformat-1.3.2 → audformat-1.3.4}/.github/workflows/linter.yml +6 -6
  3. {audformat-1.3.2 → audformat-1.3.4}/.github/workflows/publish.yml +6 -12
  4. {audformat-1.3.2 → audformat-1.3.4}/.github/workflows/test.yml +19 -15
  5. {audformat-1.3.2 → audformat-1.3.4}/.gitignore +1 -0
  6. {audformat-1.3.2 → audformat-1.3.4}/.pre-commit-config.yaml +3 -3
  7. {audformat-1.3.2 → audformat-1.3.4}/CHANGELOG.rst +16 -0
  8. {audformat-1.3.2 → audformat-1.3.4}/CONTRIBUTING.rst +14 -30
  9. {audformat-1.3.2 → audformat-1.3.4}/PKG-INFO +4 -32
  10. {audformat-1.3.2 → audformat-1.3.4}/audformat/core/attachment.py +1 -1
  11. {audformat-1.3.2 → audformat-1.3.4}/audformat/core/column.py +3 -8
  12. {audformat-1.3.2 → audformat-1.3.4}/audformat/core/common.py +15 -0
  13. {audformat-1.3.2 → audformat-1.3.4}/audformat/core/database.py +21 -8
  14. {audformat-1.3.2 → audformat-1.3.4}/audformat/core/errors.py +6 -10
  15. {audformat-1.3.2 → audformat-1.3.4}/audformat/core/index.py +8 -6
  16. {audformat-1.3.2 → audformat-1.3.4}/audformat/core/scheme.py +9 -17
  17. {audformat-1.3.2 → audformat-1.3.4}/audformat/core/table.py +15 -24
  18. {audformat-1.3.2 → audformat-1.3.4}/audformat/core/testing.py +3 -4
  19. {audformat-1.3.2 → audformat-1.3.4}/audformat/core/typing.py +0 -2
  20. {audformat-1.3.2 → audformat-1.3.4}/audformat/core/utils.py +67 -29
  21. {audformat-1.3.2 → audformat-1.3.4}/audformat.egg-info/PKG-INFO +4 -32
  22. {audformat-1.3.2 → audformat-1.3.4}/audformat.egg-info/SOURCES.txt +0 -3
  23. {audformat-1.3.2 → audformat-1.3.4}/benchmarks/benchmark_union.py +1 -1
  24. {audformat-1.3.2 → audformat-1.3.4}/docs/data-format.rst +4 -3
  25. {audformat-1.3.2 → audformat-1.3.4}/docs/data-misc-tables.rst +4 -2
  26. {audformat-1.3.2 → audformat-1.3.4}/docs/data-tables.rst +1 -1
  27. audformat-1.3.4/docs/install.rst +14 -0
  28. {audformat-1.3.2 → audformat-1.3.4}/pyproject.toml +26 -4
  29. {audformat-1.3.2 → audformat-1.3.4}/tests/test_attachment.py +1 -2
  30. {audformat-1.3.2 → audformat-1.3.4}/tests/test_column.py +3 -3
  31. {audformat-1.3.2 → audformat-1.3.4}/tests/test_database.py +1 -2
  32. {audformat-1.3.2 → audformat-1.3.4}/tests/test_database_get.py +57 -4
  33. {audformat-1.3.2 → audformat-1.3.4}/tests/test_index.py +58 -4
  34. {audformat-1.3.2 → audformat-1.3.4}/tests/test_misc_table.py +104 -65
  35. {audformat-1.3.2 → audformat-1.3.4}/tests/test_scheme.py +95 -9
  36. {audformat-1.3.2 → audformat-1.3.4}/tests/test_table.py +49 -4
  37. {audformat-1.3.2 → audformat-1.3.4}/tests/test_utils.py +576 -28
  38. {audformat-1.3.2 → audformat-1.3.4}/tests/test_utils_concat.py +6 -4
  39. audformat-1.3.2/docs/install.rst +0 -11
  40. audformat-1.3.2/docs/requirements.txt +0 -9
  41. audformat-1.3.2/requirements.txt +0 -1
  42. audformat-1.3.2/tests/requirements.txt +0 -7
  43. {audformat-1.3.2 → audformat-1.3.4}/LICENSE +0 -0
  44. {audformat-1.3.2 → audformat-1.3.4}/README.rst +0 -0
  45. {audformat-1.3.2 → audformat-1.3.4}/audformat/__init__.py +0 -0
  46. {audformat-1.3.2 → audformat-1.3.4}/audformat/core/__init__.py +0 -0
  47. {audformat-1.3.2 → audformat-1.3.4}/audformat/core/conftest.py +0 -0
  48. {audformat-1.3.2 → audformat-1.3.4}/audformat/core/define.py +0 -0
  49. {audformat-1.3.2 → audformat-1.3.4}/audformat/core/media.py +0 -0
  50. {audformat-1.3.2 → audformat-1.3.4}/audformat/core/rater.py +0 -0
  51. {audformat-1.3.2 → audformat-1.3.4}/audformat/core/split.py +0 -0
  52. {audformat-1.3.2 → audformat-1.3.4}/audformat/define/__init__.py +0 -0
  53. {audformat-1.3.2 → audformat-1.3.4}/audformat/errors/__init__.py +0 -0
  54. {audformat-1.3.2 → audformat-1.3.4}/audformat/testing/__init__.py +0 -0
  55. {audformat-1.3.2 → audformat-1.3.4}/audformat/utils/__init__.py +0 -0
  56. {audformat-1.3.2 → audformat-1.3.4}/audformat.egg-info/dependency_links.txt +0 -0
  57. {audformat-1.3.2 → audformat-1.3.4}/audformat.egg-info/requires.txt +0 -0
  58. {audformat-1.3.2 → audformat-1.3.4}/audformat.egg-info/top_level.txt +0 -0
  59. {audformat-1.3.2 → audformat-1.3.4}/docs/accessing-data.rst +0 -0
  60. {audformat-1.3.2 → audformat-1.3.4}/docs/api/audformat.define.rst +0 -0
  61. {audformat-1.3.2 → audformat-1.3.4}/docs/api/audformat.errors.rst +0 -0
  62. {audformat-1.3.2 → audformat-1.3.4}/docs/api/audformat.rst +0 -0
  63. {audformat-1.3.2 → audformat-1.3.4}/docs/api/audformat.testing.rst +0 -0
  64. {audformat-1.3.2 → audformat-1.3.4}/docs/api/audformat.utils.rst +0 -0
  65. {audformat-1.3.2 → audformat-1.3.4}/docs/api-src/audformat.define.rst +0 -0
  66. {audformat-1.3.2 → audformat-1.3.4}/docs/api-src/audformat.errors.rst +0 -0
  67. {audformat-1.3.2 → audformat-1.3.4}/docs/api-src/audformat.rst +0 -0
  68. {audformat-1.3.2 → audformat-1.3.4}/docs/api-src/audformat.testing.rst +0 -0
  69. {audformat-1.3.2 → audformat-1.3.4}/docs/api-src/audformat.utils.rst +0 -0
  70. {audformat-1.3.2 → audformat-1.3.4}/docs/changelog.rst +0 -0
  71. {audformat-1.3.2 → audformat-1.3.4}/docs/combine-tables.rst +0 -0
  72. {audformat-1.3.2 → audformat-1.3.4}/docs/conf.py +0 -0
  73. {audformat-1.3.2 → audformat-1.3.4}/docs/conftest.py +0 -0
  74. {audformat-1.3.2 → audformat-1.3.4}/docs/contributing.rst +0 -0
  75. {audformat-1.3.2 → audformat-1.3.4}/docs/create-database.rst +0 -0
  76. {audformat-1.3.2 → audformat-1.3.4}/docs/data-conventions.rst +0 -0
  77. {audformat-1.3.2 → audformat-1.3.4}/docs/data-example.rst +0 -0
  78. {audformat-1.3.2 → audformat-1.3.4}/docs/data-header.rst +0 -0
  79. {audformat-1.3.2 → audformat-1.3.4}/docs/data-introduction.rst +0 -0
  80. {audformat-1.3.2 → audformat-1.3.4}/docs/emodb-example.rst +0 -0
  81. {audformat-1.3.2 → audformat-1.3.4}/docs/genindex.rst +0 -0
  82. {audformat-1.3.2 → audformat-1.3.4}/docs/index.rst +0 -0
  83. {audformat-1.3.2 → audformat-1.3.4}/docs/map-scheme.rst +0 -0
  84. {audformat-1.3.2 → audformat-1.3.4}/docs/pics/audformat-database.dot +0 -0
  85. {audformat-1.3.2 → audformat-1.3.4}/docs/pics/audformat-misc-table.dot +0 -0
  86. {audformat-1.3.2 → audformat-1.3.4}/docs/pics/audformat-table.dot +0 -0
  87. {audformat-1.3.2 → audformat-1.3.4}/docs/update-database.rst +0 -0
  88. {audformat-1.3.2 → audformat-1.3.4}/setup.cfg +0 -0
  89. {audformat-1.3.2 → audformat-1.3.4}/tests/conftest.py +0 -0
  90. {audformat-1.3.2 → audformat-1.3.4}/tests/test_common.py +0 -0
  91. {audformat-1.3.2 → audformat-1.3.4}/tests/test_eq.py +0 -0
  92. {audformat-1.3.2 → audformat-1.3.4}/tests/test_errors.py +0 -0
@@ -13,10 +13,16 @@ jobs:
13
13
  strategy:
14
14
  matrix:
15
15
  os: [ ubuntu-latest ]
16
- python-version: [ '3.10' ]
16
+ python-version: [ '3.12' ]
17
17
 
18
18
  steps:
19
19
  - uses: actions/checkout@v4
20
+ with:
21
+ # Ensure audformat is assigned a version,
22
+ # so we can install audb as a dependency
23
+ # https://github.com/astral-sh/uv/issues/8148#issuecomment-2408639333
24
+ fetch-depth: 0
25
+ fetch-tags: true
20
26
 
21
27
  - name: Cache emodb
22
28
  uses: actions/cache@v4
@@ -29,21 +35,16 @@ jobs:
29
35
  with:
30
36
  python-version: ${{ matrix.python-version }}
31
37
 
38
+ - name: Install uv
39
+ uses: astral-sh/setup-uv@3259c6206f993105e3a61b142c2d97bf4b9ef83d
40
+
32
41
  - name: Ubuntu - install graphviz
33
42
  run: |
34
43
  sudo apt-get update
35
44
  sudo apt-get install --yes graphviz
36
45
 
37
- - name: Install package
38
- run: |
39
- python -m pip install --upgrade pip
40
- pip install -r requirements.txt
41
-
42
- - name: Install docs requirements
43
- run: pip install -r docs/requirements.txt
44
-
45
46
  - name: Test building documentation
46
- run: python -m sphinx docs/ docs/_build/ -b html -W
47
+ run: uv run python -m sphinx docs/ docs/_build/ -b html -W
47
48
 
48
49
  - name: Check links in documentation
49
- run: python -m sphinx docs/ docs/_build/ -b linkcheck -W
50
+ run: uv run python -m sphinx docs/ docs/_build/ -b linkcheck -W
@@ -17,13 +17,13 @@ jobs:
17
17
  - name: Set up Python
18
18
  uses: actions/setup-python@v5
19
19
  with:
20
- python-version: '3.10'
20
+ python-version: '3.12'
21
+
22
+ - name: Install uv
23
+ uses: astral-sh/setup-uv@3259c6206f993105e3a61b142c2d97bf4b9ef83d
21
24
 
22
25
  - name: Install pre-commit hooks
23
- run: |
24
- pip install pre-commit
25
- pre-commit install --install-hooks
26
+ run: uvx pre-commit install --install-hooks
26
27
 
27
28
  - name: Code style check via pre-commit
28
- run: |
29
- pre-commit run --all-files
29
+ run: uvx pre-commit run --all-files
@@ -29,16 +29,15 @@ jobs:
29
29
  - name: Set up Python
30
30
  uses: actions/setup-python@v5
31
31
  with:
32
- python-version: '3.10'
32
+ python-version: '3.12'
33
+
34
+ - name: Install uv
35
+ uses: astral-sh/setup-uv@3259c6206f993105e3a61b142c2d97bf4b9ef83d
33
36
 
34
- - name: Install dependencies
35
- run: |
36
- python -m pip install --upgrade pip
37
- pip install build virtualenv
38
37
 
39
38
  # PyPI package
40
39
  - name: Build Python package
41
- run: python -m build
40
+ run: uv build
42
41
 
43
42
  - name: Publish Python package to PyPI
44
43
  uses: pypa/gh-action-pypi-publish@release/v1
@@ -49,14 +48,9 @@ jobs:
49
48
  sudo apt-get update
50
49
  sudo apt-get install --no-install-recommends --yes graphviz libsndfile1 sox
51
50
 
52
- - name: Install doc dependencies
53
- run: |
54
- pip install -r requirements.txt
55
- pip install -r docs/requirements.txt
56
51
 
57
52
  - name: Build documentation
58
- run: |
59
- python -m sphinx docs/ docs/_build/ -b html
53
+ run: uv run python -m sphinx docs/ docs/_build/ -b html
60
54
 
61
55
  - name: Deploy documentation to Github pages
62
56
  uses: peaceiris/actions-gh-pages@v4
@@ -13,25 +13,28 @@ jobs:
13
13
  strategy:
14
14
  matrix:
15
15
  os: [ ubuntu-latest, windows-latest, macOS-latest ]
16
- python-version: [ '3.10' ]
16
+ python-version: [ '3.12' ]
17
17
  include:
18
18
  - os: ubuntu-latest
19
- python-version: '3.9'
19
+ python-version: '3.10'
20
20
  - os: ubuntu-latest
21
21
  python-version: '3.11'
22
- - os: ubuntu-latest
23
- python-version: '3.12'
24
22
  - os: ubuntu-latest
25
23
  python-version: '3.13'
26
24
  - os: ubuntu-latest
27
- python-version: '3.9'
25
+ python-version: '3.14'
26
+ - os: ubuntu-latest
27
+ python-version: '3.10'
28
28
  requirements: 'minimum'
29
29
 
30
30
  steps:
31
31
  - uses: actions/checkout@v4
32
32
  with:
33
+ # Ensure audformat is assigned a version,
34
+ # so we can install audb as a dependency
35
+ # https://github.com/astral-sh/uv/issues/8148#issuecomment-2408639333
36
+ fetch-depth: 0
33
37
  fetch-tags: true
34
- fetch-depth: 50
35
38
 
36
39
  - name: Cache emodb
37
40
  uses: actions/cache@v4
@@ -45,18 +48,20 @@ jobs:
45
48
  with:
46
49
  python-version: ${{ matrix.python-version }}
47
50
 
51
+ - name: Install uv
52
+ uses: astral-sh/setup-uv@3259c6206f993105e3a61b142c2d97bf4b9ef83d
53
+
48
54
  - name: Prepare Ubuntu
49
55
  run: |
50
56
  sudo apt-get update
51
57
  sudo apt-get install --no-install-recommends --yes libsndfile1
52
58
  if: matrix.os == 'ubuntu-latest'
53
59
 
54
- - name: Install dependencies
55
- run: |
56
- python -V
57
- python -m pip install --upgrade pip
58
- pip install -r requirements.txt
59
- pip install -r tests/requirements.txt
60
+ - name: Sync Python environment
61
+ run: uv sync
62
+
63
+ - name: List installed Python packages
64
+ run: uv pip list
60
65
 
61
66
  - name: Downgrade to minimum dependencies
62
67
  run: |
@@ -65,15 +70,14 @@ jobs:
65
70
  pip install "numpy<2.0.0"
66
71
  pip install "pandas==2.1.0"
67
72
  pip install "pyarrow==10.0.1"
68
- pip install "pyyaml==5.4.1"
73
+ pip install "pyyaml==6.0.1"
69
74
  # need to use an audb version in the test,
70
75
  # that supports audeer==2.0.0
71
76
  pip install "audb==1.7.4"
72
77
  if: matrix.requirements == 'minimum'
73
78
 
74
79
  - name: Test with pytest
75
- run: |
76
- python -m pytest
80
+ run: uv run pytest
77
81
 
78
82
  - name: Upload coverage to Codecov
79
83
  uses: codecov/codecov-action@v4
@@ -11,3 +11,4 @@ emodb-src/
11
11
  emodb.zip
12
12
  coverage.xml
13
13
  docs/api/
14
+ uv.lock
@@ -9,17 +9,17 @@
9
9
  #
10
10
  #
11
11
  default_language_version:
12
- python: python3.10
12
+ python: python3.12
13
13
 
14
14
  repos:
15
15
  - repo: https://github.com/astral-sh/ruff-pre-commit
16
- rev: v0.7.0
16
+ rev: v0.13.3
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.3.0
22
+ rev: v2.4.1
23
23
  hooks:
24
24
  - id: codespell
25
25
  additional_dependencies:
@@ -7,6 +7,22 @@ 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.4 (2026-02-18)
11
+ --------------------------
12
+
13
+ * Added: support for ``pandas >=3.0``
14
+
15
+
16
+ Version 1.3.3 (2026-01-12)
17
+ --------------------------
18
+
19
+ * Added: support for Python 3.14
20
+ * Added: document support for (misc) tables with zero columns
21
+ in the specification
22
+ * Fixed: ensure cache compatibility between different ``pandas`` versions
23
+ * Removed: support for Python 3.9
24
+
25
+
10
26
  Version 1.3.2 (2025-05-27)
11
27
  --------------------------
12
28
 
@@ -22,11 +22,7 @@ you should get the newest development version from Github_::
22
22
 
23
23
  git clone https://github.com/audeering/audformat/
24
24
  cd audformat
25
- # Create virtual environment for this project
26
- # e.g.
27
- # virtualenv --python="python3" $HOME/.envs/audformat
28
- # source $HOME/.envs/audformat/bin/activate
29
- pip install -r requirements.txt
25
+ uv sync
30
26
 
31
27
 
32
28
  This way,
@@ -50,9 +46,8 @@ are defined in :file:`pyproject.toml`.
50
46
  The checks are executed in the CI using `pre-commit`_.
51
47
  You can enable those checks locally by executing::
52
48
 
53
- pip install pre-commit # consider system wide installation
54
- pre-commit install
55
- pre-commit run --all-files
49
+ uvx pre-commit install
50
+ uvx pre-commit run --all-files
56
51
 
57
52
  Afterwards ruff_ and codespell_ are executed
58
53
  every time you create a commit.
@@ -60,15 +55,14 @@ every time you create a commit.
60
55
  You can also install ruff_ and codespell_
61
56
  and call it directly::
62
57
 
63
- pip install ruff codespell # consider system wide installation
64
- ruff check --fix . # lint all Python files, and fix any fixable errors
65
- ruff format . # format code of all Python files
66
- codespell
58
+ uvx ruff check --fix . # lint all Python files, and fix any fixable errors
59
+ uvx ruff format . # format code of all Python files
60
+ uvx codespell
67
61
 
68
62
  It can be restricted to specific folders::
69
63
 
70
- ruff check audfoo/ tests/
71
- codespell audfoo/ tests/
64
+ uvx ruff check audformat/ tests/
65
+ uvx codespell audformat/ tests/
72
66
 
73
67
 
74
68
  .. _codespell: https://github.com/codespell-project/codespell/
@@ -81,21 +75,16 @@ Building the Documentation
81
75
  --------------------------
82
76
 
83
77
  If you make changes to the documentation,
84
- you can re-create the HTML pages using Sphinx_.
85
- You can install it and a few other necessary packages with::
78
+ you can re-create the HTML pages using Sphinx_::
86
79
 
87
- pip install -r docs/requirements.txt
88
-
89
- To create the HTML pages, use::
90
-
91
- python -m sphinx docs/ build/sphinx/html -b html
80
+ uv run python -m sphinx docs/ build/html -b html
92
81
 
93
82
  The generated files will be available
94
- in the directory :file:`build/sphinx/html/`.
83
+ in the directory :file:`build/html/`.
95
84
 
96
85
  It is also possible to automatically check if all links are still valid::
97
86
 
98
- python -m sphinx docs/ build/sphinx/html -b linkcheck
87
+ uv run python -m sphinx docs/ build/html -b linkcheck
99
88
 
100
89
  .. _Sphinx: https://www.sphinx-doc.org
101
90
 
@@ -103,14 +92,9 @@ It is also possible to automatically check if all links are still valid::
103
92
  Running the Tests
104
93
  -----------------
105
94
 
106
- You'll need pytest_ for that.
107
- It can be installed with::
108
-
109
- pip install -r tests/requirements.txt
110
-
111
- To execute the tests, simply run::
95
+ You can run tests with pytest_::
112
96
 
113
- python -m pytest
97
+ uv run pytest
114
98
 
115
99
  .. _pytest: https://pytest.org
116
100
 
@@ -1,54 +1,26 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: audformat
3
- Version: 1.3.2
3
+ Version: 1.3.4
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>
7
- License: MIT License
8
-
9
- Copyright (c) 2018-present audEERING GmbH and Contributors
10
-
11
- Authors:
12
- Hagen Wierstorf
13
- Johannes Wagner
14
- Christian Geng
15
- Baha Eddine Abrougui
16
-
17
- Permission is hereby granted, free of charge, to any person obtaining a copy
18
- of this software and associated documentation files (the "Software"), to deal
19
- in the Software without restriction, including without limitation the rights
20
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
- copies of the Software, and to permit persons to whom the Software is
22
- furnished to do so, subject to the following conditions:
23
-
24
- The above copyright notice and this permission notice shall be included in all
25
- copies or substantial portions of the Software.
26
-
27
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
- SOFTWARE.
34
-
7
+ License-Expression: MIT
35
8
  Project-URL: repository, https://github.com/audeering/audformat/
36
9
  Project-URL: documentation, https://audeering.github.io/audformat/
37
10
  Keywords: audio,database,annotation
38
11
  Classifier: Development Status :: 5 - Production/Stable
39
12
  Classifier: Intended Audience :: Science/Research
40
13
  Classifier: Intended Audience :: Developers
41
- Classifier: License :: OSI Approved :: MIT License
42
14
  Classifier: Operating System :: OS Independent
43
15
  Classifier: Programming Language :: Python
44
16
  Classifier: Programming Language :: Python :: 3
45
- Classifier: Programming Language :: Python :: 3.9
46
17
  Classifier: Programming Language :: Python :: 3.10
47
18
  Classifier: Programming Language :: Python :: 3.11
48
19
  Classifier: Programming Language :: Python :: 3.12
49
20
  Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
50
22
  Classifier: Topic :: Scientific/Engineering
51
- Requires-Python: >=3.9
23
+ Requires-Python: >=3.10
52
24
  Description-Content-Type: text/x-rst
53
25
  License-File: LICENSE
54
26
  Requires-Dist: audeer>=2.0.0
@@ -135,7 +135,7 @@ class Attachment(HeaderBase):
135
135
  or other.path.startswith(self.path)
136
136
  ):
137
137
  raise RuntimeError(
138
- f"Attachments '{self.path}' and '{other.path}' " "are nested."
138
+ f"Attachments '{self.path}' and '{other.path}' are nested."
139
139
  )
140
140
 
141
141
  def _check_path(
@@ -249,7 +249,7 @@ class Column(HeaderBase):
249
249
 
250
250
  if not any(labels.values()):
251
251
  raise ValueError(
252
- f"Scheme '{self.scheme_id}' provides no mapping " "for its labels."
252
+ f"Scheme '{self.scheme_id}' provides no mapping for its labels."
253
253
  )
254
254
 
255
255
  # Check that at least one key is available for map
@@ -261,12 +261,7 @@ class Column(HeaderBase):
261
261
  keys = sorted(list(set(keys)))
262
262
  if len(keys) > 0 and map not in keys:
263
263
  raise ValueError(
264
- f"Cannot map "
265
- f"'{self._id}' "
266
- f"to "
267
- f"'{map}'. "
268
- f"Expected one of "
269
- f"{list(keys)}."
264
+ f"Cannot map '{self._id}' to '{map}'. Expected one of {list(keys)}."
270
265
  )
271
266
 
272
267
  mapping = {}
@@ -355,7 +350,7 @@ class Column(HeaderBase):
355
350
  return self.set(values, index=index)
356
351
  else:
357
352
  raise ValueError(
358
- "Cannot set values of a filewise column " "using a segmented index."
353
+ "Cannot set values of a filewise column using a segmented index."
359
354
  )
360
355
  else:
361
356
  if is_scalar(values):
@@ -362,6 +362,21 @@ def to_audformat_dtype(dtype: str | type) -> str:
362
362
  return define.DataType.OBJECT
363
363
 
364
364
 
365
+ def to_categorical_dtype(labels: list[object]) -> pd.api.types.CategoricalDtype:
366
+ """Create categorical dtype for labels."""
367
+ if len(labels) > 0:
368
+ if all(isinstance(label, int) for label in labels):
369
+ # allow nullable
370
+ labels = pd.array(labels, dtype="int64")
371
+ elif all(isinstance(label, str) for label in labels):
372
+ # object for string categories
373
+ labels = pd.Index(labels, dtype="object")
374
+ return pd.api.types.CategoricalDtype(
375
+ categories=labels,
376
+ ordered=False,
377
+ )
378
+
379
+
365
380
  def to_pandas_dtype(dtype: str) -> str | None:
366
381
  r"""Convert audformat to pandas dtype.
367
382
 
@@ -7,6 +7,7 @@ import itertools
7
7
  import os
8
8
  import shutil
9
9
 
10
+ import numpy as np
10
11
  import oyaml as yaml
11
12
 
12
13
 
@@ -586,7 +587,9 @@ class Database(HeaderBase):
586
587
 
587
588
  Limit to a particular table or split.
588
589
 
589
- >>> db.get("emotion", tables=["emotion.categories.train.gold_standard"]).head()
590
+ >>> db.get(
591
+ ... "emotion", tables=["emotion.categories.train.gold_standard"]
592
+ ... ).head()
590
593
  emotion
591
594
  file
592
595
  wav/03a01Fa.wav happiness
@@ -694,12 +697,16 @@ class Database(HeaderBase):
694
697
  ys.append(y)
695
698
 
696
699
  def dtypes_of_categories(objs):
697
- dtypes = [
698
- obj.dtype.categories.dtype
699
- for obj in objs
700
- if isinstance(obj.dtype, pd.CategoricalDtype)
701
- ]
702
- return sorted(list(set(dtypes)))
700
+ cat_dtypes = []
701
+ for obj in objs:
702
+ if isinstance(obj.dtype, pd.CategoricalDtype):
703
+ # Normalize string-like categorical dtypes to object
704
+ cat_dtype = obj.dtype.categories.dtype
705
+ if isinstance(cat_dtype, pd.StringDtype):
706
+ cat_dtype = np.dtype("O")
707
+ cat_dtypes.append(cat_dtype)
708
+ # Deduplicate and sort for consistent ordering
709
+ return sorted(list(set(cat_dtypes)), key=str)
703
710
 
704
711
  def empty_frame(name):
705
712
  return pd.DataFrame(
@@ -821,7 +828,7 @@ class Database(HeaderBase):
821
828
  raise TypeError( # pragma: nocover
822
829
  f"Cannot join labels for scheme '{requested_scheme}' "
823
830
  "with different data types: "
824
- f"{', '.join(dtypes)}"
831
+ f"{', '.join(str(d) for d in dtypes)}"
825
832
  )
826
833
  dtype = dtypes[0]
827
834
  # Convert everything to categorical data
@@ -830,6 +837,12 @@ class Database(HeaderBase):
830
837
  ys[n] = y.astype(
831
838
  pd.CategoricalDtype(y.array.dropna().unique().astype(dtype))
832
839
  )
840
+ # Normalize string-like categorical dtypes to object
841
+ for n, y in enumerate(ys):
842
+ cat_dtype = y.dtype.categories.dtype
843
+ if isinstance(cat_dtype, pd.StringDtype):
844
+ new_categories = y.dtype.categories.astype("object")
845
+ ys[n] = y.astype(pd.CategoricalDtype(new_categories))
833
846
  # Find union of categorical data
834
847
  data = [y.array for y in ys]
835
848
  try:
@@ -13,10 +13,10 @@ class BadIdError(ValueError):
13
13
 
14
14
  def __init__(self, name: str, invalid_id: str, dictionary: dict):
15
15
  if not dictionary:
16
- message = f"Bad {name} ID '{invalid_id}', " f"no {name} objects defined yet"
16
+ message = f"Bad {name} ID '{invalid_id}', no {name} objects defined yet"
17
17
  else:
18
18
  message = (
19
- f"Bad {name} ID '{invalid_id}', " f"expected one of {list(dictionary)}"
19
+ f"Bad {name} ID '{invalid_id}', expected one of {list(dictionary)}"
20
20
  )
21
21
  super().__init__(message)
22
22
 
@@ -31,7 +31,7 @@ class BadKeyError(KeyError):
31
31
  """
32
32
 
33
33
  def __init__(self, invalid_key: str, valid_keys: Sequence[str]):
34
- message = f"Bad key '{invalid_key}', " f"expected one of {list(valid_keys)}"
34
+ message = f"Bad key '{invalid_key}', expected one of {list(valid_keys)}"
35
35
  super().__init__(message)
36
36
 
37
37
 
@@ -45,7 +45,7 @@ class BadTypeError(TypeError):
45
45
  """
46
46
 
47
47
  def __init__(self, invalid_value: object, expected_type: type):
48
- message = f"Bad type '{type(invalid_value)}', " f"expected '{expected_type}'"
48
+ message = f"Bad type '{type(invalid_value)}', expected '{expected_type}'"
49
49
  super().__init__(message)
50
50
 
51
51
 
@@ -59,9 +59,7 @@ class BadValueError(ValueError):
59
59
  """
60
60
 
61
61
  def __init__(self, invalid_value: str, valid_values: Sequence[str]):
62
- message = (
63
- f"Bad value '{invalid_value}', " f"expected one of {list(valid_values)}"
64
- )
62
+ message = f"Bad value '{invalid_value}', expected one of {list(valid_values)}"
65
63
  super().__init__(message)
66
64
 
67
65
 
@@ -75,6 +73,4 @@ class TableExistsError(KeyError):
75
73
  """
76
74
 
77
75
  def __init__(self, table_type: str, table_id: str):
78
- KeyError(
79
- f"There is already a " f"{table_type} " f"table with ID " f"'{table_id}'."
80
- )
76
+ KeyError(f"There is already a {table_type} table with ID '{table_id}'.")
@@ -1,5 +1,3 @@
1
- from __future__ import annotations
2
-
3
1
  import numpy as np
4
2
  import pandas as pd
5
3
 
@@ -29,9 +27,13 @@ def to_array(value: object) -> list | np.ndarray:
29
27
  def to_timedelta(times):
30
28
  r"""Convert time value to pd.Timedelta."""
31
29
  try:
32
- return pd.to_timedelta(times, unit="s")
30
+ result = pd.to_timedelta(times, unit="s")
33
31
  except ValueError: # catches values like '1s'
34
- return pd.to_timedelta(times)
32
+ result = pd.to_timedelta(times)
33
+ if isinstance(result, pd.Timedelta):
34
+ return result.as_unit("ns")
35
+ else:
36
+ return result.astype("timedelta64[ns]")
35
37
 
36
38
 
37
39
  def assert_index(
@@ -102,12 +104,12 @@ def assert_index(
102
104
  "Index not conform to audformat. "
103
105
  "Level 'file' must contain values of type 'string'."
104
106
  )
105
- if not pd.api.types.is_timedelta64_dtype(obj.levels[1].dtype):
107
+ if not pd.api.types.is_timedelta64_ns_dtype(obj.levels[1].dtype):
106
108
  raise ValueError(
107
109
  "Index not conform to audformat. "
108
110
  "Level 'start' must contain values of type 'timedelta64[ns]'."
109
111
  )
110
- if not pd.api.types.is_timedelta64_dtype(obj.levels[2].dtype):
112
+ if not pd.api.types.is_timedelta64_ns_dtype(obj.levels[2].dtype):
111
113
  raise ValueError(
112
114
  "Index not conform to audformat. "
113
115
  "Level 'end' must contain values of type 'timedelta64[ns]'."
@@ -1,5 +1,3 @@
1
- from __future__ import annotations
2
-
3
1
  import datetime
4
2
  import random
5
3
  import string
@@ -78,7 +76,9 @@ class Scheme(common.HeaderBase):
78
76
  >>> # Use index of misc table as labels
79
77
  >>> import audformat
80
78
  >>> db = audformat.Database("mydb")
81
- >>> db["speaker"] = audformat.MiscTable(pd.Index(["spk1", "spk2"], name="speaker"))
79
+ >>> db["speaker"] = audformat.MiscTable(
80
+ ... pd.Index(["spk1", "spk2"], name="speaker")
81
+ ... )
82
82
  >>> Scheme("str", labels="speaker")
83
83
  {dtype: str, labels: speaker}
84
84
 
@@ -134,12 +134,11 @@ class Scheme(common.HeaderBase):
134
134
  # Labels from misc table
135
135
  if dtype is None:
136
136
  raise ValueError(
137
- "'dtype' has to be provided "
138
- "when using a misc table as labels."
137
+ "'dtype' has to be provided when using a misc table as labels."
139
138
  )
140
139
  if dtype == define.DataType.BOOL:
141
140
  raise ValueError(
142
- "'dtype' cannot be 'bool' " "when using a misc table as labels."
141
+ "'dtype' cannot be 'bool' when using a misc table as labels."
143
142
  )
144
143
  else:
145
144
  # Labels from list or dictionary
@@ -288,16 +287,9 @@ class Scheme(common.HeaderBase):
288
287
  """
289
288
  if self.labels is not None:
290
289
  labels = self._labels_to_list()
291
- if len(labels) > 0 and isinstance(labels[0], int):
292
- # allow nullable
293
- labels = pd.array(labels, dtype="int64")
294
- dtype = pd.api.types.CategoricalDtype(
295
- categories=labels,
296
- ordered=False,
297
- )
290
+ return common.to_categorical_dtype(labels)
298
291
  else:
299
- dtype = common.to_pandas_dtype(self.dtype)
300
- return dtype
292
+ return common.to_pandas_dtype(self.dtype)
301
293
 
302
294
  def replace_labels(
303
295
  self,
@@ -354,7 +346,7 @@ class Scheme(common.HeaderBase):
354
346
  """
355
347
  if self.labels is None:
356
348
  raise ValueError(
357
- "Cannot replace labels when " "scheme does not define labels."
349
+ "Cannot replace labels when scheme does not define labels."
358
350
  )
359
351
  self._check_labels(labels)
360
352
 
@@ -393,7 +385,7 @@ class Scheme(common.HeaderBase):
393
385
  r"""Raise label related errors."""
394
386
  if not isinstance(labels, (dict, list, str)):
395
387
  raise ValueError(
396
- "Labels must be passed " "as a dictionary, list or ID of a misc table."
388
+ "Labels must be passed as a dictionary, list or ID of a misc table."
397
389
  )
398
390
 
399
391
  if self._db is not None and isinstance(labels, str):