Skip to content

Commit

Permalink
added __reduce__ function to project
Browse files Browse the repository at this point in the history
  • Loading branch information
khoroshevskyi committed Aug 15, 2023
1 parent 55d142e commit ed1af89
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
22 changes: 19 additions & 3 deletions peppy/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ class Project(MutableMapping):
:param str | Iterable[str] amendments: names of the amendments to activate
:param Iterable[str] amendments: amendments to use within configuration file
:param bool defer_samples_creation: whether the sample creation should be skipped
:param Dict[Any]: dict representation of the project {_config: str,
_samples: list | dict,
_subsamples: list[list | dict]}
:Example:
Expand All @@ -105,6 +108,7 @@ def __init__(
sample_table_index: Union[str, Iterable[str]] = None,
subsample_table_index: Union[str, Iterable[str]] = None,
defer_samples_creation: bool = False,
from_dict: dict = None,
):
_LOGGER.debug(
"Creating {}{}".format(
Expand Down Expand Up @@ -159,6 +163,8 @@ def __init__(
self._sample_table = self._get_table_from_samples(
index=self.st_index, initial=True
)
if from_dict:
self.from_dict(from_dict)

def __eq__(self, other):
return [s.to_dict() for s in self.samples] == [
Expand Down Expand Up @@ -1397,9 +1403,19 @@ 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__,)
# pickle now is impossible, because it's impossible to initialize Project class without using actual files
def __reduce__(self):
return (
self.__class__,
(
None,
None,
None,
None,
False,
self.to_dict(extended=True, orient="records"),
),
)


def infer_delimiter(filepath):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_Project.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,9 @@ 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.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)
Expand Down

0 comments on commit ed1af89

Please sign in to comment.