Skip to content

Commit

Permalink
Save using Pickle instead of CSV in ParamDataFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhad6 committed Jun 28, 2024
1 parent e4b175c commit a197382
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions paramdb/_param_data/_files.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion tests/_param_data/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit a197382

Please sign in to comment.