Skip to content

Commit 7a61959

Browse files
committed
chore: improve zip file loading interface
1 parent 0682d12 commit 7a61959

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

freqtrade/data/btanalysis.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,20 +404,21 @@ def load_backtest_data(filename: Path | str, strategy: str | None = None) -> pd.
404404
return df
405405

406406

407-
def load_file_from_zip(zip_path: Path, filename: str) -> bytes | None:
407+
def load_file_from_zip(zip_path: Path, filename: str) -> bytes:
408408
"""
409409
Load a file from a zip file
410410
:param zip_path: Path to the zip file
411411
:param filename: Name of the file to load
412412
:return: Bytes of the file
413+
:raises: ValueError if loading goes wrong.
413414
"""
414415
try:
415416
with zipfile.ZipFile(zip_path) as zipf:
416417
with zipf.open(filename) as file:
417418
return file.read()
418419
except zipfile.BadZipFile:
419420
logger.exception(f"Bad zip file: {zip_path}")
420-
return None
421+
raise ValueError(f"Bad zip file: {zip_path}") from None
421422

422423

423424
def load_backtest_analysis_data(backtest_dir: Path, name: str):

freqtrade/optimize/optimize_reports/bt_storage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
from io import BytesIO, StringIO
33
from pathlib import Path
4-
from typing import Any, TextIO
4+
from typing import Any
55
from zipfile import ZIP_DEFLATED, ZipFile
66

77
from pandas import DataFrame
@@ -16,7 +16,7 @@
1616
logger = logging.getLogger(__name__)
1717

1818

19-
def file_dump_joblib(file_obj: TextIO, data: Any, log: bool = True) -> None:
19+
def file_dump_joblib(file_obj: BytesIO, data: Any, log: bool = True) -> None:
2020
"""
2121
Dump object data into a file
2222
:param filename: file to create

0 commit comments

Comments
 (0)