5
5
import re
6
6
import warnings
7
7
import scipy.io.wavfile
8
- from pathlib import Path
9
8
10
9
from . import util
11
10
from . import key
16
15
def _open(file_or_path, **kwargs):
17
16
"""Either open a file handle, or use an existing file-like object.
18
17
19
- This will behave as the `open` function if `file_or_path` is a string or `pathlib.Path`.
20
-
21
18
If `file_or_path` has the `read` attribute, it will return `file_or_path`.
22
19
23
- Otherwise, an `IOError` is raised .
20
+ Otherwise, it will attempt to open the file at the specified location .
24
21
"""
25
22
if hasattr(file_or_path, "read"):
26
23
yield file_or_path
27
- elif isinstance(file_or_path, (str, Path)):
28
- with open(file_or_path, **kwargs) as file_desc:
29
- yield file_desc
30
24
else:
31
- raise IOError(f"Invalid file-or-path object: {file_or_path}")
25
+ try:
26
+ with open(file_or_path, **kwargs) as file_desc:
27
+ yield file_desc
28
+ except TypeError as exc:
29
+ raise IOError(f"Invalid file-or-path object: {file_or_path}") from exc
32
30
33
31
34
32
def load_delimited(filename, converters, delimiter=r"\s+", comment="#"):
@@ -44,7 +42,7 @@ def load_delimited(filename, converters, delimiter=r"\s+", comment="#"):
44
42
45
43
Parameters
46
44
----------
47
- filename : str or `pathlib.Path `
45
+ filename : str or `os.Pathlike `
48
46
Path to the annotation file
49
47
50
48
converters : list of functions
@@ -130,7 +128,7 @@ def load_events(filename, delimiter=r"\s+", comment="#"):
130
128
131
129
Parameters
132
130
----------
133
- filename : str or `pathlib.Path `
131
+ filename : str or `os.Pathlike `
134
132
Path to the annotation file
135
133
136
134
delimiter : str
@@ -170,7 +168,7 @@ def load_labeled_events(filename, delimiter=r"\s+", comment="#"):
170
168
171
169
Parameters
172
170
----------
173
- filename : str or `pathlib.Path `
171
+ filename : str or `os.Pathlike `
174
172
Path to the annotation file
175
173
176
174
delimiter : str
@@ -213,7 +211,7 @@ def load_intervals(filename, delimiter=r"\s+", comment="#"):
213
211
214
212
Parameters
215
213
----------
216
- filename : str or `pathlib.Path `
214
+ filename : str or `os.Pathlike `
217
215
Path to the annotation file
218
216
219
217
delimiter : str
@@ -256,7 +254,7 @@ def load_labeled_intervals(filename, delimiter=r"\s+", comment="#"):
256
254
257
255
Parameters
258
256
----------
259
- filename : str or `pathlib.Path `
257
+ filename : str or `os.Pathlike `
260
258
Path to the annotation file
261
259
262
260
delimiter : str
@@ -299,7 +297,7 @@ def load_time_series(filename, delimiter=r"\s+", comment="#"):
299
297
300
298
Parameters
301
299
----------
302
- filename : str or `pathlib.Path `
300
+ filename : str or `os.Pathlike `
303
301
Path to the annotation file
304
302
305
303
delimiter : str
@@ -340,7 +338,7 @@ def load_patterns(filename):
340
338
341
339
Parameters
342
340
----------
343
- filename : str or `pathlib.Path `
341
+ filename : str or `os.Pathlike `
344
342
The input file path containing the patterns of a given piece using the
345
343
MIREX 2013 format.
346
344
@@ -418,7 +416,7 @@ def load_wav(path, mono=True):
418
416
419
417
Parameters
420
418
----------
421
- path : str or `pathlib.Path `
419
+ path : str or `os.Pathlike `
422
420
Path to a .wav file
423
421
mono : bool
424
422
If the provided .wav has more than one channel, it will be
@@ -457,7 +455,7 @@ def load_valued_intervals(filename, delimiter=r"\s+", comment="#"):
457
455
458
456
Parameters
459
457
----------
460
- filename : str or `pathlib.Path `
458
+ filename : str or `os.Pathlike `
461
459
Path to the annotation file
462
460
463
461
delimiter : str
@@ -504,7 +502,7 @@ def load_key(filename, delimiter=r"\s+", comment="#"):
504
502
505
503
Parameters
506
504
----------
507
- filename : str or `pathlib.Path `
505
+ filename : str or `os.Pathlike `
508
506
Path to the annotation file
509
507
510
508
delimiter : str
@@ -550,7 +548,7 @@ def load_tempo(filename, delimiter=r"\s+", comment="#"):
550
548
551
549
Parameters
552
550
----------
553
- filename : str or `pathlib.Path `
551
+ filename : str or `os.Pathlike `
554
552
Path to the annotation file
555
553
556
554
delimiter : str
@@ -614,7 +612,7 @@ def load_ragged_time_series(
614
612
615
613
Parameters
616
614
----------
617
- filename : str or `pathlib.Path `
615
+ filename : str or `os.Pathlike `
618
616
Path to the annotation file
619
617
620
618
dtype : function
0 commit comments