|
55 | 55 | ) |
56 | 56 | import numpy as np |
57 | 57 | import os |
58 | | -import pathlib |
| 58 | +from pathlib import Path |
59 | 59 | import copy |
60 | 60 | import warnings |
61 | 61 | from collections import namedtuple, OrderedDict |
@@ -151,15 +151,15 @@ def __init__( |
151 | 151 |
|
152 | 152 | if filename is not None: |
153 | 153 | include_filenames = [filename] |
154 | | - warnings.warn("`filename` is deprecated and will be removed. Please use `include_filenames` instead") |
| 154 | + warnings.warn("`filename` is deprecated and will be removed in version 1.0. Please use `include_filenames` instead") |
155 | 155 |
|
156 | 156 | if exclude_filename is not None: |
157 | 157 | if isinstance(exclude_filename, str): |
158 | 158 | exclude_filenames = [exclude_filename] |
159 | 159 | else: |
160 | 160 | exclude_filenames = exclude_filename |
161 | 161 | warnings.warn( |
162 | | - "`exclude_filename` is deprecated and will be removed. Please use `exclude_filenames` instead" |
| 162 | + "`exclude_filename` is deprecated and will be removed in version 1.0. Please use `exclude_filenames` instead" |
163 | 163 | ) |
164 | 164 |
|
165 | 165 | if include_filenames is None: |
@@ -214,30 +214,43 @@ def _parse_header(self): |
214 | 214 | unit_annotations = [] |
215 | 215 | event_annotations = [] |
216 | 216 |
|
217 | | - if self.rawmode == "one-dir": |
218 | | - filenames = sorted(os.listdir(self.dirname)) |
219 | | - else: |
220 | | - filenames = self.include_filenames |
221 | | - |
222 | | - filenames = [f for f in filenames if f not in self.exclude_filenames] |
223 | | - full_filenames = [os.path.join(self.dirname, f) for f in filenames] |
224 | | - |
225 | | - for filename in full_filenames: |
226 | | - if not os.path.isfile(filename): |
227 | | - raise ValueError( |
228 | | - f"Provided Filename is not a file: " |
229 | | - f"{filename}. If you want to provide a " |
230 | | - f"directory use the `dirname` keyword" |
231 | | - ) |
| 217 | + # 1) Get file paths based on mode and validate existence for multiple-files mode |
| 218 | + if self.rawmode == "multiple-files": |
| 219 | + # For multiple-files mode, validate that all explicitly provided files exist |
| 220 | + file_paths = [] |
| 221 | + for filename in self.include_filenames: |
| 222 | + full_path = Path(self.dirname) / filename |
| 223 | + if not full_path.is_file(): |
| 224 | + raise ValueError( |
| 225 | + f"Provided Filename is not a file: " |
| 226 | + f"{full_path}. If you want to provide a " |
| 227 | + f"directory use the `dirname` keyword" |
| 228 | + ) |
| 229 | + file_paths.append(full_path) |
| 230 | + else: # one-dir mode |
| 231 | + # For one-dir mode, get all files from directory |
| 232 | + dir_path = Path(self.dirname) |
| 233 | + file_paths = [p for p in dir_path.iterdir() if p.is_file()] |
| 234 | + file_paths = sorted(file_paths, key=lambda p: p.name) |
| 235 | + |
| 236 | + # 2) Filter by exclude filenames |
| 237 | + file_paths = [fp for fp in file_paths if fp.name not in self.exclude_filenames] |
| 238 | + |
| 239 | + # 3) Filter to keep only files with correct extensions |
| 240 | + # Note: suffix[1:] removes the leading dot from file extension (e.g., ".ncs" -> "ncs") |
| 241 | + valid_file_paths = [ |
| 242 | + fp for fp in file_paths |
| 243 | + if fp.suffix[1:].lower() in self.extensions |
| 244 | + ] |
| 245 | + |
| 246 | + # Convert back to strings for backwards compatibility with existing code |
| 247 | + full_filenames = [str(fp) for fp in valid_file_paths] |
232 | 248 |
|
233 | 249 | stream_props = {} # {(sampling_rate, n_samples, t_start): {stream_id: [filenames]} |
234 | 250 |
|
235 | 251 | for filename in full_filenames: |
236 | 252 | _, ext = os.path.splitext(filename) |
237 | | - ext = ext[1:] # remove dot |
238 | | - ext = ext.lower() # make lower case for comparisons |
239 | | - if ext not in self.extensions: |
240 | | - continue |
| 253 | + ext = ext[1:].lower() # remove dot and make lower case |
241 | 254 |
|
242 | 255 | # Skip Ncs files with only header. Other empty file types |
243 | 256 | # will have an empty dataset constructed later. |
@@ -574,7 +587,7 @@ def _get_file_map(filename): |
574 | 587 | Create memory maps when needed |
575 | 588 | see also https://github.com/numpy/numpy/issues/19340 |
576 | 589 | """ |
577 | | - filename = pathlib.Path(filename) |
| 590 | + filename = Path(filename) |
578 | 591 | suffix = filename.suffix.lower()[1:] |
579 | 592 |
|
580 | 593 | if suffix == "ncs": |
|
0 commit comments