Skip to content

Commit 75eb7e4

Browse files
authored
130 add fix attribute output type (#131)
* make output type dynamic * add output type * remove Useless suppression of 'invalid-name' (65:0) [useless-suppression] * Add unit tests
1 parent 37a8029 commit 75eb7e4

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

molpipeline/abstract_pipeline_elements/mol2any/mol2bitvector.py

+7
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,13 @@ def set_params(self, **parameters: Any) -> Self:
330330
class ABCMorganFingerprintPipelineElement(MolToRDKitGenFPElement, abc.ABC):
331331
"""Abstract Class for Morgan fingerprints."""
332332

333+
@property
334+
def output_type(self) -> str:
335+
"""Get output type."""
336+
if self.counted:
337+
return "integer"
338+
return "binary"
339+
333340
# pylint: disable=R0913
334341
def __init__(
335342
self,

molpipeline/estimators/chemprop/neural_fingerprint.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@
1212

1313

1414
class ChempropNeuralFP(ABCChemprop):
15-
"""Wrap Chemprop in a sklearn like transformer returning the neural fingerprint as a numpy array."""
15+
"""Wrap Chemprop in a sklearn like transformer returning the neural fingerprint as a numpy array.
16+
17+
This class is not a (grand-) child of MolToAnyPipelineElement, as it does not support the `pretransform_single`
18+
method. To maintain compatibility with the MolToAnyPipelineElement, the `output_type` property is implemented.
19+
It can be used as any other transformer in the pipeline, except in the `MolToConcatenatedVector`.
20+
"""
21+
22+
@property
23+
def output_type(self) -> str:
24+
"""Return the output type of the transformer."""
25+
return "float"
1626

1727
def __init__(
1828
self,
@@ -52,7 +62,7 @@ def __init__(
5262

5363
def fit(
5464
self,
55-
X: MoleculeDataset, # pylint: disable=invalid-name
65+
X: MoleculeDataset,
5666
y: Sequence[int | float] | npt.NDArray[np.int_ | np.float64],
5767
) -> Self:
5868
"""Fit the model.

test_extras/test_chemprop/test_neural_fingerprint.py

+5
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ def test_json_serialization(self) -> None:
3333
chemprop_json = recursive_to_json(chemprop_fp_encoder)
3434
chemprop_encoder_copy = recursive_from_json(chemprop_json)
3535
compare_params(self, chemprop_fp_encoder, chemprop_encoder_copy)
36+
37+
def test_output_type(self) -> None:
38+
"""Test the output type."""
39+
chemprop_fp_encoder = get_neural_fp_encoder()
40+
self.assertEqual(chemprop_fp_encoder.output_type, "float")

tests/test_elements/test_mol2any/test_mol2morgan_fingerprint.py

+7
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ def test_counted_bits(self) -> None:
6363
self.assertTrue(np.any(output_counted > output_binary))
6464

6565
def test_output_types(self) -> None:
66+
"""Test if the output types are correct for counted and binary fingerprints."""
67+
mol_fp = MolToMorganFP(counted=False)
68+
self.assertEqual(mol_fp.output_type, "binary")
69+
mol_fp = MolToMorganFP(counted=True)
70+
self.assertEqual(mol_fp.output_type, "integer")
71+
72+
def test_return_value_types(self) -> None:
6673
"""Test equality of different output_types."""
6774

6875
smi2mol = SmilesToMol()

0 commit comments

Comments
 (0)