Skip to content

Commit

Permalink
Fixed Sample serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
khoroshevskyi committed Aug 15, 2023
1 parent df76b04 commit 55d142e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion peppy/_version.py
@@ -1 +1 @@
__version__ = "0.40.0a2"
__version__ = "0.40.0a3"
3 changes: 2 additions & 1 deletion peppy/project.py
Expand Up @@ -226,7 +226,7 @@ def from_dict(self, pep_dictionary: dict) -> "Project":

def to_dict(
self,
expand: bool = False,
# expand: bool = False, # expand was used to expand paths. This functionality was removed, because of attmapp
extended: bool = False,
orient: Literal[
"dict", "list", "series", "split", "tight", "records", "index"
Expand Down Expand Up @@ -1397,6 +1397,7 @@ def __delitem__(self, key):
def __repr__(self):
return str(self)

# # pickle now is impossible, because it's impossible to initialize Project class without using actual files
# def __reduce__(self):
# return (self.__class__,)

Expand Down
7 changes: 3 additions & 4 deletions peppy/sample.py
Expand Up @@ -307,10 +307,9 @@ def __reduce__(self):
return (
self.__class__,
(pd.Series(self.to_dict()),),
# (self.as_series(),),
(None, {}),
iter([]),
iter({PRJ_REF: self[PRJ_REF]}.items()),
# (None, {}),
# iter([]),
# iter({PRJ_REF: self[PRJ_REF]}.items()),
)

def __len__(self):
Expand Down
11 changes: 11 additions & 0 deletions tests/smoketests/test_Sample.py
Expand Up @@ -66,3 +66,14 @@ def test_sheet_dict_excludes_private_attrs(self, example_pep_cfg_path):
p = Project(cfg=example_pep_cfg_path)
for sample in p.samples:
assert len(sample.get_sheet_dict()) == len(p.sample_table.columns)

@pytest.mark.parametrize("example_pep_cfg_path", ["basic"], indirect=True)
def test_pickle_in_samples(self, example_pep_cfg_path):
import pickle

p = Project(cfg=example_pep_cfg_path)
for sample in p.samples:
pickled_data = pickle.dumps(sample)
unpickled_sample = pickle.loads(pickled_data)

assert sample.to_dict() == unpickled_sample.to_dict()
4 changes: 3 additions & 1 deletion tests/test_Project.py
Expand Up @@ -393,10 +393,12 @@ 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.skip(
"skipping this test, because this functionality is unavailable now"
)
@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)

Expand Down

0 comments on commit 55d142e

Please sign in to comment.