audformat 1.1.2__tar.gz → 1.1.3__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.1.2 → audformat-1.1.3}/.github/workflows/doc.yml +3 -3
  2. {audformat-1.1.2 → audformat-1.1.3}/.github/workflows/linter.yml +2 -2
  3. {audformat-1.1.2 → audformat-1.1.3}/.github/workflows/publish.yml +4 -4
  4. {audformat-1.1.2 → audformat-1.1.3}/.github/workflows/test.yml +4 -4
  5. {audformat-1.1.2 → audformat-1.1.3}/CHANGELOG.rst +11 -0
  6. {audformat-1.1.2 → audformat-1.1.3}/PKG-INFO +1 -1
  7. {audformat-1.1.2 → audformat-1.1.3}/audformat/core/utils.py +37 -12
  8. {audformat-1.1.2 → audformat-1.1.3}/audformat.egg-info/PKG-INFO +1 -1
  9. {audformat-1.1.2 → audformat-1.1.3}/tests/test_utils.py +72 -0
  10. {audformat-1.1.2 → audformat-1.1.3}/.gitignore +0 -0
  11. {audformat-1.1.2 → audformat-1.1.3}/.pre-commit-config.yaml +0 -0
  12. {audformat-1.1.2 → audformat-1.1.3}/CONTRIBUTING.rst +0 -0
  13. {audformat-1.1.2 → audformat-1.1.3}/LICENSE +0 -0
  14. {audformat-1.1.2 → audformat-1.1.3}/README.rst +0 -0
  15. {audformat-1.1.2 → audformat-1.1.3}/audformat/__init__.py +0 -0
  16. {audformat-1.1.2 → audformat-1.1.3}/audformat/core/__init__.py +0 -0
  17. {audformat-1.1.2 → audformat-1.1.3}/audformat/core/attachment.py +0 -0
  18. {audformat-1.1.2 → audformat-1.1.3}/audformat/core/column.py +0 -0
  19. {audformat-1.1.2 → audformat-1.1.3}/audformat/core/common.py +0 -0
  20. {audformat-1.1.2 → audformat-1.1.3}/audformat/core/conftest.py +0 -0
  21. {audformat-1.1.2 → audformat-1.1.3}/audformat/core/database.py +0 -0
  22. {audformat-1.1.2 → audformat-1.1.3}/audformat/core/define.py +0 -0
  23. {audformat-1.1.2 → audformat-1.1.3}/audformat/core/errors.py +0 -0
  24. {audformat-1.1.2 → audformat-1.1.3}/audformat/core/index.py +0 -0
  25. {audformat-1.1.2 → audformat-1.1.3}/audformat/core/media.py +0 -0
  26. {audformat-1.1.2 → audformat-1.1.3}/audformat/core/rater.py +0 -0
  27. {audformat-1.1.2 → audformat-1.1.3}/audformat/core/scheme.py +0 -0
  28. {audformat-1.1.2 → audformat-1.1.3}/audformat/core/split.py +0 -0
  29. {audformat-1.1.2 → audformat-1.1.3}/audformat/core/table.py +0 -0
  30. {audformat-1.1.2 → audformat-1.1.3}/audformat/core/testing.py +0 -0
  31. {audformat-1.1.2 → audformat-1.1.3}/audformat/core/typing.py +0 -0
  32. {audformat-1.1.2 → audformat-1.1.3}/audformat/define/__init__.py +0 -0
  33. {audformat-1.1.2 → audformat-1.1.3}/audformat/errors/__init__.py +0 -0
  34. {audformat-1.1.2 → audformat-1.1.3}/audformat/testing/__init__.py +0 -0
  35. {audformat-1.1.2 → audformat-1.1.3}/audformat/utils/__init__.py +0 -0
  36. {audformat-1.1.2 → audformat-1.1.3}/audformat.egg-info/SOURCES.txt +0 -0
  37. {audformat-1.1.2 → audformat-1.1.3}/audformat.egg-info/dependency_links.txt +0 -0
  38. {audformat-1.1.2 → audformat-1.1.3}/audformat.egg-info/requires.txt +0 -0
  39. {audformat-1.1.2 → audformat-1.1.3}/audformat.egg-info/top_level.txt +0 -0
  40. {audformat-1.1.2 → audformat-1.1.3}/benchmarks/benchmark_union.py +0 -0
  41. {audformat-1.1.2 → audformat-1.1.3}/docs/accessing-data.rst +0 -0
  42. {audformat-1.1.2 → audformat-1.1.3}/docs/api/audformat.define.rst +0 -0
  43. {audformat-1.1.2 → audformat-1.1.3}/docs/api/audformat.errors.rst +0 -0
  44. {audformat-1.1.2 → audformat-1.1.3}/docs/api/audformat.rst +0 -0
  45. {audformat-1.1.2 → audformat-1.1.3}/docs/api/audformat.testing.rst +0 -0
  46. {audformat-1.1.2 → audformat-1.1.3}/docs/api/audformat.utils.rst +0 -0
  47. {audformat-1.1.2 → audformat-1.1.3}/docs/api-src/audformat.define.rst +0 -0
  48. {audformat-1.1.2 → audformat-1.1.3}/docs/api-src/audformat.errors.rst +0 -0
  49. {audformat-1.1.2 → audformat-1.1.3}/docs/api-src/audformat.rst +0 -0
  50. {audformat-1.1.2 → audformat-1.1.3}/docs/api-src/audformat.testing.rst +0 -0
  51. {audformat-1.1.2 → audformat-1.1.3}/docs/api-src/audformat.utils.rst +0 -0
  52. {audformat-1.1.2 → audformat-1.1.3}/docs/changelog.rst +0 -0
  53. {audformat-1.1.2 → audformat-1.1.3}/docs/combine-tables.rst +0 -0
  54. {audformat-1.1.2 → audformat-1.1.3}/docs/conf.py +0 -0
  55. {audformat-1.1.2 → audformat-1.1.3}/docs/contributing.rst +0 -0
  56. {audformat-1.1.2 → audformat-1.1.3}/docs/create-database.rst +0 -0
  57. {audformat-1.1.2 → audformat-1.1.3}/docs/data-conventions.rst +0 -0
  58. {audformat-1.1.2 → audformat-1.1.3}/docs/data-example.rst +0 -0
  59. {audformat-1.1.2 → audformat-1.1.3}/docs/data-format.rst +0 -0
  60. {audformat-1.1.2 → audformat-1.1.3}/docs/data-header.rst +0 -0
  61. {audformat-1.1.2 → audformat-1.1.3}/docs/data-introduction.rst +0 -0
  62. {audformat-1.1.2 → audformat-1.1.3}/docs/data-misc-tables.rst +0 -0
  63. {audformat-1.1.2 → audformat-1.1.3}/docs/data-tables.rst +0 -0
  64. {audformat-1.1.2 → audformat-1.1.3}/docs/emodb-example.rst +0 -0
  65. {audformat-1.1.2 → audformat-1.1.3}/docs/genindex.rst +0 -0
  66. {audformat-1.1.2 → audformat-1.1.3}/docs/index.rst +0 -0
  67. {audformat-1.1.2 → audformat-1.1.3}/docs/install.rst +0 -0
  68. {audformat-1.1.2 → audformat-1.1.3}/docs/map-scheme.rst +0 -0
  69. {audformat-1.1.2 → audformat-1.1.3}/docs/pics/audformat-database.dot +0 -0
  70. {audformat-1.1.2 → audformat-1.1.3}/docs/pics/audformat-misc-table.dot +0 -0
  71. {audformat-1.1.2 → audformat-1.1.3}/docs/pics/audformat-table.dot +0 -0
  72. {audformat-1.1.2 → audformat-1.1.3}/docs/requirements.txt +0 -0
  73. {audformat-1.1.2 → audformat-1.1.3}/docs/update-database.rst +0 -0
  74. {audformat-1.1.2 → audformat-1.1.3}/pyproject.toml +0 -0
  75. {audformat-1.1.2 → audformat-1.1.3}/requirements.txt +0 -0
  76. {audformat-1.1.2 → audformat-1.1.3}/setup.cfg +0 -0
  77. {audformat-1.1.2 → audformat-1.1.3}/tests/conftest.py +0 -0
  78. {audformat-1.1.2 → audformat-1.1.3}/tests/requirements.txt +0 -0
  79. {audformat-1.1.2 → audformat-1.1.3}/tests/test_attachment.py +0 -0
  80. {audformat-1.1.2 → audformat-1.1.3}/tests/test_column.py +0 -0
  81. {audformat-1.1.2 → audformat-1.1.3}/tests/test_common.py +0 -0
  82. {audformat-1.1.2 → audformat-1.1.3}/tests/test_database.py +0 -0
  83. {audformat-1.1.2 → audformat-1.1.3}/tests/test_database_get.py +0 -0
  84. {audformat-1.1.2 → audformat-1.1.3}/tests/test_eq.py +0 -0
  85. {audformat-1.1.2 → audformat-1.1.3}/tests/test_errors.py +0 -0
  86. {audformat-1.1.2 → audformat-1.1.3}/tests/test_index.py +0 -0
  87. {audformat-1.1.2 → audformat-1.1.3}/tests/test_misc_table.py +0 -0
  88. {audformat-1.1.2 → audformat-1.1.3}/tests/test_scheme.py +0 -0
  89. {audformat-1.1.2 → audformat-1.1.3}/tests/test_table.py +0 -0
  90. {audformat-1.1.2 → audformat-1.1.3}/tests/test_utils_concat.py +0 -0
@@ -16,16 +16,16 @@ jobs:
16
16
  python-version: [ '3.10' ]
17
17
 
18
18
  steps:
19
- - uses: actions/checkout@v3
19
+ - uses: actions/checkout@v4
20
20
 
21
21
  - name: Cache emodb
22
- uses: actions/cache@v3
22
+ uses: actions/cache@v4
23
23
  with:
24
24
  path: emodb-src
25
25
  key: emodb-ubuntu
26
26
 
27
27
  - name: Set up Python ${{ matrix.python-version }}
28
- uses: actions/setup-python@v4
28
+ uses: actions/setup-python@v5
29
29
  with:
30
30
  python-version: ${{ matrix.python-version }}
31
31
 
@@ -12,10 +12,10 @@ jobs:
12
12
  runs-on: ubuntu-latest
13
13
 
14
14
  steps:
15
- - uses: actions/checkout@v3
15
+ - uses: actions/checkout@v4
16
16
 
17
17
  - name: Set up Python
18
- uses: actions/setup-python@v4
18
+ uses: actions/setup-python@v5
19
19
  with:
20
20
  python-version: '3.10'
21
21
 
@@ -16,18 +16,18 @@ jobs:
16
16
  group: ${{ github.workflow }}-${{ github.ref }}
17
17
 
18
18
  steps:
19
- - uses: actions/checkout@v3
19
+ - uses: actions/checkout@v4
20
20
  with:
21
21
  fetch-depth: 2
22
22
 
23
23
  - name: Cache emodb
24
- uses: actions/cache@v3
24
+ uses: actions/cache@v4
25
25
  with:
26
26
  path: emodb-src
27
27
  key: emodb-ubuntu
28
28
 
29
29
  - name: Set up Python
30
- uses: actions/setup-python@v4
30
+ uses: actions/setup-python@v5
31
31
  with:
32
32
  python-version: '3.10'
33
33
 
@@ -81,7 +81,7 @@ jobs:
81
81
 
82
82
  - name: Create release on Github
83
83
  id: create_release
84
- uses: softprops/action-gh-release@v1
84
+ uses: softprops/action-gh-release@v2
85
85
  env:
86
86
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
87
87
  with:
@@ -23,17 +23,17 @@ jobs:
23
23
  python-version: '3.11'
24
24
 
25
25
  steps:
26
- - uses: actions/checkout@v3
26
+ - uses: actions/checkout@v4
27
27
 
28
28
  - name: Cache emodb
29
- uses: actions/cache@v3
29
+ uses: actions/cache@v4
30
30
  with:
31
31
  path: emodb-src
32
32
  key: emodb-ubuntu
33
33
  if: matrix.os == 'ubuntu-20.04'
34
34
 
35
35
  - name: Set up Python ${{ matrix.python-version }}
36
- uses: actions/setup-python@v4
36
+ uses: actions/setup-python@v5
37
37
  with:
38
38
  python-version: ${{ matrix.python-version }}
39
39
 
@@ -55,7 +55,7 @@ jobs:
55
55
  python -m pytest
56
56
 
57
57
  - name: Upload coverage to Codecov
58
- uses: codecov/codecov-action@v3
58
+ uses: codecov/codecov-action@v4
59
59
  with:
60
60
  token: ${{ secrets.CODECOV_TOKEN }}
61
61
  file: ./coverage.xml
@@ -7,6 +7,17 @@ The format is based on `Keep a Changelog`_,
7
7
  and this project adheres to `Semantic Versioning`_.
8
8
 
9
9
 
10
+ Version 1.1.3 (2024-04-26)
11
+ --------------------------
12
+
13
+ * Added: ``as_dataframe`` argument
14
+ to ``audformat.utils.read_csv()``
15
+ * Fixed: ``audformat.utils.read_csv()``
16
+ now treats float/integer values
17
+ in ``start``, ``end`` columns
18
+ as seconds
19
+
20
+
10
21
  Version 1.1.2 (2024-02-02)
11
22
  --------------------------
12
23
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: audformat
3
- Version: 1.1.2
3
+ Version: 1.1.3
4
4
  Summary: Python implementation of audformat
5
5
  Author: BahaEddine Abrougui
6
6
  Author-email: Hagen Wierstorf <hwierstorf@audeering.com>, Johannes Wagner <jwagner@audeering.com>
@@ -1261,6 +1261,7 @@ def map_language(language: str) -> str:
1261
1261
 
1262
1262
  def read_csv(
1263
1263
  *args,
1264
+ as_dataframe: bool = False,
1264
1265
  **kwargs,
1265
1266
  ) -> typing.Union[pd.Index, pd.Series, pd.DataFrame]:
1266
1267
  r"""Read object from CSV file.
@@ -1269,11 +1270,18 @@ def read_csv(
1269
1270
  conform to :ref:`table specifications <data-tables:Tables>`.
1270
1271
  If conversion is not possible, an error is raised.
1271
1272
 
1272
- See :meth:`pandas.read_csv` for supported arguments.
1273
+ Time values for the ``start`` and ``end`` column
1274
+ are converted using :func:`pandas.to_timedelta`,
1275
+ whereby float and integers are treated as seconds.
1276
+
1273
1277
 
1274
1278
  Args:
1275
- *args: arguments
1276
- **kwargs: keyword arguments
1279
+ *args: arguments passed on to :func:`pandas.read_csv`
1280
+ as_dataframe: if ``False``,
1281
+ a dataframe is only returned for data with two or more columns,
1282
+ a series for data with one column,
1283
+ an index for data with zero columns
1284
+ **kwargs: keyword arguments passed on to :func:`pandas.read_csv`
1277
1285
 
1278
1286
  Returns:
1279
1287
  object conform to :ref:`table specifications <data-tables:Tables>`
@@ -1283,19 +1291,36 @@ def read_csv(
1283
1291
  :ref:`table specifications <data-tables:Tables>`
1284
1292
 
1285
1293
  Examples:
1286
- >>> from io import StringIO
1287
- >>> string = StringIO(
1288
- ... '''file,start,end,value
1294
+ >>> string = '''file,start,end,value
1289
1295
  ... f1,00:00:00,00:00:01,0.0
1290
1296
  ... f1,00:00:01,00:00:02,1.0
1291
1297
  ... f2,00:00:02,00:00:03,2.0'''
1292
- ... )
1293
- >>> read_csv(string)
1298
+ >>> with open("file.csv", "w") as file:
1299
+ ... _ = file.write(string)
1300
+ >>> read_csv("file.csv")
1301
+ file start end
1302
+ f1 0 days 00:00:00 0 days 00:00:01 0.0
1303
+ 0 days 00:00:01 0 days 00:00:02 1.0
1304
+ f2 0 days 00:00:02 0 days 00:00:03 2.0
1305
+ Name: value, dtype: float64
1306
+ >>> string = '''file,start,end,value
1307
+ ... f1,0,1,0.0
1308
+ ... f1,1,2,1.0
1309
+ ... f2,2,3,2.0'''
1310
+ >>> with open("file.csv", "w") as file:
1311
+ ... _ = file.write(string)
1312
+ >>> read_csv("file.csv")
1294
1313
  file start end
1295
1314
  f1 0 days 00:00:00 0 days 00:00:01 0.0
1296
1315
  0 days 00:00:01 0 days 00:00:02 1.0
1297
1316
  f2 0 days 00:00:02 0 days 00:00:03 2.0
1298
1317
  Name: value, dtype: float64
1318
+ >>> read_csv("file.csv", as_dataframe=True)
1319
+ value
1320
+ file start end
1321
+ f1 0 days 00:00:00 0 days 00:00:01 0.0
1322
+ 0 days 00:00:01 0 days 00:00:02 1.0
1323
+ f2 0 days 00:00:02 0 days 00:00:03 2.0
1299
1324
 
1300
1325
  """
1301
1326
  frame = pd.read_csv(*args, **kwargs)
@@ -1308,12 +1333,12 @@ def read_csv(
1308
1333
 
1309
1334
  starts = None
1310
1335
  if define.IndexField.START in frame.columns:
1311
- starts = pd.to_timedelta(frame[define.IndexField.START])
1336
+ starts = frame[define.IndexField.START]
1312
1337
  drop.append(define.IndexField.START)
1313
1338
 
1314
1339
  ends = None
1315
1340
  if define.IndexField.END in frame.columns:
1316
- ends = pd.to_timedelta(frame[define.IndexField.END])
1341
+ ends = frame[define.IndexField.END]
1317
1342
  drop.append(define.IndexField.END)
1318
1343
 
1319
1344
  if starts is None and ends is None:
@@ -1322,11 +1347,11 @@ def read_csv(
1322
1347
  index = segmented_index(files, starts=starts, ends=ends)
1323
1348
  frame.drop(drop, axis="columns", inplace=True)
1324
1349
 
1325
- if len(frame.columns) == 0:
1350
+ if len(frame.columns) == 0 and not as_dataframe:
1326
1351
  return index
1327
1352
 
1328
1353
  frame = frame.set_index(index)
1329
- if len(frame.columns) == 1:
1354
+ if len(frame.columns) == 1 and not as_dataframe:
1330
1355
  return frame[frame.columns[0]]
1331
1356
  else:
1332
1357
  return frame
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: audformat
3
- Version: 1.1.2
3
+ Version: 1.1.3
4
4
  Summary: Python implementation of audformat
5
5
  Author: BahaEddine Abrougui
6
6
  Author-email: Hagen Wierstorf <hwierstorf@audeering.com>, Johannes Wagner <jwagner@audeering.com>
@@ -1461,6 +1461,23 @@ f2,00:00:02,2.0"""
1461
1461
  name="value",
1462
1462
  ),
1463
1463
  ),
1464
+ (
1465
+ StringIO(
1466
+ """file,start,value
1467
+ f1,0,0.0
1468
+ f1,1,1.0
1469
+ f2,2,2.0"""
1470
+ ),
1471
+ pd.Series(
1472
+ [0.0, 1.0, 2.0],
1473
+ index=audformat.segmented_index(
1474
+ ["f1", "f1", "f2"],
1475
+ starts=["0s", "1s", "2s"],
1476
+ ends=pd.to_timedelta([pd.NaT, pd.NaT, pd.NaT]),
1477
+ ),
1478
+ name="value",
1479
+ ),
1480
+ ),
1464
1481
  (
1465
1482
  StringIO(
1466
1483
  """file,end,value
@@ -1491,6 +1508,19 @@ f2,00:00:02,00:00:03"""
1491
1508
  ["1s", "2s", "3s"],
1492
1509
  ),
1493
1510
  ),
1511
+ (
1512
+ StringIO(
1513
+ """file,start,end
1514
+ f1,0,1
1515
+ f1,1,2
1516
+ f2,2,3"""
1517
+ ),
1518
+ audformat.segmented_index(
1519
+ ["f1", "f1", "f2"],
1520
+ ["0s", "1s", "2s"],
1521
+ ["1s", "2s", "3s"],
1522
+ ),
1523
+ ),
1494
1524
  (
1495
1525
  StringIO(
1496
1526
  """file,start,end,value
@@ -1508,6 +1538,40 @@ f2,00:00:02,00:00:03,2.0"""
1508
1538
  name="value",
1509
1539
  ),
1510
1540
  ),
1541
+ (
1542
+ StringIO(
1543
+ """file,start,end,value
1544
+ f1,0,1,0.0
1545
+ f1,1,2,1.0
1546
+ f2,2,3,2.0"""
1547
+ ),
1548
+ pd.Series(
1549
+ [0.0, 1.0, 2.0],
1550
+ index=audformat.segmented_index(
1551
+ ["f1", "f1", "f2"],
1552
+ starts=["0s", "1s", "2s"],
1553
+ ends=["1s", "2s", "3s"],
1554
+ ),
1555
+ name="value",
1556
+ ),
1557
+ ),
1558
+ (
1559
+ StringIO(
1560
+ """file,start,end,value
1561
+ f1,0.0,1.0,0.0
1562
+ f1,1.0,2.0,1.0
1563
+ f2,2.0,3.0,2.0"""
1564
+ ),
1565
+ pd.Series(
1566
+ [0.0, 1.0, 2.0],
1567
+ index=audformat.segmented_index(
1568
+ ["f1", "f1", "f2"],
1569
+ starts=["0s", "1s", "2s"],
1570
+ ends=["1s", "2s", "3s"],
1571
+ ),
1572
+ name="value",
1573
+ ),
1574
+ ),
1511
1575
  (
1512
1576
  StringIO(
1513
1577
  """file,start,end,value1,value2
@@ -1548,6 +1612,14 @@ def test_read_csv(csv, result):
1548
1612
  pd.testing.assert_series_equal(obj, result)
1549
1613
  else:
1550
1614
  pd.testing.assert_frame_equal(obj, result)
1615
+ # Request dataframe as return type
1616
+ csv.seek(0) # rewind string file object
1617
+ obj = audformat.utils.read_csv(csv, as_dataframe=True)
1618
+ if isinstance(result, pd.Index):
1619
+ result = pd.DataFrame([], columns=[], index=result)
1620
+ elif isinstance(result, pd.Series):
1621
+ result = result.to_frame()
1622
+ pd.testing.assert_frame_equal(obj, result)
1551
1623
 
1552
1624
 
1553
1625
  @pytest.mark.parametrize(
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
File without changes
File without changes