Skip to content
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
9 changes: 1 addition & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,9 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.12", "3.13"]
python-version: ["3.9", "3.13", "3.14"]
runs-on: [ubuntu-latest, macos-latest, windows-latest]

include:
- python-version: "3.8"
runs-on: ubuntu-latest
- python-version: "3.8"
runs-on: macos-13
- python-version: "3.8"
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
pull_request:
paths:
- ".github/workflows/wheels.yml"
- "pyproject.toml"

jobs:
make_sdist:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repos:
rev: v2.31.0
hooks:
- id: pyupgrade
args: ["--py38-plus"]
args: ["--py39-plus"]

- repo: https://github.com/pycqa/flake8
rev: 7.0.0
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sphinx:
formats: all

python:
version: 3.8
version: 3.9
install:
- method: pip
path: .
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path: List[str] = []
html_static_path: list[str] = []
23 changes: 13 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,37 @@ classifiers = [
"License :: OSI Approved :: BSD License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Development Status :: 5 - Production/Stable",
]
requires-python = ">=3.8"
requires-python = ">=3.9"
dependencies = [
"numpy >=1.13.3",
"pydantic >=2",
"rich",
"packaging",
"setuptools;python_version<'3.9'"
]

[project.optional-dependencies]
test = [
"pytest >=4.6",
"scipy",
"awkward >=2.2.2;python_version>'3.7'",
"awkward <2;python_version<='3.7'",
"dask-awkward >=2024.1.1;python_version>'3.7'",
"dask <2025.4.0;python_version>'3.7'",
"awkward >=2.2.2",
"dask-awkward >=2024.1.1",
"dask <2025.4.0",
]
dev = [
"pytest >=4.6",
"pre-commit",
"mypy",
"uhi",
"awkward >=2",
"dask-awkward;python_version>'3.7'",
"dask-awkward",
]
docs = [
"recommonmark >=0.5.0",
Expand Down Expand Up @@ -92,11 +96,10 @@ BUILD_DEMO = "OFF"
write_to = "src/correctionlib/version.py"

[tool.cibuildwheel]
skip = ["pp*-*", "cp314*"]
skip = ["pp*-*", "cp313t-*", "cp314t-*"]
test-extras = "test"
test-command = "python -m pytest {package}/tests"
# When cpython 3.7 is dropped we can ignore i686 (numpy not built)
test-skip = ["*-musllinux_*", "cp3{10,11,12}-win32", "cp3{8,9,10,11,12}-manylinux_i686"]
test-skip = ["*-musllinux_*", "cp3{10,11,12}-win32"]

[tool.cibuildwheel.environment]
# this makes sure that we build only on platforms that have a corresponding numpy wheel
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ line_length = 88

[mypy]
files = src
python_version = 3.8
python_version = 3.9

[mypy-numpy]
ignore_missing_imports = True
Expand Down
30 changes: 10 additions & 20 deletions src/correctionlib/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@

"""
from numbers import Real
from typing import (
TYPE_CHECKING,
Any,
Iterable,
List,
Optional,
Sequence,
Tuple,
Union,
cast,
)
from typing import TYPE_CHECKING, Any, Iterable, Optional, Sequence, Union, cast

import numpy

Expand Down Expand Up @@ -40,7 +30,7 @@

def from_uproot_THx(
path: str,
axis_names: Optional[List[str]] = None,
axis_names: Optional[list[str]] = None,
flow: Literal["clamp", "error"] = "error",
) -> Correction:
"""Convert a ROOT histogram
Expand All @@ -62,7 +52,7 @@ def from_uproot_THx(

def from_histogram(
hist: "PlottableHistogram",
axis_names: Optional[List[str]] = None,
axis_names: Optional[list[str]] = None,
flow: Optional[Union[Content, Literal["clamp", "error"]]] = "error",
) -> Correction:
"""Read any object with PlottableHistogram interface protocol
Expand Down Expand Up @@ -93,14 +83,14 @@ def read_axis(axis: "PlottableAxis", pos: int) -> Variable:
variables = [read_axis(ax, i) for i, ax in enumerate(hist.axes)]
# Here we could try to optimize the ordering

def edges(axis: "PlottableAxis") -> List[float]:
def edges(axis: "PlottableAxis") -> list[float]:
out = []
for i, b in enumerate(axis):
if isinstance(b, (str, int)):
raise ValueError(
"cannot auto-convert string or integer category axes (yet)"
)
b = cast(Tuple[float, float], b)
b = cast(tuple[float, float], b)
out.append(b[0])
if i == len(axis) - 1:
out.append(b[1])
Expand All @@ -116,7 +106,7 @@ def flatten_to(values: "ndarray[Any, Any]", depth: int) -> Iterable[Any]:
def build_data(
values: "ndarray[Any, Any]",
axes: Sequence["PlottableAxis"],
variables: List[Variable],
variables: list[Variable],
) -> Content:
vartype = variables[0].type
if vartype in {"string", "int"}:
Expand Down Expand Up @@ -183,12 +173,12 @@ def build_data(


def ndpolyfit(
points: List["ndarray[Any, Any]"],
points: list["ndarray[Any, Any]"],
values: "ndarray[Any, Any]",
weights: "ndarray[Any, Any]",
varnames: List[str],
degree: Tuple[int],
) -> Tuple[Correction, Any]:
varnames: list[str],
degree: tuple[int],
) -> tuple[Correction, Any]:
"""Fit an n-dimensional polynomial to data points with weight

Example::
Expand Down
20 changes: 10 additions & 10 deletions src/correctionlib/highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
import json
from numbers import Integral
from typing import Any, Callable, Dict, Iterator, List, Mapping, Union
from typing import Any, Callable, Iterator, Mapping, Union

import numpy
from packaging import version
Expand Down Expand Up @@ -186,10 +186,10 @@ def __init__(self, base: correctionlib._core.Correction, context: "CorrectionSet
self._name = base.name
self._context = context

def __getstate__(self) -> Dict[str, Any]:
def __getstate__(self) -> dict[str, Any]:
return {"_context": self._context, "_name": self._name}

def __setstate__(self, state: Dict[str, Any]) -> None:
def __setstate__(self, state: dict[str, Any]) -> None:
self._context = state["_context"]
self._name = state["_name"]
self._base = self._context[self._name]._base
Expand All @@ -207,7 +207,7 @@ def version(self) -> int:
return self._base.version

@property
def inputs(self) -> List[correctionlib._core.Variable]:
def inputs(self) -> list[correctionlib._core.Variable]:
return self._base.inputs

@property
Expand Down Expand Up @@ -268,10 +268,10 @@ def __init__(
self._name = base.name
self._context = context

def __getstate__(self) -> Dict[str, Any]:
def __getstate__(self) -> dict[str, Any]:
return {"_context": self._context, "_name": self._name}

def __setstate__(self, state: Dict[str, Any]) -> None:
def __setstate__(self, state: dict[str, Any]) -> None:
self._context = state["_context"]
self._name = state["_name"]
self._base = self._context.compound[self._name]._base
Expand All @@ -285,7 +285,7 @@ def description(self) -> str:
return self._base.description

@property
def inputs(self) -> List[correctionlib._core.Variable]:
def inputs(self) -> list[correctionlib._core.Variable]:
return self._base.inputs

@property
Expand Down Expand Up @@ -376,14 +376,14 @@ def from_file(cls, filename: str) -> "CorrectionSet":
def from_string(cls, data: str) -> "CorrectionSet":
return cls(data)

def __getstate__(self) -> Dict[str, Any]:
def __getstate__(self) -> dict[str, Any]:
return {"_data": self._data}

def __setstate__(self, state: Dict[str, Any]) -> None:
def __setstate__(self, state: dict[str, Any]) -> None:
self._data = state["_data"]
self._base = correctionlib._core.CorrectionSet.from_string(self._data)

def _ipython_key_completions_(self) -> List[str]:
def _ipython_key_completions_(self) -> list[str]:
return list(self.keys())

@property
Expand Down
20 changes: 10 additions & 10 deletions src/correctionlib/schemav1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Literal, Optional, Union
from typing import Literal, Optional, Union

from pydantic import BaseModel, ConfigDict

Expand All @@ -21,7 +21,7 @@ class Formula(Model):
# TODO: nodetype: Literal["formula"]
expression: str
parser: Literal["TFormula", "numexpr"]
parameters: List[int]
parameters: list[int]
"Index to Correction.inputs[]"


Expand All @@ -31,29 +31,29 @@ class Formula(Model):

class Binning(Model):
nodetype: Literal["binning"]
edges: List[float]
edges: list[float]
"Edges of the binning, where edges[i] <= x < edges[i+1] => f(x, ...) = content[i](...)"
content: List[Content]
content: list[Content]


class MultiBinning(Model):
"""N-dimensional rectangular binning"""

nodetype: Literal["multibinning"]
edges: List[List[float]]
edges: list[list[float]]
"""Bin edges for each input

C-ordered array, e.g. content[d1*d2*d3*i0 + d2*d3*i1 + d3*i2 + i3] corresponds
to the element at i0 in dimension 0, i1 in dimension 1, etc. and d0 = len(edges[0])-1, etc.
"""
content: List[Content]
content: list[Content]


class Category(Model):
nodetype: Literal["category"]
# TODO: should be Union[List[str], List[int]]
keys: List[Union[str, int]]
content: List[Content]
keys: list[Union[str, int]]
content: list[Content]


Binning.update_forward_refs()
Expand All @@ -68,15 +68,15 @@ class Correction(Model):
"Detailed description of the correction"
version: int
"Version"
inputs: List[Variable]
inputs: list[Variable]
output: Variable
data: Content


class CorrectionSet(Model):
schema_version: Literal[1]
"Schema version"
corrections: List[Correction]
corrections: list[Correction]


if __name__ == "__main__":
Expand Down
Loading
Loading