From cda0fa31d4efea3a8fb54e35984c27e0487c0961 Mon Sep 17 00:00:00 2001 From: Sortofamudkip <wishyutp0328@gmail.com> Date: Thu, 13 Jul 2023 00:33:56 +0200 Subject: [PATCH] colname in columns test (get_sorted_column) --- src/Dataset.py | 3 +++ src/test_dataset.py | 1 + 2 files changed, 4 insertions(+) diff --git a/src/Dataset.py b/src/Dataset.py index a192474..0c73fc7 100644 --- a/src/Dataset.py +++ b/src/Dataset.py @@ -232,6 +232,9 @@ class Dataset: if type(colname) != str: logging.error("parameter `colname` is not a string") raise ValueError(f"{colname} is not a string") + if colname not in self.dataframe.columns: + logging.error("column requested not in dataframe") + raise KeyError(f"{colname} is not a column in dataframe") if not (ascending is None or type(ascending) is bool): logging.error("parameter `ascending` is not a bool or None") raise ValueError(f"{ascending} is not a bool or None") diff --git a/src/test_dataset.py b/src/test_dataset.py index be4d743..7e7331a 100644 --- a/src/test_dataset.py +++ b/src/test_dataset.py @@ -121,3 +121,4 @@ def test_catch_colname_not_in_df(the_dataset: Dataset): catch colnames not in dataset.""" with pytest.raises(KeyError): the_dataset.get_category_counts("GAAAD_T") + the_dataset.get_sorted_column("GAAAD_T") -- GitLab