Skip to content

Commit

Permalink
fix save when no batches were processed
Browse files Browse the repository at this point in the history
  • Loading branch information
timonmerk committed Jan 24, 2025
1 parent 1d19a08 commit eff4c1d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 0 additions & 1 deletion py_neuromodulation/stream/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def __init__(
sampling_rate_features_hz: float | None = None,
path_grids: _PathLike | None = None,
coord_names: list | None = None,
is_stream_lsl: bool = False,
coord_list: list | None = None,
verbose: bool = True,
) -> None:
Expand Down
10 changes: 8 additions & 2 deletions py_neuromodulation/utils/file_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pandas as pd
import numpy as np
from py_neuromodulation.utils.types import _PathLike
from py_neuromodulation import logger

class AbstractFileWriter(ABC):

Expand Down Expand Up @@ -78,7 +79,8 @@ def load_all(self):
for i in range(self.idx):
with open(self.out_dir / f"{self.name}-{i}.msgpack", "rb") as f:
data_l.append(msgpack.unpack(f))

if len(self.data_l) == 0:
raise ValueError("No data to load")
data = pd.DataFrame(list(np.concatenate(data_l)))
return data

Expand All @@ -88,7 +90,11 @@ def save_as_csv(self, save_all_combined: bool = False):
"""

if save_all_combined:
data = self.load_all()
try:
data = self.load_all()
except ValueError as e:
logger.error(e)
return
data.to_csv(self.csv_path, index=False)
else:
if len(self.data_l) > 0:
Expand Down

0 comments on commit eff4c1d

Please sign in to comment.