diff --git a/peppy/project.py b/peppy/project.py index 05db0e45..3310c3a1 100644 --- a/peppy/project.py +++ b/peppy/project.py @@ -1397,6 +1397,9 @@ def __delitem__(self, key): def __repr__(self): return str(self) + # def __reduce__(self): + # return (self.__class__,) + def infer_delimiter(filepath): """ diff --git a/peppy/sample.py b/peppy/sample.py index 8e3c2767..eac6bc45 100644 --- a/peppy/sample.py +++ b/peppy/sample.py @@ -306,7 +306,8 @@ def project(self): def __reduce__(self): return ( self.__class__, - (self.as_series(),), + (pd.Series(self.to_dict()),), + # (self.as_series(),), (None, {}), iter([]), iter({PRJ_REF: self[PRJ_REF]}.items()), diff --git a/tests/test_Project.py b/tests/test_Project.py index 7a4f33c1..9833c0cb 100644 --- a/tests/test_Project.py +++ b/tests/test_Project.py @@ -8,7 +8,9 @@ import pytest from pandas import DataFrame from yaml import dump, safe_load +import pickle +import peppy from peppy import Project from peppy.const import SAMPLE_NAME_ATTR, SAMPLE_TABLE_FILE_KEY from peppy.exceptions import ( @@ -391,6 +393,15 @@ def test_peppy_initializes_samples_with_correct_attributes( p = Project(example_pep_cfg_path, sample_table_index="sample") assert all([expected_attribute in sample for sample in p.samples]) + @pytest.mark.parametrize("example_pep_cfg_path", ["basic", "imply"], indirect=True) + def test_correct_pickle(self, example_pep_cfg_path): + proj = Project(example_pep_cfg_path) + + pickled_data = pickle.dumps(proj) + unpickled_project = pickle.loads(pickled_data) + + assert proj == unpickled_project + class TestProjectManipulationTests: @pytest.mark.parametrize("example_pep_cfg_path", ["amendments1"], indirect=True)