mirror of
https://github.com/freqtrade/freqtrade.git
synced 2026-02-19 10:50:50 +00:00
chore: improve zip file loading interface
This commit is contained in:
@@ -404,12 +404,13 @@ def load_backtest_data(filename: Path | str, strategy: str | None = None) -> pd.
|
||||
return df
|
||||
|
||||
|
||||
def load_file_from_zip(zip_path: Path, filename: str) -> bytes | None:
|
||||
def load_file_from_zip(zip_path: Path, filename: str) -> bytes:
|
||||
"""
|
||||
Load a file from a zip file
|
||||
:param zip_path: Path to the zip file
|
||||
:param filename: Name of the file to load
|
||||
:return: Bytes of the file
|
||||
:raises: ValueError if loading goes wrong.
|
||||
"""
|
||||
try:
|
||||
with zipfile.ZipFile(zip_path) as zipf:
|
||||
@@ -417,7 +418,7 @@ def load_file_from_zip(zip_path: Path, filename: str) -> bytes | None:
|
||||
return file.read()
|
||||
except zipfile.BadZipFile:
|
||||
logger.exception(f"Bad zip file: {zip_path}")
|
||||
return None
|
||||
raise ValueError(f"Bad zip file: {zip_path}") from None
|
||||
|
||||
|
||||
def load_backtest_analysis_data(backtest_dir: Path, name: str):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import logging
|
||||
from io import BytesIO, StringIO
|
||||
from pathlib import Path
|
||||
from typing import Any, TextIO
|
||||
from typing import Any
|
||||
from zipfile import ZIP_DEFLATED, ZipFile
|
||||
|
||||
from pandas import DataFrame
|
||||
@@ -16,7 +16,7 @@ from freqtrade.optimize.backtest_caching import get_backtest_metadata_filename
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def file_dump_joblib(file_obj: TextIO, data: Any, log: bool = True) -> None:
|
||||
def file_dump_joblib(file_obj: BytesIO, data: Any, log: bool = True) -> None:
|
||||
"""
|
||||
Dump object data into a file
|
||||
:param filename: file to create
|
||||
|
||||
Reference in New Issue
Block a user