Skip to content

Commit

Permalink
Merge pull request #453 from pepkit/dev
Browse files Browse the repository at this point in the history
Release 0.35.7
  • Loading branch information
khoroshevskyi committed Jul 19, 2023
2 parents f9845b1 + 5997971 commit d4cfc63
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format.

## [0.35.7] -- 2023-07-19
### Fixed
- incorrect setting of sample and subsample indexes using from_dict function (#452)
- clarified debug messages

## [0.35.6] -- 2023-06-27
### Added
- `orient` argument to `to_dict` method
Expand Down
2 changes: 1 addition & 1 deletion peppy/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.35.6"
__version__ = "0.35.7"
33 changes: 24 additions & 9 deletions peppy/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from collections.abc import Mapping
from contextlib import suppress
from logging import getLogger
from typing import Dict, Iterable, List, Tuple, Union, Literal
from typing import Dict, Iterable, List, Tuple, Union, Literal, NoReturn

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -220,6 +220,8 @@ def from_dict(self, pep_dictionary: dict) -> "Project":
if DESC_KEY in self[CONFIG_KEY]:
self[DESC_KEY] = self[CONFIG_KEY][DESC_KEY]

self._set_indexes(self[CONFIG_KEY])

self.create_samples(modify=False if self[SAMPLE_TABLE_FILE_KEY] else True)
self._sample_table = self._get_table_from_samples(
index=self.st_index, initial=True
Expand Down Expand Up @@ -268,6 +270,9 @@ def create_samples(self, modify: bool = False):
Populate Project with Sample objects
"""
self._samples: List[Sample] = self.load_samples()
if self.samples is None:
_LOGGER.info("No samples found in the project.")

if modify:
self.modify_samples()
else:
Expand Down Expand Up @@ -336,14 +341,7 @@ def parse_config_file(

_LOGGER.debug("Raw ({}) config data: {}".format(cfg_path, config))

self.st_index = (
config[SAMPLE_TABLE_INDEX_KEY] if SAMPLE_TABLE_INDEX_KEY in config else None
)
self.sst_index = (
config[SUBSAMPLE_TABLE_INDEX_KEY]
if SUBSAMPLE_TABLE_INDEX_KEY in config
else None
)
self._set_indexes(config)
# recursively import configs
if (
PROJ_MODS_KEY in config
Expand Down Expand Up @@ -398,6 +396,23 @@ def parse_config_file(
relative_vars = [CFG_SAMPLE_TABLE_KEY, CFG_SUBSAMPLE_TABLE_KEY]
_make_sections_absolute(self[CONFIG_KEY], relative_vars, cfg_path)

def _set_indexes(self, config: Mapping) -> NoReturn:
"""
Set sample and subsample indexes if they are different then Default
:param config: project config
"""
self.st_index = (
config[SAMPLE_TABLE_INDEX_KEY]
if SAMPLE_TABLE_INDEX_KEY in config
else SAMPLE_NAME_ATTR
)
self.sst_index = (
config[SUBSAMPLE_TABLE_INDEX_KEY]
if SUBSAMPLE_TABLE_INDEX_KEY in config
else SUBSAMPLE_NAME_ATTR
)

def load_samples(self):
"""
Read the sample_table and subsample_tables into dataframes
Expand Down
4 changes: 3 additions & 1 deletion tests/test_Project.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,9 @@ def test_unequality(self, example_pep_cfg_path, example_pep_csv_path):
assert not p1 == p2

@pytest.mark.parametrize(
"example_pep_cfg_path", ["append", "subtable2"], indirect=True
"example_pep_cfg_path",
["append", "custom_index", "imply", "subtables"],
indirect=True,
)
@pytest.mark.parametrize("orient", ["dict", "records"])
def test_from_dict(self, example_pep_cfg_path, orient):
Expand Down

0 comments on commit d4cfc63

Please sign in to comment.