Skip to content

Commit 289fdec

Browse files
committed
remove copy method
1 parent a2ff8eb commit 289fdec

File tree

4 files changed

+10
-24
lines changed

4 files changed

+10
-24
lines changed

molpipeline/abstract_pipeline_elements/core.py

+1-18
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from joblib import Parallel, delayed
1919
from loguru import logger
2020
from rdkit import Chem
21-
from rdkit.Chem import Mol as RDKitMol # pylint: disable=no-name-in-module
21+
from rdkit.Chem import Mol as RDKitMol
2222

2323
from molpipeline.utils.multi_proc import check_available_cores
2424

@@ -393,23 +393,6 @@ def parameters(self, **parameters: Any) -> None:
393393
"""
394394
self.set_params(**parameters)
395395

396-
def copy(self) -> Self:
397-
"""Copy the object.
398-
399-
Returns
400-
-------
401-
Self
402-
Copy of the object.
403-
"""
404-
recreated_object = self.__class__(**self.parameters)
405-
for key, value in self.additional_attributes.items():
406-
if not hasattr(recreated_object, key):
407-
raise AssertionError(
408-
f"Cannot set attribute {key} on {self.__class__.__name__}. This should not happen!"
409-
)
410-
setattr(recreated_object, key, copy.copy(value))
411-
return recreated_object
412-
413396
def fit_to_result(self, values: Any) -> Self:
414397
"""Fit object to result of transformed values.
415398

tests/test_elements/test_mol2any/test_mol2maccs_key_fingerprint.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import Any
77

88
import numpy as np
9+
from sklearn.base import clone
910

1011
from molpipeline import Pipeline
1112
from molpipeline.any2mol import SmilesToMol
@@ -32,7 +33,7 @@ def test_can_be_constructed(self) -> None:
3233
None
3334
"""
3435
mol_fp = MolToMACCSFP()
35-
mol_fp_copy = mol_fp.copy()
36+
mol_fp_copy = clone(mol_fp)
3637
self.assertTrue(mol_fp_copy is not mol_fp)
3738
for key, value in mol_fp.get_params().items():
3839
self.assertEqual(value, mol_fp_copy.get_params()[key])

tests/test_elements/test_mol2any/test_mol2morgan_fingerprint.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import Any
77

88
import numpy as np
9+
from sklearn.base import clone
910

1011
from molpipeline import Pipeline
1112
from molpipeline.any2mol import SmilesToMol
@@ -22,15 +23,15 @@
2223
class TestMol2MorganFingerprint(unittest.TestCase):
2324
"""Unittest for MolToFoldedMorganFingerprint, which calculates folded Morgan Fingerprints."""
2425

25-
def test_can_be_constructed(self) -> None:
26+
def test_clone(self) -> None:
2627
"""Test if the MolToFoldedMorganFingerprint pipeline element can be constructed.
2728
2829
Returns
2930
-------
3031
None
3132
"""
3233
mol_fp = MolToMorganFP()
33-
mol_fp_copy = mol_fp.copy()
34+
mol_fp_copy = clone(mol_fp)
3435
self.assertTrue(mol_fp_copy is not mol_fp)
3536
for key, value in mol_fp.get_params().items():
3637
self.assertEqual(value, mol_fp_copy.get_params()[key])

tests/test_elements/test_mol2any/test_mol2path_fingerprint.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import Any
77

88
import numpy as np
9+
from sklearn.base import clone
910

1011
from molpipeline import Pipeline
1112
from molpipeline.any2mol import SmilesToMol
@@ -23,15 +24,15 @@
2324
class TestMol2PathFingerprint(unittest.TestCase):
2425
"""Unittest for Mol2PathFP, which calculates the RDKit Path Fingerprint."""
2526

26-
def test_can_be_constructed(self) -> None:
27-
"""Test if the Mol2PathFP pipeline element can be constructed.
27+
def test_clone(self) -> None:
28+
"""Test if the Mol2PathFP pipeline element can be cloned.
2829
2930
Returns
3031
-------
3132
None
3233
"""
3334
mol_fp = Mol2PathFP()
34-
mol_fp_copy = mol_fp.copy()
35+
mol_fp_copy = clone(mol_fp)
3536
self.assertTrue(mol_fp_copy is not mol_fp)
3637
for key, value in mol_fp.get_params().items():
3738
self.assertEqual(value, mol_fp_copy.get_params()[key])

0 commit comments

Comments
 (0)