diff --git a/CHANGELOG.md b/CHANGELOG.md index 68012821d79409d3a8b7eb1ef4c53094d30f6c28..9eb927fd561912a1a31a2c4083570232281b4adf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed ### +* `TableImporter.check_missing` in case of array-valued fields in table + ### Security ### ### Documentation ### diff --git a/src/caosadvancedtools/table_importer.py b/src/caosadvancedtools/table_importer.py index 8f793584051386796bce18bdbaded6c7e34c06ca..3d77e36db4d031657e43589e540edec28fd09633 100755 --- a/src/caosadvancedtools/table_importer.py +++ b/src/caosadvancedtools/table_importer.py @@ -388,7 +388,8 @@ class TableImporter(): if key not in df.columns: continue - if pd.isnull(row.loc[key]): + null_check = pd.isnull(row.loc[key]) + if (isinstance(null_check, np.ndarray) and null_check.any()) or (not isinstance(null_check, np.ndarray) and null_check): errmsg = ( "Required information is missing ({}) in {}. row" " (without header) of " diff --git a/unittests/test_table_importer.py b/unittests/test_table_importer.py index 0b3f0d7c7fc81b2a9d64e24fb2262c686ea669da..dd5b7af712e341683f6bcbd36b67653beebe1673 100644 --- a/unittests/test_table_importer.py +++ b/unittests/test_table_importer.py @@ -181,6 +181,15 @@ class TableImporterTest(unittest.TestCase): self.assertEqual(df_new.shape[1], 4) self.assertEqual(df_new.iloc[0].b, 5) + # check that missing array-valued fields are detected correctly: + df = pd.DataFrame([[[None, None], 4, 2.0, 'yes'], + ['b', 5, 3.0, 'no']], + columns=['a', 'b', 'c', 'd']) + df_new = importer.check_missing(df) + self.assertEqual(df_new.shape[0], 1) + self.assertEqual(df_new.shape[1], 4) + self.assertEqual(df_new.iloc[0].b, 5) + def test_wrong_datatype(self): importer = TableImporter(**self.importer_kwargs) df = pd.DataFrame([[None, np.nan, 2.0, 'yes'],