From 5b6cd1b004d871becf8b135384dc6cdd5fd652ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com> Date: Thu, 13 Apr 2023 10:40:33 +0200 Subject: [PATCH] MAINT: obligatory no longer forces columns to exist --- CHANGELOG.md | 3 ++- src/caosadvancedtools/table_importer.py | 4 ++-- unittests/test_table_importer.py | 4 ---- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52b2ce4e..c948dcd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### - TableImporter now accepts a `existing_columns` argument which demands that certain columns exist - although they may have missing values ### Changed ### - The converters and datatype arguments of TableImporter now may have keys for nonexisting columns +- The obligatory key word no longer enforces that the columns exist. Since all rows are still + checked whether this column has a non-NULL value, this is deemed a non breaking change. ### Deprecated ### diff --git a/src/caosadvancedtools/table_importer.py b/src/caosadvancedtools/table_importer.py index 4324bc8b..f38c3ffc 100755 --- a/src/caosadvancedtools/table_importer.py +++ b/src/caosadvancedtools/table_importer.py @@ -221,7 +221,7 @@ class TableImporter(): value check is not necessary. obligatory_columns : list, optional - List of column names, each listed column must exist and must not have missing values. + List of column names that must not have missing values. unique_keys : list, optional List of column names that in combination must be unique: each row has a unique @@ -272,7 +272,7 @@ class TableImporter(): """ - for col in self.obligatory_columns+self.existing_columns: + for col in self.existing_columns: if col not in df.columns: errmsg = "Column '{}' missing in ".format(col) errmsg += ("\n{}.\n".format(filename) if filename diff --git a/unittests/test_table_importer.py b/unittests/test_table_importer.py index a2d4b7c2..fc0eb043 100644 --- a/unittests/test_table_importer.py +++ b/unittests/test_table_importer.py @@ -153,10 +153,6 @@ class TableImporterTest(unittest.TestCase): [['a', 1, 2.0, 'yes', np.nan]], columns=['a', 'b', 'c', 'd', 'e']) def test_missing_col(self): - # check missing from obligatory - df = pd.DataFrame(columns=['a', 'e']) - importer = TableImporter(**self.importer_kwargs) - self.assertRaises(ValueError, importer.check_columns, df) # check missing from existing df = pd.DataFrame(columns=['a', 'b']) importer = TableImporter(**self.importer_kwargs) -- GitLab