Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump dev tools versions #503

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ ci:

repos:
- repo: https://github.com/pycqa/flake8
rev: 7.1.0
rev: 7.1.2
hooks:
- id: flake8
additional_dependencies: [pydoclint==0.5.5]
args: [--select=DOC, --config=pydoclint.toml]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.2
rev: v0.9.9
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.0
rev: v3.19.1
hooks:
- id: pyupgrade
args: [--py310-plus]
Expand Down
3 changes: 1 addition & 2 deletions baybe/constraints/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ def get_absolute_thresholds(self, bounds: Interval, /) -> Interval:
"""
if not bounds.contains(0.0):
raise ValueError(
f"The specified interval must contain zero. "
f"Given: {bounds.to_tuple()}."
f"The specified interval must contain zero. Given: {bounds.to_tuple()}."
)

return Interval(
Expand Down
3 changes: 1 addition & 2 deletions baybe/insights/shap.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,7 @@ def plot(

if plot_type not in SHAP_PLOTS:
raise ValueError(
f"Invalid plot type: '{plot_type}'. "
f"Available options: {SHAP_PLOTS}."
f"Invalid plot type: '{plot_type}'. Available options: {SHAP_PLOTS}."
)
plot_func = getattr(shap.plots, plot_type)

Expand Down
6 changes: 3 additions & 3 deletions baybe/parameters/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def get_parameters_from_dataframe(
# Try to find a parameter match for each dataframe column
parameters = []
for name, series in df.items():
assert isinstance(
name, str
), "The given dataframe must only contain string-valued column names."
assert isinstance(name, str), (
"The given dataframe must only contain string-valued column names."
)
unique_values = series.unique()

# If a match is found, assert that the values are in range
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 @@ -235,7 +235,7 @@ def _get_recommender_at_current_step(self) -> RecommenderProtocol:
return self.recommenders[idx]
except IndexError as ex:
raise NoRecommendersLeftError(
f"A total of {self._step+1} recommender(s) was/were requested but "
f"A total of {self._step + 1} recommender(s) was/were requested but "
f"the provided sequence contains only {self._step} element(s). "
f"Add more recommenders or adjust the "
f"'{fields(SequentialMetaRecommender).mode.name}' attribute."
Expand Down Expand Up @@ -292,8 +292,8 @@ def _get_recommender_at_current_step(self) -> RecommenderProtocol:
self._last_recommender = next(self._iterator)
except StopIteration as ex:
raise NoRecommendersLeftError(
f"A total of {self._step+1} recommender(s) was/were requested but "
f"the provided iterator provided only {self._step} element(s). "
f"A total of {self._step + 1} recommender(s) was/were requested "
f"but the provided iterator provided only {self._step} element(s). "
) from ex
self._position_of_latest_recommender = self._step

Expand Down
3 changes: 1 addition & 2 deletions baybe/simulation/_imputation.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ def _impute_lookup(
match_vals = np.array(vals)
else:
raise IndexError(
f"Cannot match the recommended row {row} to any of "
f"the rows in the lookup."
f"Cannot match the recommended row {row} to any of the rows in the lookup."
)

return match_vals
2 changes: 1 addition & 1 deletion examples/Constraints_Continuous/hybrid_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
for k in range(0, DIMENSION // 2)
] + [
NumericalContinuousParameter(
name=f"x_{k+1}",
name=f"x_{k + 1}",
bounds=(BOUNDS[0, k], BOUNDS[1, k]),
)
for k in range(DIMENSION // 2, DIMENSION)
Expand Down
2 changes: 1 addition & 1 deletion examples/Constraints_Continuous/linear_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

parameters = [
NumericalContinuousParameter(
name=f"x_{k+1}",
name=f"x_{k + 1}",
bounds=(BOUNDS[0, k], BOUNDS[1, k]),
)
for k in range(DIMENSION)
Expand Down
2 changes: 1 addition & 1 deletion examples/Constraints_Discrete/custom_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def custom_function(df: pd.DataFrame) -> pd.Series:

N_ITERATIONS = 3
for kIter in range(N_ITERATIONS):
print(f"\n\n#### ITERATION {kIter+1} ####")
print(f"\n\n#### ITERATION {kIter + 1} ####")

print("## ASSERTS ##")
print(
Expand Down
8 changes: 4 additions & 4 deletions examples/Constraints_Discrete/dependency_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,27 @@

N_ITERATIONS = 2 if SMOKE_TEST else 5
for kIter in range(N_ITERATIONS):
print(f"\n#### ITERATION {kIter+1} ####")
print(f"\n#### ITERATION {kIter + 1} ####")

print("## ASSERTS ##")
print(
f"Number entries with both switches on "
f"(expected {RESOLUTION*len(dict_solvent)*2*2}): ",
f"(expected {RESOLUTION * len(dict_solvent) * 2 * 2}): ",
(
(campaign.searchspace.discrete.exp_rep["Switch1"] == "on")
& (campaign.searchspace.discrete.exp_rep["Switch2"] == "right")
).sum(),
)
print(
f"Number entries with Switch1 off " f"(expected {2*2}): ",
f"Number entries with Switch1 off (expected {2 * 2}): ",
(
(campaign.searchspace.discrete.exp_rep["Switch1"] == "off")
& (campaign.searchspace.discrete.exp_rep["Switch2"] == "right")
).sum(),
)
print(
f"Number entries with Switch2 off "
f"(expected {RESOLUTION*len(dict_solvent)}):"
f"(expected {RESOLUTION * len(dict_solvent)}):"
f" ",
(
(campaign.searchspace.discrete.exp_rep["Switch1"] == "on")
Expand Down
2 changes: 1 addition & 1 deletion examples/Constraints_Discrete/exclusion_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@

N_ITERATIONS = 3
for kIter in range(N_ITERATIONS):
print(f"\n\n#### ITERATION {kIter+1} ####")
print(f"\n\n#### ITERATION {kIter + 1} ####")

print("## ASSERTS ##")
print(
Expand Down
2 changes: 1 addition & 1 deletion examples/Constraints_Discrete/prodsum_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@

N_ITERATIONS = 2 if SMOKE_TEST else 5
for kIter in range(N_ITERATIONS):
print(f"\n\n#### ITERATION {kIter+1} ####")
print(f"\n\n#### ITERATION {kIter + 1} ####")

print("## ASSERTS ##")
print(
Expand Down
4 changes: 2 additions & 2 deletions examples/Custom_Hooks/campaign_stopping.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def stop_on_PI(
n_pis_over_required = math.ceil(len(candidates_comp_rep) * PI_REQUIRED_FRACTION)
if n_pis_over < n_pis_over_required:
raise CampaignStoppedException(
f"Less than {PI_REQUIRED_FRACTION*100:.0f}% of candidates are above the PI "
f"threshold of {PI_THRESHOLD*100:.0f}% - Stopping the campaign."
f"Less than {PI_REQUIRED_FRACTION * 100:.0f}% of candidates are above the PI "
f"threshold of {PI_THRESHOLD * 100:.0f}% - Stopping the campaign."
)


Expand Down
2 changes: 1 addition & 1 deletion examples/Multi_Target/desirability.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
campaign.add_measurements(rec)
desirability = campaign.objective.transform(campaign.measurements, allow_extra=True)

print(f"\n\n#### ITERATION {kIter+1} ####")
print(f"\n\n#### ITERATION {kIter + 1} ####")
print("\nRecommended measurements with fake measured results:\n")
print(rec)
print("\nInternal measurement database with desirability values:\n")
Expand Down
2 changes: 1 addition & 1 deletion examples/Searchspaces/continuous_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
BOUNDS = (-1, 1)

parameters = [
NumericalContinuousParameter(name=f"x_{k+1}", bounds=BOUNDS)
NumericalContinuousParameter(name=f"x_{k + 1}", bounds=BOUNDS)
for k in range(DIMENSION)
]

Expand Down
2 changes: 1 addition & 1 deletion examples/Searchspaces/discrete_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

parameters = [
NumericalDiscreteParameter(
name=f"x_{k+1}",
name=f"x_{k + 1}",
values=list(np.linspace(BOUNDS[0, k], BOUNDS[1, k], POINTS_PER_DIM)),
tolerance=0.01,
)
Expand Down
4 changes: 2 additions & 2 deletions examples/Searchspaces/hybrid_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

cont_parameters = [
NumericalContinuousParameter(
name=f"x_{k+1}",
name=f"x_{k + 1}",
bounds=(BOUNDS[0, k], BOUNDS[1, k]),
)
for k in CONT_INDICES
Expand All @@ -91,7 +91,7 @@

disc_parameters = [
NumericalDiscreteParameter(
name=f"x_{k+1}",
name=f"x_{k + 1}",
values=list(np.linspace(BOUNDS[0, k], BOUNDS[1, k], POINTS_PER_DIM)),
tolerance=0.01,
)
Expand Down
2 changes: 1 addition & 1 deletion examples/Transfer_Learning/basic_transfer_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
campaign = Campaign(searchspace=searchspace, objective=objective)
initial_data = [lookup_training_task.sample(frac=p) for _ in range(N_MC_ITERATIONS)]
result_fraction = simulate_scenarios(
{f"{int(100*p)}": campaign},
{f"{int(100 * p)}": campaign},
lookup_test_task,
initial_data=initial_data,
batch_size=BATCH_SIZE,
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ examples = [
]

lint = [
"flake8==7.1.0", # see DEV TOOLS NOTE
"flake8==7.1.2", # see DEV TOOLS NOTE
"pre-commit==3.7.1", # see DEV TOOLS NOTE
"pydoclint==0.5.5", # see DEV TOOLS NOTE
"pyupgrade==3.19.0", # see DEV TOOLS NOTE
"ruff==0.5.2", # see DEV TOOLS NOTE
"pyupgrade==3.19.1", # see DEV TOOLS NOTE
"ruff==0.9.9", # see DEV TOOLS NOTE
]

mypy = [
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def fixture_parameters(
valid_parameters += [
*[
SubstanceParameter(
name=f"Solvent_{k+1}",
name=f"Solvent_{k + 1}",
data=mock_substances,
)
for k in range(3)
Expand All @@ -360,7 +360,7 @@ def fixture_parameters(
valid_parameters += [
*[
CategoricalParameter(
name=f"Solvent_{k+1}",
name=f"Solvent_{k + 1}",
values=tuple(mock_substances.keys()),
)
for k in range(3)
Expand Down
8 changes: 5 additions & 3 deletions tests/constraints/test_cardinality_constraint_continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_polytope_sampling_with_cardinality_constraint():
TOLERANCE = 1e-3

parameters = [
NumericalContinuousParameter(name=f"x_{i+1}", bounds=(0, 1))
NumericalContinuousParameter(name=f"x_{i + 1}", bounds=(0, 1))
for i in range(N_PARAMETERS)
]
params_equality = ["x_1", "x_2", "x_3", "x_4"]
Expand Down Expand Up @@ -191,7 +191,9 @@ def test_min_cardinality_warning():
upper_bound = 0.5
stepsize = 0.05
parameters = [
NumericalContinuousParameter(name=f"x_{i+1}", bounds=(lower_bound, upper_bound))
NumericalContinuousParameter(
name=f"x_{i + 1}", bounds=(lower_bound, upper_bound)
)
for i in range(N_PARAMETERS)
]

Expand Down Expand Up @@ -245,7 +247,7 @@ def test_empty_constraints_after_cardinality_constraint():
N_PARAMETERS = 2

parameters = [
NumericalContinuousParameter(name=f"x_{i+1}", bounds=(0, 1))
NumericalContinuousParameter(name=f"x_{i + 1}", bounds=(0, 1))
for i in range(N_PARAMETERS)
]
constraints = [
Expand Down
6 changes: 3 additions & 3 deletions tests/hypothesis_strategies/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def intervals(
exclude_fully_unbounded: bool = False,
):
"""Generate :class:`baybe.utils.interval.Interval`."""
assert not all(
(exclude_bounded, exclude_half_bounded, exclude_fully_unbounded)
), "At least one Interval type must be allowed."
assert not all((exclude_bounded, exclude_half_bounded, exclude_fully_unbounded)), (
"At least one Interval type must be allowed."
)

# Draw the interval type from the allowed types
type_gate = {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_input_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ def test_recommendation_is_not_ordered(n_values, n_parameters):
"""
# Set up custom df with entries monotonically increasing
values = list(range(n_values))
df = pd.DataFrame({f"p{k+1}": values for k in range(n_parameters)})
df = pd.DataFrame({f"p{k + 1}": values for k in range(n_parameters)})
searchspace = SearchSpace.from_dataframe(
df,
parameters=[
NumericalDiscreteParameter(name=f"p{k+1}", values=values)
NumericalDiscreteParameter(name=f"p{k + 1}", values=values)
for k in range(n_parameters)
],
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_meta_recommenders.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_sequential_meta_recommender(cls, mode):
# Selection with smaller training size raises an error
with pytest.raises(
RuntimeError,
match=f"decreased from {training_size} to {training_size-1}",
match=f"decreased from {training_size} to {training_size - 1}",
):
select_recommender(meta_recommender, training_size - 1)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_substance_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ def test_degenerate_comp_df():
}
p = SubstanceParameter(name="p", data=dict_base, encoding="RDKITFINGERPRINT")

assert (
not p.comp_df.duplicated().any()
), "A degenerate comp_df was not correctly treated."
assert not p.comp_df.duplicated().any(), (
"A degenerate comp_df was not correctly treated."
)
12 changes: 6 additions & 6 deletions tests/utils/test_augmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ def test_df_permutation_aug(content, col_groups, content_expected):
# Determine equality ignoring row order
are_equal = df_augmented.equals(df_expected)

assert (
are_equal
), f"\norig:\n{df}\n\naugmented:\n{df_augmented}\n\nexpected:\n{df_expected}"
assert are_equal, (
f"\norig:\n{df}\n\naugmented:\n{df_augmented}\n\nexpected:\n{df_expected}"
)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -299,6 +299,6 @@ def test_df_dependency_aug(content, causing, affected, content_expected):
# Determine equality ignoring row order
are_equal = df_augmented.equals(df_expected)

assert (
are_equal
), f"\norig:\n{df}\n\naugmented:\n{df_augmented}\n\nexpected:\n{df_expected}"
assert are_equal, (
f"\norig:\n{df}\n\naugmented:\n{df_augmented}\n\nexpected:\n{df_expected}"
)
12 changes: 6 additions & 6 deletions tests/utils/test_sampling_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ def test_discrete_sampling(fraction, method):
n_points = math.ceil(fraction * len(df))
sampled = sample_numerical_df(df, n_points, method=method)

assert (
len(sampled) == n_points
), "Sampling did not return expected number of points."
assert len(sampled) == n_points, (
"Sampling did not return expected number of points."
)
if fraction >= 1.0:
# Ensure the entire dataframe is contained in the sampled points
assert (
pd.merge(df, sampled, how="left", indicator=True)["_merge"].eq("both").all()
), "Oversized sampling did not return all original points at least once."
else:
# Assure all points are unique
assert len(sampled) == len(
sampled.drop_duplicates()
), "Undersized sampling did not return unique points."
assert len(sampled) == len(sampled.drop_duplicates()), (
"Undersized sampling did not return unique points."
)


@given(
Expand Down
Loading