Skip to content

Commit f451271

Browse files
committed
Fix docstrings (#159)
Adapt docstrings to ruff format
1 parent 7de69ae commit f451271

File tree

58 files changed

+819
-310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+819
-310
lines changed

molpipeline/abstract_pipeline_elements/core.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ def __init__(self, filter_element_id: str, message: str | None = None) -> None:
7171
message: str | None, optional
7272
Optional message why the molecule was removed.
7373
74-
Returns
75-
-------
76-
None
7774
"""
7875
self.filter_element_id = filter_element_id
7976
self.message = message
@@ -193,10 +190,16 @@ def set_params(self, **parameters: Any) -> Self:
193190
parameters: Any
194191
Parameters to be set.
195192
193+
Raises
194+
------
195+
ValueError
196+
If the parameter is not a valid parameter of the object.
197+
196198
Returns
197199
-------
198200
Self
199201
Self with updated parameters.
202+
200203
"""
201204
for att_name, att_value in parameters.items():
202205
if not hasattr(self, att_name):
@@ -225,9 +228,6 @@ def n_jobs(self, n_jobs: int) -> None:
225228
n_jobs: int
226229
Number of cores used for processing.
227230
228-
Returns
229-
-------
230-
None
231231
"""
232232
self._n_jobs = check_available_cores(n_jobs)
233233

@@ -388,19 +388,22 @@ def parameters(self, **parameters: Any) -> None:
388388
parameters: Any
389389
Object parameters as a dictionary.
390390
391-
Returns
392-
-------
393-
None
394391
"""
395392
self.set_params(**parameters)
396393

397394
def copy(self) -> Self:
398395
"""Copy the object.
399396
397+
Raises
398+
------
399+
AssertionError
400+
If the object cannot be copied.
401+
400402
Returns
401403
-------
402404
Self
403405
Copy of the object.
406+
404407
"""
405408
recreated_object = self.__class__(**self.parameters)
406409
for key, value in self.additional_attributes.items():

molpipeline/abstract_pipeline_elements/mol2any/mol2bitvector.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,24 @@ def set_params(self, **parameters: Any) -> Self:
155155
parameters: Any
156156
Dictionary of parameter names and values.
157157
158+
Raises
159+
------
160+
ValueError
161+
If return_as is not one of the allowed values.
162+
158163
Returns
159164
-------
160165
Self
161166
Copied object with updated parameters.
167+
162168
"""
163169
parameter_dict_copy = dict(parameters)
164170
return_as = parameter_dict_copy.pop("return_as", None)
165171
if return_as is not None:
166172
if return_as not in get_args(OutputDatatype):
167173
raise ValueError(
168-
f"return_as has to be one of {get_args(OutputDatatype)}! (Received: {return_as})"
174+
f"return_as has to be one of {get_args(OutputDatatype)}! "
175+
f"(Received: {return_as})"
169176
)
170177
self._return_as = return_as
171178
super().set_params(**parameter_dict_copy)
@@ -373,6 +380,12 @@ def __init__(
373380
Number of jobs.
374381
uuid: str | None, optional
375382
Unique identifier.
383+
384+
Raises
385+
------
386+
ValueError
387+
If radius is not a positive integer.
388+
376389
"""
377390
# pylint: disable=R0801
378391
super().__init__(

molpipeline/abstract_pipeline_elements/mol2mol/filter.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,16 @@ def pretransform_single( # pylint: disable=too-many-return-statements
187187
value: RDKitMol
188188
Molecule to check.
189189
190+
Raises
191+
------
192+
ValueError
193+
If the mode is not "any" or "all".
194+
190195
Returns
191196
-------
192197
OptionalMol
193198
Molecule that matches defined filter elements, else InvalidInstance.
199+
194200
"""
195201
for filter_element, (lower_limit, upper_limit) in self.filter_elements.items():
196202
property_value = self._calculate_single_element_value(filter_element, value)
@@ -318,6 +324,12 @@ def patterns_mol_dict(self, patterns: Sequence[str]) -> None:
318324
----------
319325
patterns: Sequence[str]
320326
List of patterns.
327+
328+
Raises
329+
------
330+
ValueError
331+
If the patterns are not valid SMILES or SMARTS.
332+
321333
"""
322334
self._patterns_mol_dict = {pat: self._pattern_to_mol(pat) for pat in patterns}
323335
failed_patterns = [

molpipeline/error_handling.py

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def __init__(
5858
uuid: str | None, optional
5959
UUID of the pipeline element.
6060
61+
Raises
62+
------
63+
ValueError
64+
If element_ids is None and filter_everything is False.
65+
6166
"""
6267
super().__init__(name=name, n_jobs=n_jobs, uuid=uuid)
6368
self.error_indices = []
@@ -134,10 +139,16 @@ def set_params(self, **parameters: Any) -> Self:
134139
parameters: Any
135140
Dict of arameters to set.
136141
142+
Raises
143+
------
144+
TypeError
145+
If element_ids is not a set.
146+
137147
Returns
138148
-------
139149
Self
140150
Self with updated parameters.
151+
141152
"""
142153
param_copy = dict(parameters)
143154
if "element_ids" in param_copy:
@@ -221,10 +232,18 @@ def co_transform(self, values: TypeFixedVarSeq) -> TypeFixedVarSeq:
221232
values: TypeFixedVarSeq
222233
Values to be transformed.
223234
235+
Raises
236+
------
237+
ValueError
238+
If the length of the values does not match the length of the values in fit.
239+
TypeError
240+
If the type of values is not a list or numpy array.
241+
224242
Returns
225243
-------
226244
TypeFixedVarSeq
227245
Input where rows are removed.
246+
228247
"""
229248
if self.n_total != len(values):
230249
raise ValueError("Length of values does not match length of values in fit")
@@ -375,6 +394,14 @@ def register_removed(self, index: int, value: RemovedInstance) -> None:
375394
Index of the invalid instance.
376395
value: Any
377396
Value of the invalid instance.
397+
398+
Raises
399+
------
400+
TypeError
401+
If value is not a RemovedInstance.
402+
ValueError
403+
If value is not captured by any ErrorFilter.
404+
378405
"""
379406
if not isinstance(value, RemovedInstance):
380407
raise TypeError(f"Unexpected Type: {type(value)}")
@@ -399,9 +426,6 @@ def set_total(self, total: int) -> None:
399426
total: int
400427
Total number of instances seen during transformation.
401428
402-
Returns
403-
-------
404-
None
405429
"""
406430
for error_filter in self.error_filter_list:
407431
error_filter.n_total = total
@@ -531,7 +555,14 @@ def set_params(self, **parameters: Any) -> Self:
531555

532556
@property
533557
def error_filter(self) -> ErrorFilter:
534-
"""Get the ErrorFilter connected to this FilterReinserter."""
558+
"""Get the ErrorFilter connected to this FilterReinserter.
559+
560+
Raises
561+
------
562+
ValueError
563+
If the ErrorFilter is not set.
564+
565+
"""
535566
if self._error_filter is None:
536567
raise ValueError("ErrorFilter not set")
537568
return self._error_filter
@@ -555,10 +586,16 @@ def select_error_filter(self, error_filter_list: list[ErrorFilter]) -> Self:
555586
error_filter_list: list[ErrorFilter]
556587
List of ErrorFilters to select from.
557588
589+
Raises
590+
------
591+
ValueError
592+
If the ErrorFilter with the given id is not found in the list.
593+
558594
Returns
559595
-------
560596
Self
561597
FilterReinserter with updated ErrorFilter.
598+
562599
"""
563600
for error_filter in error_filter_list:
564601
if error_filter.uuid == self.error_filter_id:
@@ -674,10 +711,16 @@ def transform(
674711
**params: Any
675712
Additional keyword arguments.
676713
714+
Raises
715+
------
716+
ValueError
717+
If the length of the values does not match the length of the values in fit.
718+
677719
Returns
678720
-------
679721
TypeFixedVarSeq
680722
Iterable where invalid instances were removed.
723+
681724
"""
682725
if len(values) != self.error_filter.n_total - len(
683726
self.error_filter.error_indices
@@ -696,10 +739,17 @@ def _fill_list(self, list_to_fill: Sequence[_S]) -> Sequence[_S | _T]:
696739
list_to_fill: list[Number]
697740
List to fill with dummy values.
698741
742+
Raises
743+
------
744+
AssertionError
745+
If the length of the list does not match the expected length.
746+
699747
Returns
700748
-------
701749
list[Number]
702-
List where dummy values were inserted to replace instances which could not be processed.
750+
List where dummy values were inserted to replace instances which could not
751+
be processed.
752+
703753
"""
704754
filled_list: list[_S | _T] = []
705755
next_value_pos = 0
@@ -710,7 +760,9 @@ def _fill_list(self, list_to_fill: Sequence[_S]) -> Sequence[_S | _T]:
710760
filled_list.append(list_to_fill[next_value_pos])
711761
next_value_pos += 1
712762
if len(list_to_fill) != next_value_pos:
713-
raise AssertionError()
763+
raise AssertionError(
764+
"Length of list does not match length of values in fit"
765+
)
714766
return filled_list
715767

716768
def _fill_numpy_arr(self, value_array: npt.NDArray[Any]) -> npt.NDArray[Any]:
@@ -753,10 +805,16 @@ def fill_with_dummy(
753805
value_container: TypeFixedVarSeq
754806
Iterable to fill with dummy values.
755807
808+
Raises
809+
------
810+
TypeError
811+
If value_container is not a list or numpy array.
812+
756813
Returns
757814
-------
758815
AnyVarSeq
759816
Iterable where dummy values were inserted to replace molecules which could not be processed.
817+
760818
"""
761819
if isinstance(value_container, list):
762820
return self._fill_list(value_container) # type: ignore

0 commit comments

Comments
 (0)