Skip to content

Commit

Permalink
Remove no longer needed suppression of D102 linting rule
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianSosic committed Oct 15, 2024
1 parent a117d58 commit 16d2363
Show file tree
Hide file tree
Showing 27 changed files with 61 additions and 65 deletions.
4 changes: 0 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,6 @@ Apart from that, we generally recommend adhering to the following guideline:
* an optional extended summary or description below and
* all relevant sections (`Args`, `Raises`, ...).

Potential exceptions are functions whose docstring is to be fully inherited from a
parent class.
In this case, use `# noqa: D102` to disable the automatic checks locally.

- Use type hints (for variables/constants, attributes, function/method signatures, ...).
Avoid repeating type hints in docstrings.

Expand Down
10 changes: 5 additions & 5 deletions baybe/constraints/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def _make_operator_function(self):
return func

@override
def evaluate(self, data: pd.Series) -> pd.Series: # noqa: D102
def evaluate(self, data: pd.Series) -> pd.Series:
if data.dtype.kind not in "iufb":
raise ValueError(
"You tried to apply a threshold condition to non-numeric data. "
Expand All @@ -183,7 +183,7 @@ def evaluate(self, data: pd.Series) -> pd.Series: # noqa: D102
return data.apply(func)

@override
def to_polars(self, expr: pl.Expr, /) -> pl.Expr: # noqa: D102
def to_polars(self, expr: pl.Expr, /) -> pl.Expr:
op = self._make_operator_function()
return op(expr)

Expand All @@ -204,19 +204,19 @@ class SubSelectionCondition(Condition):
"""The internal list of items which are considered valid."""

@property
def selection(self) -> tuple: # noqa: D102
def selection(self) -> tuple:
"""The list of items which are considered valid."""
return tuple(
DTypeFloatNumpy(itm) if isinstance(itm, (float, int, bool)) else itm
for itm in self._selection
)

@override
def evaluate(self, data: pd.Series) -> pd.Series: # noqa: D102
def evaluate(self, data: pd.Series) -> pd.Series:
return data.isin(self.selection)

@override
def to_polars(self, expr: pl.Expr, /) -> pl.Expr: # noqa: D102
def to_polars(self, expr: pl.Expr, /) -> pl.Expr:
return expr.is_in(self.selection)


Expand Down
28 changes: 14 additions & 14 deletions baybe/constraints/discrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DiscreteExcludeConstraint(DiscreteConstraint):
"""Operator encoding how to combine the individual conditions."""

@override
def get_invalid(self, data: pd.DataFrame) -> pd.Index: # noqa: D102
def get_invalid(self, data: pd.DataFrame) -> pd.Index:
satisfied = [
cond.evaluate(data[self.parameters[k]])
for k, cond in enumerate(self.conditions)
Expand All @@ -51,7 +51,7 @@ def get_invalid(self, data: pd.DataFrame) -> pd.Index: # noqa: D102
return data.index[res]

@override
def get_invalid_polars(self) -> pl.Expr: # noqa: D102
def get_invalid_polars(self) -> pl.Expr:
from baybe._optional.polars import polars as pl

satisfied = []
Expand All @@ -78,14 +78,14 @@ class DiscreteSumConstraint(DiscreteConstraint):
"""The condition modeled by this constraint."""

@override
def get_invalid(self, data: pd.DataFrame) -> pd.Index: # noqa: D102
def get_invalid(self, data: pd.DataFrame) -> pd.Index:
evaluate_data = data[self.parameters].sum(axis=1)
mask_bad = ~self.condition.evaluate(evaluate_data)

return data.index[mask_bad]

@override
def get_invalid_polars(self) -> pl.Expr: # noqa: D102
def get_invalid_polars(self) -> pl.Expr:
from baybe._optional.polars import polars as pl

return self.condition.to_polars(pl.sum_horizontal(self.parameters)).not_()
Expand All @@ -106,14 +106,14 @@ class DiscreteProductConstraint(DiscreteConstraint):
"""The condition that is used for this constraint."""

@override
def get_invalid(self, data: pd.DataFrame) -> pd.Index: # noqa: D102
def get_invalid(self, data: pd.DataFrame) -> pd.Index:
evaluate_data = data[self.parameters].prod(axis=1)
mask_bad = ~self.condition.evaluate(evaluate_data)

return data.index[mask_bad]

@override
def get_invalid_polars(self) -> pl.Expr: # noqa: D102
def get_invalid_polars(self) -> pl.Expr:
from baybe._optional.polars import polars as pl

op = _threshold_operators[self.condition.operator]
Expand All @@ -140,13 +140,13 @@ class DiscreteNoLabelDuplicatesConstraint(DiscreteConstraint):
"""

@override
def get_invalid(self, data: pd.DataFrame) -> pd.Index: # noqa: D102
def get_invalid(self, data: pd.DataFrame) -> pd.Index:
mask_bad = data[self.parameters].nunique(axis=1) != len(self.parameters)

return data.index[mask_bad]

@override
def get_invalid_polars(self) -> pl.Expr: # noqa: D102
def get_invalid_polars(self) -> pl.Expr:
from baybe._optional.polars import polars as pl

expr = (
Expand All @@ -168,13 +168,13 @@ class DiscreteLinkedParametersConstraint(DiscreteConstraint):
"""

@override
def get_invalid(self, data: pd.DataFrame) -> pd.Index: # noqa: D102
def get_invalid(self, data: pd.DataFrame) -> pd.Index:
mask_bad = data[self.parameters].nunique(axis=1) != 1

return data.index[mask_bad]

@override
def get_invalid_polars(self) -> pl.Expr: # noqa: D102
def get_invalid_polars(self) -> pl.Expr:
from baybe._optional.polars import polars as pl

expr = (
Expand Down Expand Up @@ -229,7 +229,7 @@ def _validate_affected_parameters( # noqa: DOC101, DOC103
)

@override
def get_invalid(self, data: pd.DataFrame) -> pd.Index: # noqa: D102
def get_invalid(self, data: pd.DataFrame) -> pd.Index:
# Create data copy and mark entries where the dependency conditions are negative
# with a dummy value to cause degeneracy.
censored_data = data.copy()
Expand Down Expand Up @@ -295,7 +295,7 @@ class DiscretePermutationInvarianceConstraint(DiscreteConstraint):
"""Dependencies connected with the invariant parameters."""

@override
def get_invalid(self, data: pd.DataFrame) -> pd.Index: # noqa: D102
def get_invalid(self, data: pd.DataFrame) -> pd.Index:
# Get indices of entries with duplicate label entries. These will also be
# dropped by this constraint.
mask_duplicate_labels = pd.Series(False, index=data.index)
Expand Down Expand Up @@ -350,7 +350,7 @@ class DiscreteCustomConstraint(DiscreteConstraint):
you want to keep/remove."""

@override
def get_invalid(self, data: pd.DataFrame) -> pd.Index: # noqa: D102
def get_invalid(self, data: pd.DataFrame) -> pd.Index:
mask_bad = ~self.validator(data[self.parameters])

return data.index[mask_bad]
Expand All @@ -365,7 +365,7 @@ class DiscreteCardinalityConstraint(CardinalityConstraint, DiscreteConstraint):
# See base class.

@override
def get_invalid(self, data: pd.DataFrame) -> pd.Index: # noqa: D102
def get_invalid(self, data: pd.DataFrame) -> pd.Index:
non_zeros = (data[self.parameters] != 0.0).sum(axis=1)
mask_bad = non_zeros > self.max_cardinality
mask_bad |= non_zeros < self.min_cardinality
Expand Down
6 changes: 3 additions & 3 deletions baybe/kernels/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class LinearKernel(BasicKernel):
"""An optional initial value for the kernel variance parameter."""

@override
def to_gpytorch(self, *args, **kwargs): # noqa: D102
def to_gpytorch(self, *args, **kwargs):
import torch

from baybe.utils.torch import DTypeFloatTorch
Expand Down Expand Up @@ -98,7 +98,7 @@ class PeriodicKernel(BasicKernel):
"""An optional initial value for the kernel period length."""

@override
def to_gpytorch(self, *args, **kwargs): # noqa: D102
def to_gpytorch(self, *args, **kwargs):
import torch

from baybe.utils.torch import DTypeFloatTorch
Expand Down Expand Up @@ -153,7 +153,7 @@ class PolynomialKernel(BasicKernel):
"""An optional initial value for the kernel offset."""

@override
def to_gpytorch(self, *args, **kwargs): # noqa: D102
def to_gpytorch(self, *args, **kwargs):
import torch

from baybe.utils.torch import DTypeFloatTorch
Expand Down
6 changes: 3 additions & 3 deletions baybe/kernels/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ScaleKernel(CompositeKernel):
"""An optional initial value for the output scale."""

@override
def to_gpytorch(self, *args, **kwargs): # noqa: D102
def to_gpytorch(self, *args, **kwargs):
import torch

from baybe.utils.torch import DTypeFloatTorch
Expand All @@ -61,7 +61,7 @@ class AdditiveKernel(CompositeKernel):
"""The individual kernels to be summed."""

@override
def to_gpytorch(self, *args, **kwargs): # noqa: D102
def to_gpytorch(self, *args, **kwargs):
return reduce(add, (k.to_gpytorch(*args, **kwargs) for k in self.base_kernels))


Expand All @@ -78,7 +78,7 @@ class ProductKernel(CompositeKernel):
"""The individual kernels to be multiplied."""

@override
def to_gpytorch(self, *args, **kwargs): # noqa: D102
def to_gpytorch(self, *args, **kwargs):
return reduce(mul, (k.to_gpytorch(*args, **kwargs) for k in self.base_kernels))


Expand Down
4 changes: 2 additions & 2 deletions baybe/objectives/desirability.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _validate_weights(self, _, weights) -> None: # noqa: DOC101, DOC103

@override
@property
def targets(self) -> tuple[Target, ...]: # noqa: D102
def targets(self) -> tuple[Target, ...]:
return self._targets

@cached_property
Expand All @@ -140,7 +140,7 @@ def __str__(self) -> str:
return to_string("Objective", *fields)

@override
def transform(self, data: pd.DataFrame) -> pd.DataFrame: # noqa: D102
def transform(self, data: pd.DataFrame) -> pd.DataFrame:
# Transform all targets individually
transformed = data[[t.name for t in self.targets]].copy()
for target in self.targets:
Expand Down
4 changes: 2 additions & 2 deletions baybe/objectives/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def __str__(self) -> str:

@override
@property
def targets(self) -> tuple[Target, ...]: # noqa: D102
def targets(self) -> tuple[Target, ...]:
return (self._target,)

@override
def transform(self, data: pd.DataFrame) -> pd.DataFrame: # noqa: D102
def transform(self, data: pd.DataFrame) -> pd.DataFrame:
target_data = data[[self._target.name]].copy()
return self._target.transform(target_data)

Expand Down
6 changes: 3 additions & 3 deletions baybe/parameters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def comp_df(self) -> pd.DataFrame:

@override
@property
def comp_rep_columns(self) -> tuple[str, ...]: # noqa: D102
def comp_rep_columns(self) -> tuple[str, ...]:
return tuple(self.comp_df.columns)

def to_subspace(self) -> SubspaceDiscrete:
Expand All @@ -120,7 +120,7 @@ def to_subspace(self) -> SubspaceDiscrete:
return SubspaceDiscrete.from_parameter(self)

@override
def is_in_range(self, item: Any) -> bool: # noqa: D102
def is_in_range(self, item: Any) -> bool:
return item in self.values

def transform(self, series: pd.Series, /) -> pd.DataFrame:
Expand All @@ -147,7 +147,7 @@ def transform(self, series: pd.Series, /) -> pd.DataFrame:
return transformed

@override
def summary(self) -> dict: # noqa: D102
def summary(self) -> dict:
param_dict = dict(
Name=self.name,
Type=self.__class__.__name__,
Expand Down
2 changes: 1 addition & 1 deletion baybe/parameters/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def values(self) -> tuple:

@override
@cached_property
def comp_df(self) -> pd.DataFrame: # noqa: D102
def comp_df(self) -> pd.DataFrame:
if self.encoding is CategoricalEncoding.OHE:
cols = [f"{self.name}_{val}" for val in self.values]
comp_df = pd.DataFrame(
Expand Down
2 changes: 1 addition & 1 deletion baybe/parameters/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def values(self) -> tuple:

@override
@cached_property
def comp_df(self) -> pd.DataFrame: # noqa: D102
def comp_df(self) -> pd.DataFrame:
# The encoding is directly provided by the user
# We prepend the parameter name to the columns names to avoid potential
# conflicts with other parameters
Expand Down
12 changes: 6 additions & 6 deletions baybe/parameters/numerical.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ def _validate_tolerance( # noqa: DOC101, DOC103

@override
@property
def values(self) -> tuple: # noqa: D102
def values(self) -> tuple:
return tuple(DTypeFloatNumpy(itm) for itm in self._values)

@override
@cached_property
def comp_df(self) -> pd.DataFrame: # noqa: D102
def comp_df(self) -> pd.DataFrame:
comp_df = pd.DataFrame(
{self.name: self.values}, index=self.values, dtype=DTypeFloatNumpy
)
return comp_df

@override
def is_in_range(self, item: float) -> bool: # noqa: D102
def is_in_range(self, item: float) -> bool:
differences_acceptable = [
np.abs(val - item) <= self.tolerance for val in self.values
]
Expand Down Expand Up @@ -131,16 +131,16 @@ def _validate_bounds(self, _: Any, value: Interval) -> None: # noqa: DOC101, DO
)

@override
def is_in_range(self, item: float) -> bool: # noqa: D102
def is_in_range(self, item: float) -> bool:
return self.bounds.contains(item)

@override
@property
def comp_rep_columns(self) -> tuple[str, ...]: # noqa: D102
def comp_rep_columns(self) -> tuple[str, ...]:
return (self.name,)

@override
def summary(self) -> dict: # noqa: D102
def summary(self) -> dict:
param_dict = dict(
Name=self.name,
Type=self.__class__.__name__,
Expand Down
2 changes: 1 addition & 1 deletion baybe/parameters/substance.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def values(self) -> tuple:

@override
@cached_property
def comp_df(self) -> pd.DataFrame: # noqa: D102
def comp_df(self) -> pd.DataFrame:
from baybe.utils import chemistry

vals = list(self.data.values())
Expand Down
2 changes: 1 addition & 1 deletion baybe/priors/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class BetaPrior(Prior):
"""Beta concentration parameter. Controls mass accumulated toward one."""

@override
def to_gpytorch(self, *args, **kwargs): # noqa: D102
def to_gpytorch(self, *args, **kwargs):
raise NotImplementedError(
f"'{self.__class__.__name__}' does not have a gpytorch analog."
)
Expand Down
6 changes: 3 additions & 3 deletions baybe/recommenders/meta/sequential.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class TwoPhaseMetaRecommender(MetaRecommender):
requested batch."""

@override
def select_recommender( # noqa: D102
def select_recommender(
self,
batch_size: int,
searchspace: SearchSpace | None = None,
Expand Down Expand Up @@ -133,7 +133,7 @@ class SequentialMetaRecommender(MetaRecommender):
"""The number of measurements that were available at the last call."""

@override
def select_recommender( # noqa: D102
def select_recommender(
self,
batch_size: int,
searchspace: SearchSpace | None = None,
Expand Down Expand Up @@ -223,7 +223,7 @@ def default_iterator(self):
return iter(self.recommenders)

@override
def select_recommender( # noqa: D102
def select_recommender(
self,
batch_size: int,
searchspace: SearchSpace | None = None,
Expand Down
2 changes: 1 addition & 1 deletion baybe/recommenders/naive.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __attrs_post_init__(self):
)

@override
def recommend( # noqa: D102
def recommend(
self,
batch_size: int,
searchspace: SearchSpace,
Expand Down
Loading

0 comments on commit 16d2363

Please sign in to comment.