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

style: apply Black's 2025 style #498

Merged
merged 3 commits into from
Feb 2, 2025
Merged
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
24 changes: 12 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.8.0
rev: 25.1.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
- id: mypy
name: mypy with Python 3.12
files: src/cabinetry
additional_dependencies: ["numpy>=1.22", "boost-histogram>=1.0.1", "click>=8", "types-tabulate", "types-PyYAML", "hist>=2.3.0"]
args: ["--python-version=3.12"]
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v1.14.1
# hooks:
# - id: mypy
# name: mypy with Python 3.12
# files: src/cabinetry
# additional_dependencies: ["numpy>=1.22", "boost-histogram>=1.0.1", "click>=8", "types-tabulate", "types-PyYAML", "hist>=2.3.0"]
# args: ["--python-version=3.12"]
- repo: https://github.com/pycqa/flake8
rev: 7.1.1
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear, flake8-import-order, flake8-print]
- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
rev: v3.19.1
hooks:
- id: pyupgrade
args: ["--py38-plus"]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-added-large-files
args: ["--maxkb=100"]
Expand All @@ -34,7 +34,7 @@ repos:
# configuration duplicated in setup.cfg
args: ["--match=(?!setup|example).*\\.py'", "--match-dir='^(?!(tests|utils|docs)).*'", "--convention=google"]
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
rev: v2.4.1
hooks:
- id: codespell
args: ["-L", "hist", "src", "tests", "utils", "docs/*rst"]
8 changes: 4 additions & 4 deletions src/cabinetry/tabulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def _yields_per_bin(
_header_name(
channel_name, i_bin
): f"{model_yields[i_chan][i_sam][i_bin]:.2f} "
f"\u00B1 {total_stdev_model[i_chan][i_sam][i_bin]:.2f}"
f"\u00b1 {total_stdev_model[i_chan][i_sam][i_bin]:.2f}"
}
)
table.append(sample_dict)
Expand All @@ -140,7 +140,7 @@ def _yields_per_bin(
{
header_name: (
f"{total_model[i_bin]:.2f} "
f"\u00B1 {total_stdev_model[i_chan][-1][i_bin]:.2f}"
f"\u00b1 {total_stdev_model[i_chan][-1][i_bin]:.2f}"
)
}
)
Expand Down Expand Up @@ -188,7 +188,7 @@ def _yields_per_channel(
sample_dict.update(
{
channel_name: f"{model_yields[i_chan][i_sam]:.2f} "
f"\u00B1 {total_stdev_model[i_chan][i_sam]:.2f}"
f"\u00b1 {total_stdev_model[i_chan][i_sam]:.2f}"
}
)
table.append(sample_dict)
Expand All @@ -201,7 +201,7 @@ def _yields_per_channel(
total_dict.update(
{
channel_name: f"{total_model:.2f} "
f"\u00B1 {total_stdev_model[i_chan][-1]:.2f}"
f"\u00b1 {total_stdev_model[i_chan][-1]:.2f}"
}
)
data_dict.update({channel_name: f"{data[i_chan]:.2f}"})
Expand Down
62 changes: 31 additions & 31 deletions tests/test_tabulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def test__yields_per_bin(example_spec_multibin, example_spec_with_background, ca
assert yield_table == [
{
"sample": "Signal",
"region_1\nbin 1": "25.00 \u00B1 5.00",
"region_1\nbin 2": "5.00 \u00B1 2.00",
"region_2\nbin 1": "8.00 \u00B1 1.00",
"region_1\nbin 1": "25.00 \u00b1 5.00",
"region_1\nbin 2": "5.00 \u00b1 2.00",
"region_2\nbin 1": "8.00 \u00b1 1.00",
},
{
"sample": "total",
"region_1\nbin 1": "25.00 \u00B1 5.00",
"region_1\nbin 2": "5.00 \u00B1 2.00",
"region_2\nbin 1": "8.00 \u00B1 1.00",
"region_1\nbin 1": "25.00 \u00b1 5.00",
"region_1\nbin 2": "5.00 \u00b1 2.00",
"region_2\nbin 1": "8.00 \u00b1 1.00",
},
{
"sample": "data",
Expand All @@ -65,9 +65,9 @@ def test__yields_per_bin(example_spec_multibin, example_spec_with_background, ca
model, yields, total_stdev, data, channels, label
)
assert yield_table == [
{"sample": "Background", "Signal Region\nbin 1": "150.00 \u00B1 6.45"},
{"sample": "Signal", "Signal Region\nbin 1": "50.00 \u00B1 2.15"},
{"sample": "total", "Signal Region\nbin 1": "200.00 \u00B1 8.60"},
{"sample": "Background", "Signal Region\nbin 1": "150.00 \u00b1 6.45"},
{"sample": "Signal", "Signal Region\nbin 1": "50.00 \u00b1 2.15"},
{"sample": "total", "Signal Region\nbin 1": "200.00 \u00b1 8.60"},
{"sample": "data", "Signal Region\nbin 1": "160.00"},
]

Expand All @@ -77,18 +77,18 @@ def test__save_tables(tmp_path):
"yields_per_bin": [
{
"sample": "Background",
"Signal_region\nbin 1": "111.00 \u00B1 9.50",
"Signal_region\nbin 2": "116.00 \u00B1 10.00",
"Signal_region\nbin 1": "111.00 \u00b1 9.50",
"Signal_region\nbin 2": "116.00 \u00b1 10.00",
},
{
"sample": "Signal",
"Signal_region\nbin 1": "1.00 \u00B1 0.50",
"Signal_region\nbin 2": "5.00 \u00B1 1.00",
"Signal_region\nbin 1": "1.00 \u00b1 0.50",
"Signal_region\nbin 2": "5.00 \u00b1 1.00",
},
{
"sample": "total",
"Signal_region\nbin 1": "112.00 \u00B1 10.00",
"Signal_region\nbin 2": "121.00 \u00B1 11.00",
"Signal_region\nbin 1": "112.00 \u00b1 10.00",
"Signal_region\nbin 2": "121.00 \u00b1 11.00",
},
{
"sample": "data",
Expand All @@ -97,9 +97,9 @@ def test__save_tables(tmp_path):
},
],
"yields_per_channel": [
{"sample": "Background", "Signal_region": "227.00 \u00B1 16.00"},
{"sample": "Signal", "Signal_region": "6.00 \u00B1 1.00"},
{"sample": "total", "Signal_region": "233.00 \u00B1 17.00"},
{"sample": "Background", "Signal_region": "227.00 \u00b1 16.00"},
{"sample": "Signal", "Signal_region": "6.00 \u00b1 1.00"},
{"sample": "total", "Signal_region": "233.00 \u00b1 17.00"},
{"sample": "data", "Signal_region": "235.00"},
],
}
Expand All @@ -113,17 +113,17 @@ def test__save_tables(tmp_path):
"sample Signal_region Signal_region\n"
" bin 1 bin 2\n"
"---------- --------------- ---------------\n"
"Background 111.00 \u00B1 9.50 116.00 \u00B1 10.00\n"
"Signal 1.00 \u00B1 0.50 5.00 \u00B1 1.00\n"
"total 112.00 \u00B1 10.00 121.00 \u00B1 11.00\n"
"Background 111.00 \u00b1 9.50 116.00 \u00b1 10.00\n"
"Signal 1.00 \u00b1 0.50 5.00 \u00b1 1.00\n"
"total 112.00 \u00b1 10.00 121.00 \u00b1 11.00\n"
"data 112.00 123.00\n"
)
assert fname_channel.read_text() == (
"sample Signal_region\n"
"---------- ---------------\n"
"Background 227.00 \u00B1 16.00\n"
"Signal 6.00 \u00B1 1.00\n"
"total 233.00 \u00B1 17.00\n"
"Background 227.00 \u00b1 16.00\n"
"Signal 6.00 \u00b1 1.00\n"
"total 233.00 \u00b1 17.00\n"
"data 235.00\n"
)

Expand Down Expand Up @@ -159,13 +159,13 @@ def test__yields_per_channel(
assert yield_table == [
{
"sample": "Signal",
"region_1": "30.00 \u00B1 5.39",
"region_2": "8.00 \u00B1 1.00",
"region_1": "30.00 \u00b1 5.39",
"region_2": "8.00 \u00b1 1.00",
},
{
"sample": "total",
"region_1": "30.00 \u00B1 5.39",
"region_2": "8.00 \u00B1 1.00",
"region_1": "30.00 \u00b1 5.39",
"region_2": "8.00 \u00b1 1.00",
},
{"sample": "data", "region_1": "43.00", "region_2": "10.00"},
]
Expand All @@ -185,9 +185,9 @@ def test__yields_per_channel(
model, yields, total_stdev, data, channels, label
)
assert yield_table == [
{"sample": "Background", "Signal Region": "150.00 \u00B1 6.45"},
{"sample": "Signal", "Signal Region": "50.00 \u00B1 2.15"},
{"sample": "total", "Signal Region": "200.00 \u00B1 8.60"},
{"sample": "Background", "Signal Region": "150.00 \u00b1 6.45"},
{"sample": "Signal", "Signal Region": "50.00 \u00b1 2.15"},
{"sample": "total", "Signal Region": "200.00 \u00b1 8.60"},
{"sample": "data", "Signal Region": "160.00"},
]

Expand Down