From efec4b99704d796d615311115a4ff2178b35aff3 Mon Sep 17 00:00:00 2001 From: Khoroshevskyi Date: Mon, 3 Apr 2023 15:51:26 -0400 Subject: [PATCH 1/6] to_dict fix --- peppy/project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/peppy/project.py b/peppy/project.py index d16d470f..ee378e76 100644 --- a/peppy/project.py +++ b/peppy/project.py @@ -242,7 +242,7 @@ def to_dict(self, expand: bool = False, extended: bool = False) -> dict: sub_df = None p_dict = { SAMPLE_RAW_DICT_KEY: self[SAMPLE_DF_KEY].to_dict(), - CONFIG_KEY: self[CONFIG_KEY], + CONFIG_KEY: dict(self[CONFIG_KEY]), SUBSAMPLE_RAW_DICT_KEY: sub_df, NAME_KEY: self[NAME_KEY], DESC_KEY: self[DESC_KEY], From a9b8f0f8f8ce620aed3fe445b764b7c33f2e5a81 Mon Sep 17 00:00:00 2001 From: ayobi <17304717+ayobi@users.noreply.github.com> Date: Fri, 21 Apr 2023 22:14:17 -0400 Subject: [PATCH 2/6] added handling of empty sample file. fixes #444 --- peppy/project.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/peppy/project.py b/peppy/project.py index ee378e76..90bac9f7 100644 --- a/peppy/project.py +++ b/peppy/project.py @@ -259,6 +259,9 @@ def create_samples(self, modify: bool = False): """ self._samples: List[Sample] = self.load_samples() if modify: + if self.samples is None: + _LOGGER.info("No samples found in file.") + sys.exit(1) self.modify_samples() else: self._assert_samples_have_names() From b9b9d39c20fcbb5e6b39b33524135c08381a2081 Mon Sep 17 00:00:00 2001 From: ayobi <17304717+ayobi@users.noreply.github.com> Date: Sat, 22 Apr 2023 17:17:20 -0400 Subject: [PATCH 3/6] added message if empty sample file. fixes #444 --- peppy/project.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/peppy/project.py b/peppy/project.py index 90bac9f7..066ac382 100644 --- a/peppy/project.py +++ b/peppy/project.py @@ -258,10 +258,10 @@ 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: - if self.samples is None: - _LOGGER.info("No samples found in file.") - sys.exit(1) self.modify_samples() else: self._assert_samples_have_names() From 876ac49d24882b8af8cc78f2ca36b600fe5a86c6 Mon Sep 17 00:00:00 2001 From: nsheff Date: Mon, 24 Apr 2023 16:00:06 -0400 Subject: [PATCH 4/6] clarify debug msg --- peppy/project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/peppy/project.py b/peppy/project.py index ee378e76..a98be147 100644 --- a/peppy/project.py +++ b/peppy/project.py @@ -450,7 +450,7 @@ def _modifier_exists(self, modifier_key=None): :param str modifier_key: modifier key to be checked :return bool: whether the requirements are met """ - _LOGGER.debug("Checking existence: {}".format(modifier_key)) + _LOGGER.debug(f"Checking existence of modifier: {modifier_key}") if CONFIG_KEY not in self or SAMPLE_MODS_KEY not in self[CONFIG_KEY]: return False if ( From 75c548a97ea13b7278a6270318d2652efa9ecda8 Mon Sep 17 00:00:00 2001 From: Khoroshevskyi Date: Tue, 18 Jul 2023 23:57:12 -0400 Subject: [PATCH 5/6] fixed #452 --- peppy/project.py | 30 +++++++++++++++++++++--------- tests/test_Project.py | 4 +++- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/peppy/project.py b/peppy/project.py index 9e213641..f98b1d83 100644 --- a/peppy/project.py +++ b/peppy/project.py @@ -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 @@ -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 @@ -336,14 +338,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 @@ -398,6 +393,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 diff --git a/tests/test_Project.py b/tests/test_Project.py index 85a1c488..751c4ef9 100644 --- a/tests/test_Project.py +++ b/tests/test_Project.py @@ -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): From 5997971a0a8c6fba7ede8bc4341e770827218834 Mon Sep 17 00:00:00 2001 From: Khoroshevskyi Date: Wed, 19 Jul 2023 00:07:25 -0400 Subject: [PATCH 6/6] updated version --- docs/changelog.md | 5 +++++ peppy/_version.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index 3ecc3822..1351854c 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -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 diff --git a/peppy/_version.py b/peppy/_version.py index a51f1e97..c83377ec 100644 --- a/peppy/_version.py +++ b/peppy/_version.py @@ -1 +1 @@ -__version__ = "0.35.6" +__version__ = "0.35.7"