Skip to content

Commit b75ece3

Browse files
authored
maint: black -> ruff (#251)
Instead of black and isort, run ruff as pre-commit hook. Enable pyupgrade and additional rules. Applied safe auto-fixes, but validation currently fails. Will be addressed in a follow-up PR (#252). Relevant changes: `.pre-commit-config.yaml`, `pyproject.toml`
1 parent a5e771e commit b75ece3

33 files changed

+103
-136
lines changed

.pre-commit-config.yaml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
4-
- repo: https://github.com/pycqa/isort
5-
rev: 5.12.0
6-
hooks:
7-
- id: isort
8-
name: isort (python)
9-
args: ["--profile", "black", "--filter-files", "--line-length", "79"]
104
- repo: https://github.com/pre-commit/pre-commit-hooks
115
rev: v4.4.0
126
hooks:
@@ -16,13 +10,19 @@ repos:
1610
args: [--allow-multiple-documents]
1711
- id: end-of-file-fixer
1812
- id: trailing-whitespace
19-
- repo: https://github.com/psf/black
20-
rev: 23.7.0
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
# Ruff version.
15+
rev: v0.1.11
2116
hooks:
22-
- id: black-jupyter
23-
# It is recommended to specify the latest version of Python
24-
# supported by your project here, or alternatively use
25-
# pre-commit's default_language_version, see
26-
# https://pre-commit.com/#top_level-default_language_version
27-
language_version: python3.11
28-
args: ["--line-length", "79"]
17+
# Run the linter.
18+
- id: ruff
19+
args:
20+
- --fix
21+
- --config
22+
- pyproject.toml
23+
24+
# Run the formatter.
25+
- id: ruff-format
26+
args:
27+
- --config
28+
- pyproject.toml

petab/calculate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ def calculate_llh_for_table(
322322
parameter_df: pd.DataFrame,
323323
) -> float:
324324
"""Calculate log-likelihood for one set of tables. For the arguments, see
325-
`calculate_llh`."""
325+
`calculate_llh`.
326+
"""
326327
llhs = []
327328

328329
# matching columns

petab/composite_problem.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def from_yaml(yaml_config: Union[Dict, str]) -> "CompositeProblem":
4646
Arguments:
4747
yaml_config: PEtab configuration as dictionary or YAML file name
4848
"""
49-
5049
if isinstance(yaml_config, str):
5150
path_prefix = os.path.dirname(yaml_config)
5251
yaml_config = yaml.load_yaml(yaml_config)

petab/conditions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
def get_condition_df(
21-
condition_file: Union[str, pd.DataFrame, Path, None]
21+
condition_file: Union[str, pd.DataFrame, Path, None],
2222
) -> pd.DataFrame:
2323
"""Read the provided condition file into a ``pandas.Dataframe``
2424
@@ -75,7 +75,6 @@ def create_condition_df(
7575
A :py:class:`pandas.DataFrame` with empty given rows and columns and
7676
all nan values
7777
"""
78-
7978
condition_ids = [] if condition_ids is None else list(condition_ids)
8079

8180
data = {CONDITION_ID: condition_ids}

petab/core.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def write_simulation_df(df: pd.DataFrame, filename: Union[str, Path]) -> None:
7272

7373

7474
def get_visualization_df(
75-
visualization_file: Union[str, Path, pd.DataFrame, None]
75+
visualization_file: Union[str, Path, pd.DataFrame, None],
7676
) -> Union[pd.DataFrame, None]:
7777
"""Read PEtab visualization table
7878
@@ -357,7 +357,6 @@ def concat_tables(
357357
Returns:
358358
The concatenated DataFrames
359359
"""
360-
361360
if isinstance(tables, pd.DataFrame):
362361
return tables
363362

@@ -389,7 +388,6 @@ def to_float_if_float(x: Any) -> Any:
389388
Returns:
390389
``x`` as float if possible, otherwise ``x``
391390
"""
392-
393391
try:
394392
return float(x)
395393
except (ValueError, TypeError):
@@ -427,7 +425,6 @@ def create_combine_archive(
427425
email: E-mail address of archive creator
428426
organization: Organization of archive creator
429427
"""
430-
431428
path_prefix = os.path.dirname(str(yaml_file))
432429
yaml_config = yaml.load_yaml(yaml_file)
433430

petab/lint.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ def check_condition_df(
105105
Raises:
106106
AssertionError: in case of problems
107107
"""
108-
109108
# Check required columns are present
110109
req_cols = []
111110
_check_df(df, req_cols, "condition")
@@ -167,7 +166,6 @@ def check_measurement_df(
167166
Raises:
168167
AssertionError, ValueError: in case of problems
169168
"""
170-
171169
_check_df(df, MEASUREMENT_DF_REQUIRED_COLS, "measurement")
172170

173171
for column_name in MEASUREMENT_DF_REQUIRED_COLS:
@@ -432,7 +430,6 @@ def assert_measured_observables_defined(
432430
Raises:
433431
AssertionError: in case of problems
434432
"""
435-
436433
used_observables = set(measurement_df[OBSERVABLE_ID].values)
437434
defined_observables = set(observable_df.index.values)
438435
if undefined_observables := (used_observables - defined_observables):
@@ -453,7 +450,6 @@ def condition_table_is_parameter_free(condition_df: pd.DataFrame) -> bool:
453450
``True`` if there are no parameter overrides in the condition table,
454451
``False`` otherwise.
455452
"""
456-
457453
return len(petab.get_parametric_overrides(condition_df)) == 0
458454

459455

@@ -468,7 +464,6 @@ def assert_parameter_id_is_string(parameter_df: pd.DataFrame) -> None:
468464
Raises:
469465
AssertionError: in case of problems
470466
"""
471-
472467
for parameter_id in parameter_df:
473468
if isinstance(parameter_id, str):
474469
if parameter_id[0].isdigit():
@@ -1088,7 +1083,6 @@ def assert_measurement_conditions_present_in_condition_table(
10881083
Raises:
10891084
AssertionError: in case of problems
10901085
"""
1091-
10921086
used_conditions = set(measurement_df[SIMULATION_CONDITION_ID].values)
10931087
if PREEQUILIBRATION_CONDITION_ID in measurement_df:
10941088
used_conditions |= set(

petab/mapping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
def get_mapping_df(
19-
mapping_file: Union[None, str, Path, pd.DataFrame]
19+
mapping_file: Union[None, str, Path, pd.DataFrame],
2020
) -> pd.DataFrame:
2121
"""
2222
Read the provided mapping file into a ``pandas.Dataframe``.

petab/measurements.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929

3030
def get_measurement_df(
31-
measurement_file: Union[None, str, Path, pd.DataFrame]
31+
measurement_file: Union[None, str, Path, pd.DataFrame],
3232
) -> pd.DataFrame:
3333
"""
3434
Read the provided measurement file into a ``pandas.Dataframe``.
@@ -217,7 +217,6 @@ def create_measurement_df() -> pd.DataFrame:
217217
Returns:
218218
Created DataFrame
219219
"""
220-
221220
return pd.DataFrame(
222221
data={
223222
OBSERVABLE_ID: [],

petab/models/model.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import abc
55
from pathlib import Path
6-
from typing import Any, Iterable, Tuple
6+
from typing import Any, Iterable
77

88

99
class Model(abc.ABC):
@@ -55,7 +55,7 @@ def get_parameter_value(self, id_: str) -> float:
5555
@abc.abstractmethod
5656
def get_free_parameter_ids_with_values(
5757
self,
58-
) -> Iterable[Tuple[str, float]]:
58+
) -> Iterable[tuple[str, float]]:
5959
"""Get free model parameters along with their values
6060
6161
Returns:
@@ -106,7 +106,6 @@ def symbol_allowed_in_observable_formula(self, id_: str) -> bool:
106106
107107
:returns: ``True``, if allowed, ``False`` otherwise
108108
"""
109-
110109
...
111110

112111
@abc.abstractmethod

petab/observables.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626
def get_observable_df(
27-
observable_file: Union[str, pd.DataFrame, Path, None]
27+
observable_file: Union[str, pd.DataFrame, Path, None],
2828
) -> Union[pd.DataFrame, None]:
2929
"""
3030
Read the provided observable file into a ``pandas.Dataframe``.
@@ -191,7 +191,6 @@ def get_placeholders(
191191
List of placeholder parameters from observable table observableFormulas
192192
and noiseFormulas.
193193
"""
194-
195194
# collect placeholder parameters overwritten by
196195
# {observable,noise}Parameters
197196
placeholder_types = []
@@ -224,5 +223,4 @@ def create_observable_df() -> pd.DataFrame:
224223
Returns:
225224
Created DataFrame
226225
"""
227-
228226
return pd.DataFrame(data={col: [] for col in OBSERVABLE_DF_COLS})

0 commit comments

Comments
 (0)