diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a82707..6498d73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ project adheres to clauses 1–8 of [Semantic Versioning](https://semver.org/spe ## [Unreleased] +## [0.15.2] (Jun 28 2024) + +### Changed + +- `ParamDataFrame` now saves and loads DataFrames to and from Pickle files instead of CSV + files. + ## [0.15.1] (Jun 26 2024) ### Fixed diff --git a/paramdb/_param_data/_files.py b/paramdb/_param_data/_files.py index 2e06c18..3ffeb2e 100644 --- a/paramdb/_param_data/_files.py +++ b/paramdb/_param_data/_files.py @@ -1,7 +1,7 @@ """Base class for parameter files.""" from __future__ import annotations -from typing import TypeVar, Generic +from typing import TypeVar, Generic, cast from abc import abstractmethod from dataclasses import InitVar from paramdb._param_data._dataclasses import ParamDataclass @@ -68,12 +68,12 @@ class ParamDataFrame(ParamFile[pd.DataFrame]): """ Subclass of :py:class:`ParamFile`. - Parameter data Pandas DataFrame, stored in a CSV file (with no index). This - class will only be defined if Pandas is installed. + Parameter data Pandas DataFrame, stored in a Pickle file. This class will only + be defined if Pandas is installed. """ def _load_data(self, path: str) -> pd.DataFrame: - return pd.read_csv(path) + return cast(pd.DataFrame, pd.read_pickle(path)) def _save_data(self, path: str, data: pd.DataFrame) -> None: - data.to_csv(path, index=False) + data.to_pickle(path) diff --git a/tests/_param_data/test_files.py b/tests/_param_data/test_files.py index 33ec86c..611cbaa 100644 --- a/tests/_param_data/test_files.py +++ b/tests/_param_data/test_files.py @@ -88,7 +88,7 @@ def test_param_file_saves_file( type(param_file)(param_file_path, data) assert os.path.exists(param_file_path) if isinstance(param_file, ParamDataFrame): - pd.testing.assert_frame_equal(data, pd.read_csv(param_file_path)) + pd.testing.assert_frame_equal(data, pd.read_pickle(param_file_path)) else: with open(param_file_path, "r", encoding="utf-8") as f: assert data == f.read()