Skip to content

Commit 7de69ae

Browse files
JochenSiegWorkc-w-feldmann
authored andcommitted
rdkit_phys_chem: raise when an empty descriptor list is provided (#160)
1 parent c943c0a commit 7de69ae

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

molpipeline/mol2any/mol2rdkit_phys_chem.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,16 @@ def descriptor_list(self, descriptor_list: list[str] | None) -> None:
105105
------
106106
ValueError
107107
If an unknown descriptor name is used.
108+
ValueError
109+
If an empty descriptor_list is used.
108110
"""
109111
if descriptor_list is None or descriptor_list is DEFAULT_DESCRIPTORS:
110112
# if None or DEFAULT_DESCRIPTORS are used, set the default descriptors
111113
self._descriptor_list = DEFAULT_DESCRIPTORS
114+
elif len(descriptor_list) == 0:
115+
raise ValueError(
116+
"Empty descriptor_list is not allowed. Use None for default descriptors."
117+
)
112118
else:
113119
# check all user defined descriptors are valid
114120
for descriptor_name in descriptor_list:

tests/test_elements/test_mol2any/test_mol2rdkit_phys_chem.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,14 @@ def test_exception_handling(self) -> None:
403403
output = pipeline.fit_transform(["[HH]"])
404404
self.assertTrue(output.shape == (1, len(DEFAULT_DESCRIPTORS)))
405405

406+
def test_empty_descriptor_list(self) -> None:
407+
"""Test that an empty descriptor list raises ValueError."""
408+
with self.assertRaises(ValueError) as context:
409+
MolToRDKitPhysChem(descriptor_list=[])
410+
self.assertTrue(
411+
str(context.exception).startswith("Empty descriptor_list is not allowed")
412+
)
413+
406414

407415
if __name__ == "__main__":
408416
unittest.main()

0 commit comments

Comments
 (0)