Skip to content

Commit

Permalink
Updates (#105)
Browse files Browse the repository at this point in the history
* update to numpy2.0 and pandas2.0

* update pre commit hooks

* update to latest python version

* udpate gitignore

* updated version

* style: pre-commit fixes

* ignore some errors in ipynb files

* pdm updates

* added ruff --fix to pre-commit

* new pre-commit fixes

* change non-covered lines to new python version

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
The-Ludwig and pre-commit-ci[bot] authored Nov 19, 2024
1 parent e857b01 commit bf18268
Show file tree
Hide file tree
Showing 16 changed files with 285 additions and 222 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
ci:
strategy:
matrix:
python-version: ["3.8"]
python-version: ["3.13"]
corsika-version: ["77550"]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ corsika-*/
corsika-*.tar.gz
node_modules/
.ipynb_checkpoints/
.venv/
15 changes: 7 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,33 @@ exclude: "(admin/config.h|tests/)"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.12.1
rev: 24.10.0
hooks:
- id: black
language_version: python3.11
- id: black-jupyter
language_version: python3.11

- repo: https://github.com/adamchainz/blacken-docs
rev: "1.16.0" # replace with latest tag on GitHub
rev: "1.19.1" # replace with latest tag on GitHub
hooks:
- id: blacken-docs
additional_dependencies:
- black==22.12.0

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
rev: v1.13.0
hooks:
- id: mypy
args: [--config-file, ./pyproject.toml]
additional_dependencies: ["types-toml"]

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
rev: v2.3.0
hooks:
- id: codespell
exclude: >
Expand All @@ -54,6 +52,7 @@ repos:
- id: prettier

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.9
rev: v0.7.4
hooks:
- id: ruff
args: [--fix]
12 changes: 6 additions & 6 deletions docs/examples/complete.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@
"# Let's see what kind of particles we have in the simulation\n",
"counts = particles[\"pdgid\"].value_counts()\n",
"counts.index = counts.index.map(\n",
" lambda pid: f\"{Particle.from_pdgid(pid).name} ({pid})\"\n",
" if pid != 0\n",
" else \"unknown (0)\"\n",
" lambda pid: (\n",
" f\"{Particle.from_pdgid(pid).name} ({pid})\" if pid != 0 else \"unknown (0)\"\n",
" )\n",
")\n",
"counts.plot(kind=\"bar\", log=True)\n",
"\n",
Expand Down Expand Up @@ -293,9 +293,9 @@
"\n",
"counts = sel.mother_pdgid_cleaned.value_counts()\n",
"counts.index = counts.index.map(\n",
" lambda pid: f\"{Particle.from_pdgid(pid).name} ({pid})\"\n",
" if pid != 0\n",
" else \"unknown (0)\"\n",
" lambda pid: (\n",
" f\"{Particle.from_pdgid(pid).name} ({pid})\" if pid != 0 else \"unknown (0)\"\n",
" )\n",
")\n",
"counts.plot(kind=\"bar\", log=True)\n",
"\n",
Expand Down
7 changes: 3 additions & 4 deletions docs/examples/plot_spectrum.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"source": [
"# These modules will be used\n",
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import panama as pn\n",
Expand Down Expand Up @@ -247,9 +246,9 @@
"\n",
"counts = sel.mother_pdgid_cleaned.value_counts()\n",
"counts.index = counts.index.map(\n",
" lambda pid: f\"{Particle.from_pdgid(pid).name} ({pid})\"\n",
" if pid != 0\n",
" else \"unknown (0)\"\n",
" lambda pid: (\n",
" f\"{Particle.from_pdgid(pid).name} ({pid})\" if pid != 0 else \"unknown (0)\"\n",
" )\n",
")\n",
"counts.plot(kind=\"bar\", log=True)\n",
"\n",
Expand Down
1 change: 1 addition & 0 deletions panama/_nbstreamreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Only to be used internally.
Adapted from http://eyalarubas.com/python-subproc-nonblock.html
"""

from __future__ import annotations

from queue import Empty, Queue
Expand Down
2 changes: 1 addition & 1 deletion panama/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def convert(self, value: int | str, param: Any, ctx: Any) -> int | dict[int, int
return value

try:
d = eval(value) # noqa: PGH001
d = eval(value)
if not isinstance(d, (int, dict)): # noqa: UP038
self.fail(
f"{value!r} is a valid python expression, but not a dict nor an int",
Expand Down
1 change: 1 addition & 0 deletions panama/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Some constants used across multiple modules
"""

from particle import PDGID, Particle

D0_LIFETIME = Particle.from_name("D0").lifetime
Expand Down
7 changes: 4 additions & 3 deletions panama/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Functions to use to determine if a particle is prompt or not,
using multiple different definitions.
"""

from __future__ import annotations

from math import inf
Expand Down Expand Up @@ -60,9 +61,9 @@ def add_cleaned_mother_cols(df_particles: pd.DataFrame) -> None:
if "mother_lifetime_cleaned" not in df_particles:
pdgids = df_particles["mother_pdgid_cleaned"].unique()
lifetimes = {
pdgid: Particle.from_pdgid(pdgid).lifetime
if pdgid != PDGID_ERROR_VAL
else inf
pdgid: (
Particle.from_pdgid(pdgid).lifetime if pdgid != PDGID_ERROR_VAL else inf
)
for pdgid in pdgids
}
for pdgid in lifetimes:
Expand Down
24 changes: 15 additions & 9 deletions panama/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,11 @@ def read_DAT(
# the use of pd.NA is currently experimental in Int64 type columns
corsikaids = df_particles["corsikaid"].unique()
pdg_map = {
corsikaid: int(Corsika7ID(corsikaid).to_pdgid())
if Corsika7ID(corsikaid).is_particle()
else PDGID_ERROR_VAL # This will be our error value
corsikaid: (
int(Corsika7ID(corsikaid).to_pdgid())
if Corsika7ID(corsikaid).is_particle()
else PDGID_ERROR_VAL
) # This will be our error value
for corsikaid in corsikaids
}
df_particles["pdgid"] = (
Expand Down Expand Up @@ -381,9 +383,11 @@ def add_mother_columns(
df_particles.loc[~df_particles["has_mother"], f"mother_{name}"] = error_val

has_charm = {
pdgid: "c" in Particle.from_pdgid(pdgid).quarks.lower()
if pdgid != PDGID_ERROR_VAL
else False
pdgid: (
"c" in Particle.from_pdgid(pdgid).quarks.lower()
if pdgid != PDGID_ERROR_VAL
else False
)
for pdgid in pdgids
}
# explicitly force an invalid PDGID to not be charm
Expand All @@ -401,9 +405,11 @@ def add_mother_columns(
lifetimes[PDGID_ERROR_VAL] = inf

is_resonance = {
pdgid: "*" in Particle.from_pdgid(pdgid).name
if pdgid != PDGID_ERROR_VAL
else False
pdgid: (
"*" in Particle.from_pdgid(pdgid).name
if pdgid != PDGID_ERROR_VAL
else False
)
for pdgid in pdgids
}
# explicitly force an invalid PDGID to not be a resonance
Expand Down
1 change: 1 addition & 0 deletions panama/run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Classes handling the parallel execution of CORSIKA7 processes.
"""

from __future__ import annotations

import io
Expand Down
8 changes: 4 additions & 4 deletions panama/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
try:
from importlib.metadata import packages_distributions # , version

pkgs = packages_distributions() # pragma: no cover
except ImportError:
pkgs = {}
pkgs = packages_distributions()
except ImportError: # pragma: no cover
pkgs = {} # pragma: no cover

__distribution__ = pkgs["panama"][0] if "panama" in pkgs else "corsika-panama"

# __version__ = version(__distribution__)
__version__ = "1.0.1"
__version__ = "1.0.2"

LOGO_TEMPLATE = r"""
,-.----. ,--.das nd ____ ulticore utils for corsik 7
Expand Down
7 changes: 4 additions & 3 deletions panama/weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
are given in units of :math:`(\mathrm{m^2}\ \mathrm{s}\ \mathrm{sr}\ \mathrm{GeV})^{-1}`.
""" # noqa: W605

from __future__ import annotations

from typing import Any
Expand Down Expand Up @@ -150,9 +151,9 @@ def add_weight_prompt(
df.sort_index(inplace=True)

df[weight_col_name] = 1.0
df.loc[
df[is_prompt_col_name] == True, weight_col_name # noqa: E712
] = prompt_factor
df.loc[df[is_prompt_col_name] == True, weight_col_name] = ( # noqa: E712
prompt_factor
)


def add_weight_prompt_per_event(
Expand Down
Loading

0 comments on commit bf18268

Please sign in to comment.