From 1e89cebe65687a163e695e0f78c267a32b8d1b35 Mon Sep 17 00:00:00 2001 From: Shing Chan Date: Mon, 5 Feb 2024 02:03:37 +0000 Subject: [PATCH] fix(read): handle filenames with dots confusing with extension --- src/stepcount/stepcount.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/stepcount/stepcount.py b/src/stepcount/stepcount.py index 53b3adc..1639ee4 100644 --- a/src/stepcount/stepcount.py +++ b/src/stepcount/stepcount.py @@ -333,8 +333,10 @@ def nanint(x): def read(filepath, resample_hz='uniform', sample_rate=None, verbose=True): p = pathlib.Path(filepath) - ftype = p.suffixes[0].lower() fsize = round(p.stat().st_size / (1024 * 1024), 1) + ftype = p.suffix.lower() + if ftype in (".gz", ".xz", ".lzma", ".bz2", ".zip"): # if file is compressed, check the next extension + ftype = pathlib.Path(p.stem).suffix.lower() if ftype in (".csv", ".pkl"): @@ -386,6 +388,9 @@ def read(filepath, resample_hz='uniform', sample_rate=None, verbose=True): verbose=verbose, ) + else: + raise ValueError(f"Unknown file format: {ftype}") + if 'ResampleRate' not in info: info['ResampleRate'] = info['SampleRate']