@@ -322,13 +322,10 @@ def __init__(self, **kwargs):
322322 assert isinstance (self .dir_path , Path )
323323 assert self .dir_path .exists ()
324324
325- # Set dat_path.
326- if not self .dat_path : # pragma: no cover
327- self .dat_path = []
328- elif not isinstance (self .dat_path , (list , tuple )):
329- self .dat_path = [self .dat_path ]
330- assert isinstance (self .dat_path , (list , tuple ))
331- self .dat_path = [Path (p ).resolve () if not Path (p ).is_symlink () else p for p in self .dat_path ]
325+ # Set dat_path. Blank entries mean "no raw data file", see _clean_dat_path().
326+ self .dat_path = [
327+ Path (p ).resolve () if not Path (p ).is_symlink () else p
328+ for p in _clean_dat_path (self .dat_path )]
332329
333330 self .dtype = getattr (self , 'dtype' , np .int16 )
334331 if not self .sample_rate : # pragma: no cover
@@ -1416,6 +1413,23 @@ def close(self):
14161413 _close_memmap (k , v )
14171414
14181415
1416+ def _clean_dat_path (dat_path ):
1417+ """Normalize a raw data path specification into a list of non-empty paths.
1418+
1419+ A blank `dat_path` means the dataset has no raw data file at all. Some sorters write
1420+ `dat_path = ''` in `params.py` when the recording has no file on disk, for instance
1421+ SpikeInterface with a simulated or in-memory recording. Such entries have to be dropped
1422+ rather than resolved, because `Path('')` is `Path('.')`, which would silently turn the
1423+ missing raw data file into the dataset directory itself.
1424+
1425+ """
1426+ if not dat_path :
1427+ return []
1428+ if not isinstance (dat_path , (list , tuple )):
1429+ dat_path = [dat_path ]
1430+ return [p for p in dat_path if str (p ).strip ()]
1431+
1432+
14191433def _make_abs_path (p , dir_path ):
14201434 p = Path (p )
14211435 if not op .isabs (p ):
@@ -1438,9 +1452,8 @@ def get_template_params(params_path):
14381452 assert params ['dir_path' ].is_dir ()
14391453 assert params ['dir_path' ].exists ()
14401454
1441- if isinstance (params ['dat_path' ], str ):
1442- params ['dat_path' ] = [params ['dat_path' ]]
1443- params ['dat_path' ] = [_make_abs_path (_ , params ['dir_path' ]) for _ in params ['dat_path' ]]
1455+ params ['dat_path' ] = [
1456+ _make_abs_path (_ , params ['dir_path' ]) for _ in _clean_dat_path (params ['dat_path' ])]
14441457 return params
14451458
14461459
0 commit comments