diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7c983aa6..c937decb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,14 +27,12 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python-version: ["2.7", "3.5", "3.6", "3.8", "3.9", "3.10"] + python-version: ["3.6", "3.8", "3.9", "3.10"] include: - - {os: macos-latest, python-version: '2.7'} - - {os: macos-latest, python-version: '3.9'} + - {os: macos-latest, python-version: '3.6'} + - {os: macos-latest, python-version: '3.10'} - {os: windows-latest, python-version: '3.7'} - {os: windows-latest, python-version: '3.9'} - exclude: - - {os: ubuntu-latest, python-version: '3.7'} steps: - uses: actions/checkout@v2 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 918385c8..5fd02e9f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,7 +15,6 @@ repos: - id: requirements-txt-fixer - id: debug-statements - id: end-of-file-fixer - - id: fix-encoding-pragma - repo: https://github.com/PyCQA/isort rev: 5.10.1 @@ -31,12 +30,12 @@ repos: rev: v1.20.0 hooks: - id: setup-cfg-fmt - args: [--max-py-version=3.10, --min-py3-version=3.5] - repo: https://github.com/asottile/pyupgrade rev: v2.29.1 hooks: - id: pyupgrade + args: ["--py36-plus"] - repo: https://github.com/mgedmin/check-manifest rev: "0.47" @@ -55,7 +54,7 @@ repos: hooks: - id: mypy files: src - additional_dependencies: [attrs==19.3.0, types-deprecated] + additional_dependencies: [attrs==21.2.0, types-deprecated] - repo: https://github.com/codespell-project/codespell rev: v2.1.0 diff --git a/admin/dump_pdgid_to_lhcb.py b/admin/dump_pdgid_to_lhcb.py index 206fe1a2..d5a9a17b 100755 --- a/admin/dump_pdgid_to_lhcb.py +++ b/admin/dump_pdgid_to_lhcb.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/noxfile.py b/noxfile.py index a430d74f..f17b0f5b 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from pathlib import Path import nox diff --git a/setup.cfg b/setup.cfg index 999e7f24..4e3bc2ae 100644 --- a/setup.cfg +++ b/setup.cfg @@ -17,10 +17,8 @@ classifiers = License :: OSI Approved :: BSD License Operating System :: OS Independent Programming Language :: Python - Programming Language :: Python :: 2 - Programming Language :: Python :: 2.7 Programming Language :: Python :: 3 - Programming Language :: Python :: 3.5 + Programming Language :: Python :: 3 :: Only Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 @@ -42,11 +40,9 @@ install_requires = attrs>=19.2 deprecated hepunits>=2.0.0 - enum34>=1.1;python_version<"3.4" importlib-resources>=2.0;python_version<"3.9" - typing>=3.7;python_version<"3.5" typing-extensions;python_version<"3.8" -python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.* +python_requires = >=3.6 include_package_data = True package_dir = =src @@ -57,22 +53,22 @@ where = src [options.extras_require] all = check-manifest>=0.42 - pytest + pandas + pytest>=6 pytest-benchmark tabulate - pandas;python_version>"3.4" dev = check-manifest>=0.42 - pytest + pandas + pytest>=6 pytest-benchmark tabulate - pandas;python_version>"3.4" test = - pytest + pandas + pytest>=6 pytest-benchmark pytest-cov tabulate - pandas;python_version>"3.4" [options.package_data] * = *.csv, *.fwf, *.mcd, *.py.typed @@ -90,5 +86,5 @@ filterwarnings = [flake8] max-complexity = 24 -ignore = E203, E231, E501, E722, W503, B950, E402, B904 +ignore = E203, E231, E501, E722, W503, B950, E402 select = C,E,F,W,B,B9 diff --git a/setup.py b/setup.py index 1b95755a..7afd1c56 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/src/particle/__init__.py b/src/particle/__init__.py index a0fdd6bf..06eb370f 100644 --- a/src/particle/__init__.py +++ b/src/particle/__init__.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -from __future__ import absolute_import import sys from typing import Tuple diff --git a/src/particle/__main__.py b/src/particle/__main__.py index a3be94ed..935da28b 100644 --- a/src/particle/__main__.py +++ b/src/particle/__main__.py @@ -1,11 +1,9 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -from __future__ import absolute_import, print_function import argparse import sys @@ -25,7 +23,7 @@ def main(): parser.add_argument( "--version", action="version", - version="%(prog)s {version}".format(version=__version__), + version=f"%(prog)s {__version__}", ) subparsers = parser.add_subparsers(help="Subcommands") diff --git a/src/particle/converters/__init__.py b/src/particle/converters/__init__.py index 56d50df7..18d3e40b 100644 --- a/src/particle/converters/__init__.py +++ b/src/particle/converters/__init__.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -from __future__ import absolute_import from typing import Tuple diff --git a/src/particle/converters/bimap.py b/src/particle/converters/bimap.py index fe7d19ab..dc5f754e 100644 --- a/src/particle/converters/bimap.py +++ b/src/particle/converters/bimap.py @@ -1,19 +1,11 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -from __future__ import absolute_import - -try: - # for Python 3 - from collections.abc import Mapping -except ImportError: - # for Python 2.7 - from collections import Mapping import csv +from collections.abc import Mapping from typing import ( Any, Callable, @@ -88,7 +80,7 @@ def __init__(self, class_A, class_B, converters=(int, int), filename=None): name_B = self.class_B.__name__.upper() if filename is None: - filename = "{a}_to_{b}.csv".format(a=name_A.lower(), b=name_B.lower()) + filename = f"{name_A.lower()}_to_{name_B.lower()}.csv" file_object = data.basepath.joinpath(filename).open() elif isinstance(filename, HasRead): file_object = filename diff --git a/src/particle/converters/evtgen.py b/src/particle/converters/evtgen.py index 4508c264..01db64d7 100644 --- a/src/particle/converters/evtgen.py +++ b/src/particle/converters/evtgen.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -from __future__ import absolute_import from .. import data from ..pdgid import PDGID diff --git a/src/particle/converters/geant.py b/src/particle/converters/geant.py index c7dc8569..3b06f977 100644 --- a/src/particle/converters/geant.py +++ b/src/particle/converters/geant.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -from __future__ import absolute_import from ..geant import Geant3ID from ..pdgid import PDGID diff --git a/src/particle/converters/pythia.py b/src/particle/converters/pythia.py index 8ee360f5..e4d24440 100644 --- a/src/particle/converters/pythia.py +++ b/src/particle/converters/pythia.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -from __future__ import absolute_import from ..pdgid import PDGID from ..pythia import PythiaID diff --git a/src/particle/data/__init__.py b/src/particle/data/__init__.py index 75be5f6d..6bb2ba85 100644 --- a/src/particle/data/__init__.py +++ b/src/particle/data/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/src/particle/exceptions.py b/src/particle/exceptions.py index e35ac4f8..489de26d 100644 --- a/src/particle/exceptions.py +++ b/src/particle/exceptions.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/src/particle/geant/__init__.py b/src/particle/geant/__init__.py index 7aa733da..a9ffdbc6 100644 --- a/src/particle/geant/__init__.py +++ b/src/particle/geant/__init__.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -from __future__ import absolute_import from typing import Tuple diff --git a/src/particle/geant/geant3id.py b/src/particle/geant/geant3id.py index bc804a28..9727a9f5 100644 --- a/src/particle/geant/geant3id.py +++ b/src/particle/geant/geant3id.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE @@ -13,7 +12,6 @@ follows the PDG rules, hence uses the standard PDG IDs. """ -from __future__ import absolute_import import csv @@ -55,9 +53,7 @@ def from_pdgid(cls, pdgid): for k, v in _bimap.items(): if v == pdgid: return cls(k) - raise MatchingIDNotFound( - "Non-existent Geant3ID for input PDGID {} !".format(pdgid) - ) + raise MatchingIDNotFound(f"Non-existent Geant3ID for input PDGID {pdgid} !") def to_pdgid(self): # type: () -> PDGID @@ -65,7 +61,7 @@ def to_pdgid(self): def __repr__(self): # type: () -> str - return "".format(int(self)) + return f"" def __str__(self): # type: () -> str diff --git a/src/particle/lhcb/__init__.py b/src/particle/lhcb/__init__.py index d38940ed..a61360d2 100644 --- a/src/particle/lhcb/__init__.py +++ b/src/particle/lhcb/__init__.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -from __future__ import absolute_import from typing import Tuple diff --git a/src/particle/lhcb/converters/__init__.py b/src/particle/lhcb/converters/__init__.py index 9bf45bf2..bb7194c0 100644 --- a/src/particle/lhcb/converters/__init__.py +++ b/src/particle/lhcb/converters/__init__.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -from __future__ import absolute_import from typing import Tuple diff --git a/src/particle/lhcb/converters/lhcb.py b/src/particle/lhcb/converters/lhcb.py index fc96baf4..45853481 100644 --- a/src/particle/lhcb/converters/lhcb.py +++ b/src/particle/lhcb/converters/lhcb.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -from __future__ import absolute_import from ...converters.bimap import BiMap from ...pdgid import PDGID diff --git a/src/particle/lhcb/data/__init__.py b/src/particle/lhcb/data/__init__.py index bdce3bec..9cb3b019 100644 --- a/src/particle/lhcb/data/__init__.py +++ b/src/particle/lhcb/data/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/src/particle/lhcb/utils.py b/src/particle/lhcb/utils.py index f999f821..8683670a 100644 --- a/src/particle/lhcb/utils.py +++ b/src/particle/lhcb/utils.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from ..particle import Particle from .converters import LHCbName2PDGIDBiMap diff --git a/src/particle/particle/__init__.py b/src/particle/particle/__init__.py index 91531fb0..31bb057c 100644 --- a/src/particle/particle/__init__.py +++ b/src/particle/particle/__init__.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -from __future__ import absolute_import from typing import Tuple diff --git a/src/particle/particle/convert.py b/src/particle/particle/convert.py index 8a0dba0c..cf6fe87c 100644 --- a/src/particle/particle/convert.py +++ b/src/particle/particle/convert.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE @@ -53,6 +52,7 @@ import os from datetime import date +from io import StringIO from typing import ( Any, Callable, @@ -68,14 +68,6 @@ import numpy as np import pandas as pd -try: - from io import StringIO -except ImportError: # Python2 workaround, could also use six - try: - from cStringIO import StringIO # type: ignore - except ImportError: - from StringIO import StringIO # type: ignore - from .. import data from ..pdgid import PDGID, is_baryon from .enums import ( @@ -346,11 +338,11 @@ def get_from_pdg_mcd(filename): print("DUPLICATES:\n", nar[duplicated_ids]) assert ( nar[duplicated_ids].shape[0] == 0 - ), "Duplicate entries found in {} !".format(filename) + ), f"Duplicate entries found in {filename} !" ds_list = [] for i in range(4): - name = "ID{}".format(i + 1) + name = f"ID{i + 1}" d = nar[~pd.isna(nar[name])].copy() d["ID"] = d[name].astype(int) nc = d.NameCharge.str.split(expand=True) diff --git a/src/particle/particle/enums.py b/src/particle/particle/enums.py index 6e9a12a8..43a23970 100644 --- a/src/particle/particle/enums.py +++ b/src/particle/particle/enums.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/src/particle/particle/kinematics.py b/src/particle/particle/kinematics.py index 29e7b6a6..043464b1 100644 --- a/src/particle/particle/kinematics.py +++ b/src/particle/particle/kinematics.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE @@ -8,7 +7,6 @@ Functions relevant to particle kinematics. """ -from __future__ import absolute_import, division, print_function from hepunits.constants import hbar from hepunits.units import MeV, ns @@ -52,7 +50,7 @@ def width_to_lifetime(Gamma): """ if Gamma < 0.0: - raise ValueError("Input provided, {} <= 0!".format(Gamma)) + raise ValueError(f"Input provided, {Gamma} <= 0!") elif Gamma == 0: return float("inf") @@ -99,7 +97,7 @@ def lifetime_to_width(tau): """ if tau < 0: - raise ValueError("Input provided, {} <= 0!".format(tau)) + raise ValueError(f"Input provided, {tau} <= 0!") elif tau == 0: return float("inf") diff --git a/src/particle/particle/literals.py b/src/particle/particle/literals.py index ecdb9fb5..2a83cc2f 100644 --- a/src/particle/particle/literals.py +++ b/src/particle/particle/literals.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/src/particle/particle/particle.py b/src/particle/particle/particle.py index d11eb2ab..3a93b444 100644 --- a/src/particle/particle/particle.py +++ b/src/particle/particle/particle.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -from __future__ import absolute_import, division, print_function # Python standard library import csv @@ -87,7 +85,7 @@ def _none_or_positive_converter(value): @total_ordering @attr.s(slots=True, eq=False, order=False, repr=False) -class Particle(object): +class Particle: """ The Particle object class. Hold a series of properties for a particle. @@ -293,7 +291,7 @@ def to_list( n_rows=-1, # type: int filter_fn=None, # type: Optional[Callable[[Particle], bool]] particle=None, # type: Optional[bool] - **search_terms # type: Any + **search_terms, # type: Any ): # type: (...) -> List[List[Union[bool, int, str, float]]] """ @@ -419,7 +417,7 @@ def to_list( # Apply a filter, if specified if filter_fn is not None: - tbl_all = cls.findall(filter_fn, particle, **search_terms) + tbl_all = cls.findall(filter_fn, particle=particle, **search_terms) # In any case, only keep a given number of rows? if n_rows >= 0: @@ -576,9 +574,7 @@ def load_table(cls, filename=None, append=False, _name=None): return elif isinstance(filename, HasRead): tmp_name = _name or filename.name - cls._table_names.append( - tmp_name or "{!r} {}".format(filename, len(cls._table_names)) - ) + cls._table_names.append(tmp_name or f"{filename!r} {len(cls._table_names)}") open_file = filename elif isinstance(filename, HasOpen): cls._table_names.append(str(filename)) @@ -857,7 +853,7 @@ def _width_or_lifetime(self): elif self.width == 0: return "Width = 0.0 MeV" elif self.width_lower is None or self.width_upper is None: - return "Width < {width} MeV".format(width=self.width) + return f"Width < {self.width} MeV" elif ( self.width < 0.05 ): # corresponds to a lifetime of approximately 1.3e-20 seconds @@ -981,9 +977,9 @@ def describe(self): ) if self.spin_type != SpinType.Unknown: - val += " SpinType: {self.spin_type!s}\n".format(self=self) + val += f" SpinType: {self.spin_type!s}\n" if self.quarks: - val += " Quarks: {self.quarks}\n".format(self=self) + val += f" Quarks: {self.quarks}\n" val += " Antiparticle name: {inv_self.name} (antiparticle status: {self.anti_flag.name})".format( inv_self=self.invert(), self=self ) @@ -1028,7 +1024,7 @@ def from_pdgid(cls, value): If no matching PDG ID is found in the loaded data table(s). """ if not is_valid(value): - raise InvalidParticle("Input PDGID {} is invalid!".format(value)) + raise InvalidParticle(f"Input PDGID {value} is invalid!") if not cls.table_loaded(): cls.load_table() @@ -1039,7 +1035,7 @@ def from_pdgid(cls, value): return cls._hash_table[int(value)] except KeyError: raise ParticleNotFound( # noqa: B904 <- use from None when Python 2 is dropped - "Could not find PDGID {}".format(value) + f"Could not find PDGID {value}" ) @classmethod @@ -1060,7 +1056,7 @@ def from_name(cls, name): return particle except ValueError: raise ParticleNotFound( # noqa: B904 <- use from None when Python 2 is dropped - 'Could not find name "{}"'.format(name) + f'Could not find name "{name}"' ) @classmethod @@ -1082,8 +1078,9 @@ def from_evtgen_name(cls, name): def finditer( cls, filter_fn=None, # type: Optional[Callable[[Particle], bool]] + *, particle=None, # type: Optional[bool] - **search_terms # type: Any + **search_terms, # type: Any ): # type: (...) -> Iterator[Particle] """ @@ -1124,9 +1121,6 @@ def finditer( See also ``findall``, which returns the same thing, but as a list. """ - # Note that particle can be called by position to keep compatibility with Python 2, but that behavior should - # not be used and will be removed when support for Python 2.7 is dropped. - # Filter out values for item in cls.all(): # At this point, continue if a match fails @@ -1180,8 +1174,9 @@ def finditer( def findall( cls, filter_fn=None, # type: Optional[Callable[[Particle], bool]] + *, particle=None, # type: Optional[bool] - **search_terms # type: Any + **search_terms, # type: Any ): # type: (...) -> List[Particle] @@ -1258,7 +1253,7 @@ def find(cls, *args, **search_terms): return results[0] elif len(results) == 0: raise ParticleNotFound( - "Did not find particle matching query: {}".format(search_terms) + f"Did not find particle matching query: {search_terms}" ) else: raise RuntimeError("Found too many particles") @@ -1271,7 +1266,7 @@ def from_string(cls, name): if matches: return matches[0] else: - raise ParticleNotFound("{} not found in particle table".format(name)) + raise ParticleNotFound(f"{name} not found in particle table") @classmethod def from_string_list(cls, name): @@ -1348,9 +1343,7 @@ def _from_group_dict_list(cls, mat): vals = cls.findall(name=lambda x: name in x, **kw) if not vals: - raise ParticleNotFound( - "Could not find particle {} or {}".format(maxname, name) - ) + raise ParticleNotFound(f"Could not find particle {maxname} or {name}") if len(vals) > 1 and mat["mass"] is not None: vals = [val for val in vals if mat["mass"] in val.latex_name] diff --git a/src/particle/particle/regex.py b/src/particle/particle/regex.py index 25cf54fe..f4eba936 100644 --- a/src/particle/particle/regex.py +++ b/src/particle/particle/regex.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/src/particle/particle/utilities.py b/src/particle/particle/utilities.py index 6ca945c8..0124f566 100644 --- a/src/particle/particle/utilities.py +++ b/src/particle/particle/utilities.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE @@ -6,7 +5,6 @@ import math import re -import sys import unicodedata from typing import Optional @@ -67,13 +65,13 @@ def str_with_unc(value, upper, lower=None): # This is normal notation if -3 < value_digits < 6: if error_digits < 0: - fsv = fse = ".{}f".format(-error_digits) + fsv = fse = f".{-error_digits}f" else: fsv = fse = ".0f" # This is scientific notation - a little odd, but better than the other options. else: - fsv = ".{}e".format(abs(error_digits - value_digits)) + fsv = f".{abs(error_digits - value_digits)}e" pure_error_digits = int(math.floor(math.log10(error))) fse = ".0e" if error_digits == pure_error_digits else ".1e" @@ -84,12 +82,7 @@ def str_with_unc(value, upper, lower=None): value=value, upper=upper, lower=lower, fsv=fsv, fse=fse ) - # Only bother with unicode if this is Python 3. - pm = u"±" if sys.version_info >= (3,) else "+/-" - - return "{value:{fsv}} {pm} {upper:{fse}}".format( - value=value, pm=pm, upper=upper, fsv=fsv, fse=fse - ) + return f"{value:{fsv}} ± {upper:{fse}}" # List of greek letter names as used in Unicode (see unicodedata package) @@ -165,7 +158,7 @@ def latex_name_unicode(name): if "ambda" in name: name = name.replace("ambda", "amda") for gl in _list_name_greek_letters: - name = name.replace(r"\{}".format(gl), greek_letter_name_to_unicode(gl)) + name = name.replace(fr"\{gl}", greek_letter_name_to_unicode(gl)) return name diff --git a/src/particle/pdgid/__init__.py b/src/particle/pdgid/__init__.py index e216fc28..4c9164d7 100644 --- a/src/particle/pdgid/__init__.py +++ b/src/particle/pdgid/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE @@ -59,7 +58,6 @@ """ -from __future__ import absolute_import from typing import Tuple diff --git a/src/particle/pdgid/functions.py b/src/particle/pdgid/functions.py index c8bf6e59..ec2b0ef4 100644 --- a/src/particle/pdgid/functions.py +++ b/src/particle/pdgid/functions.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE @@ -24,7 +23,6 @@ - HepPDT and HepPID versions 3.04.01. """ -from __future__ import absolute_import, division, print_function from enum import IntEnum from typing import Optional, SupportsInt diff --git a/src/particle/pdgid/literals.py b/src/particle/pdgid/literals.py index 8e0aab10..c8b33e6e 100644 --- a/src/particle/pdgid/literals.py +++ b/src/particle/pdgid/literals.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE @@ -38,8 +37,7 @@ __doc = "".join( - " {item!s} = PDGID({pdgid})\n".format(item=item, pdgid=common_particles[item]) - for item in common_particles + f" {item!s} = PDGID({common_particles[item]})\n" for item in common_particles ) __doc__ = __doc__.format(__doc) diff --git a/src/particle/pdgid/pdgid.py b/src/particle/pdgid/pdgid.py index 60a785da..b3e92cf4 100644 --- a/src/particle/pdgid/pdgid.py +++ b/src/particle/pdgid/pdgid.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE @@ -10,7 +9,6 @@ All methods of HepPID are implemented in a Pythonic version, see the functions module. """ -from __future__ import absolute_import from inspect import isfunction @@ -58,7 +56,7 @@ def info(self): Print all PDGID properties one per line, for easy inspection. """ return "".join( - "{item:14} {value}\n".format(item=item, value=getattr(self, item)) + f"{item:14} {getattr(self, item)}\n" for item in _fnames if item != "is_composite_quark_or_lepton" ) @@ -135,4 +133,4 @@ def info(self): for _n in _fnames: assert _n in dir( PDGID - ), "{} missing from PDGID class! Update the list in pdgid.py".format(_n) + ), f"{_n} missing from PDGID class! Update the list in pdgid.py" diff --git a/src/particle/pythia/__init__.py b/src/particle/pythia/__init__.py index 10ea60e0..a433ddd9 100644 --- a/src/particle/pythia/__init__.py +++ b/src/particle/pythia/__init__.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -from __future__ import absolute_import from typing import Tuple diff --git a/src/particle/pythia/pythiaid.py b/src/particle/pythia/pythiaid.py index d958b8be..3ed31262 100644 --- a/src/particle/pythia/pythiaid.py +++ b/src/particle/pythia/pythiaid.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE @@ -8,7 +7,6 @@ Class representing a Pythia ID. """ -from __future__ import absolute_import import csv @@ -50,9 +48,7 @@ def from_pdgid(cls, pdgid): for k, v in _bimap.items(): if v == pdgid: return cls(k) - raise MatchingIDNotFound( - "Non-existent PythiaID for input PDGID {} !".format(pdgid) - ) + raise MatchingIDNotFound(f"Non-existent PythiaID for input PDGID {pdgid} !") def to_pdgid(self): # type: () -> PDGID @@ -60,7 +56,7 @@ def to_pdgid(self): def __repr__(self): # type: () -> str - return "".format(int(self)) + return f"" def __str__(self): # type: () -> str diff --git a/src/particle/shared_literals.py b/src/particle/shared_literals.py index a10f73d0..97b68bba 100644 --- a/src/particle/shared_literals.py +++ b/src/particle/shared_literals.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE @@ -11,7 +10,6 @@ See the particle.literals and the pdgid.literals submodules for the actually exposed aliases. """ -from __future__ import absolute_import from .particle import Particle diff --git a/src/particle/typing.py b/src/particle/typing.py index 37f18e3a..1913df83 100644 --- a/src/particle/typing.py +++ b/src/particle/typing.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -from __future__ import absolute_import, division, print_function import sys diff --git a/tests/__init__.py b/tests/__init__.py index f4bad91d..a47ee414 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/tests/conftest.py b/tests/conftest.py index dac6303b..8f831c90 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/tests/converters/__init__.py b/tests/converters/__init__.py index f4bad91d..a47ee414 100644 --- a/tests/converters/__init__.py +++ b/tests/converters/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/tests/converters/test_maps.py b/tests/converters/test_maps.py index a02b7dc6..adbcfd95 100644 --- a/tests/converters/test_maps.py +++ b/tests/converters/test_maps.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/tests/geant/__init__.py b/tests/geant/__init__.py index f4bad91d..a47ee414 100644 --- a/tests/geant/__init__.py +++ b/tests/geant/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/tests/geant/test_geant3id.py b/tests/geant/test_geant3id.py index 53793356..427de0b8 100644 --- a/tests/geant/test_geant3id.py +++ b/tests/geant/test_geant3id.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/tests/lhcb/test_lhcb_name.py b/tests/lhcb/test_lhcb_name.py index 6e5945d1..c157eaf7 100644 --- a/tests/lhcb/test_lhcb_name.py +++ b/tests/lhcb/test_lhcb_name.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/tests/particle/__init__.py b/tests/particle/__init__.py index f4bad91d..a47ee414 100644 --- a/tests/particle/__init__.py +++ b/tests/particle/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/tests/particle/test_convert.py b/tests/particle/test_convert.py index 0cf6b073..550f2b11 100644 --- a/tests/particle/test_convert.py +++ b/tests/particle/test_convert.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE @@ -9,13 +8,9 @@ # Requires pandas pd = pytest.importorskip("pandas") -from particle.particle.convert import get_from_pdg_mcd - -try: - from pathlib2 import Path -except ImportError: - from pathlib import Path +from pathlib import Path +from particle.particle.convert import get_from_pdg_mcd DIR = Path(__file__).parent.resolve() diff --git a/tests/particle/test_decfilenames.py b/tests/particle/test_decfilenames.py index aebac12c..f3ae6516 100644 --- a/tests/particle/test_decfilenames.py +++ b/tests/particle/test_decfilenames.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -from __future__ import absolute_import, division, print_function from particle.particle import Particle, ParticleNotFound diff --git a/tests/particle/test_enums.py b/tests/particle/test_enums.py index 2fe57146..a7711e20 100644 --- a/tests/particle/test_enums.py +++ b/tests/particle/test_enums.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -from __future__ import absolute_import, division, print_function from particle.particle.enums import Charge, SpinType diff --git a/tests/particle/test_generation.py b/tests/particle/test_generation.py index 02d7c852..ce2d26cf 100644 --- a/tests/particle/test_generation.py +++ b/tests/particle/test_generation.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/tests/particle/test_kinematics.py b/tests/particle/test_kinematics.py index 51bc3a0b..2267a522 100644 --- a/tests/particle/test_kinematics.py +++ b/tests/particle/test_kinematics.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/tests/particle/test_literals.py b/tests/particle/test_literals.py index b391dd17..4ed69281 100644 --- a/tests/particle/test_literals.py +++ b/tests/particle/test_literals.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -from __future__ import division from particle import literals as lp diff --git a/tests/particle/test_particle.py b/tests/particle/test_particle.py index 2afb103d..2af72ef8 100644 --- a/tests/particle/test_particle.py +++ b/tests/particle/test_particle.py @@ -1,12 +1,8 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -from __future__ import absolute_import, division, print_function - -import sys import pytest from hepunits import meter, second @@ -313,14 +309,14 @@ def test_C_consistency(): # Test print-out of zero width values [22, "Width = 0.0 MeV"], # photon # Test print-out of symmetric width errors - [413, u"Width = 0.0834 ± 0.0018 MeV"], # D*(2010)+ - [443, u"Width = 0.0926 ± 0.0017 MeV"], # J/psi + [413, "Width = 0.0834 ± 0.0018 MeV"], # D*(2010)+ + [443, "Width = 0.0926 ± 0.0017 MeV"], # J/psi # Test print-out of asymmetric width errors [4222, "Width = 1.89 + 0.09 - 0.18 MeV"], # Sigma_c(2455)++ - [23, u"Width = 2495.2 ± 2.3 MeV"], # H0 + [23, "Width = 2495.2 ± 2.3 MeV"], # H0 # Test print-out of symmetric lifetime errors - [5332, u"Lifetime = 1.65e-03 + 1.8e-04 - 1.8e-04 ns"], # Omega_b- - [211, u"Lifetime = 26.033 ± 0.005 ns"], # pion + [5332, "Lifetime = 1.65e-03 + 1.8e-04 - 1.8e-04 ns"], # Omega_b- + [211, "Lifetime = 26.033 ± 0.005 ns"], # pion # Test print-out of asymmetric lifetime errors [4332, "Lifetime = 2.7e-04 + 3e-05 - 3e-05 ns"], # Omega_c^0 # Test particles with at present an upper limit on their width @@ -330,9 +326,6 @@ def test_C_consistency(): [4212, "Width < 4.6 MeV"], # Sigma(c)(2455)+ [4214, "Width < 17.0 MeV"], # Sigma(c)(2520)+ ) -if sys.version_info < (3, 0): - for i, pair_vals in enumerate(checklist_describe): - checklist_describe[i][1] = pair_vals[1].replace(u"±", u"+/-") @pytest.mark.parametrize("pid,description", checklist_describe) @@ -405,7 +398,6 @@ def test_all_particles_are_loaded(): ) -@pytest.mark.skipif(sys.version_info < (3, 0), reason="Requires Python 3") @pytest.mark.parametrize("pid,html_name", checklist_html_name) def test_html_name(pid, html_name): particle = Particle.from_pdgid(pid) diff --git a/tests/particle/test_performance.py b/tests/particle/test_performance.py index 68f3cc26..40b0a8f9 100644 --- a/tests/particle/test_performance.py +++ b/tests/particle/test_performance.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from particle import Particle, data diff --git a/tests/particle/test_utilities.py b/tests/particle/test_utilities.py index 3c5f251a..8386efa2 100644 --- a/tests/particle/test_utilities.py +++ b/tests/particle/test_utilities.py @@ -1,35 +1,29 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -import sys - import pytest from particle.particle.utilities import str_with_unc possibilities = ( - (1.234567, 0.01, None, u"1.235 ± 0.010"), - (1.234567e-9, 0.01e-9, None, u"1.235e-09 ± 1.0e-11"), - (1.234567e9, 0.04e9, None, u"1.23e+09 ± 4e+07"), - (0.001, 0.00001, None, u"1.000e-03 ± 1.0e-05"), - (0.00099, 0.00001, None, u"9.90e-04 ± 1.0e-05"), - (99, 0.24, None, u"99.00 ± 0.24"), - (100, 0.25, None, u"100.0 ± 0.2"), - (101, 0.26, None, u"101.0 ± 0.3"), - (0.00001231, 0.000002, 0.000004, u"1.23e-05 + 2.0e-06 - 4.0e-06"), - (1234.5, 0.03, 0.03, u"1234.50 ± 0.03"), - (1234.5, 5, 5, u"1234 ± 5"), - (1234.5, 2, 2, u"1234.5 ± 2.0"), + (1.234567, 0.01, None, "1.235 ± 0.010"), + (1.234567e-9, 0.01e-9, None, "1.235e-09 ± 1.0e-11"), + (1.234567e9, 0.04e9, None, "1.23e+09 ± 4e+07"), + (0.001, 0.00001, None, "1.000e-03 ± 1.0e-05"), + (0.00099, 0.00001, None, "9.90e-04 ± 1.0e-05"), + (99, 0.24, None, "99.00 ± 0.24"), + (100, 0.25, None, "100.0 ± 0.2"), + (101, 0.26, None, "101.0 ± 0.3"), + (0.00001231, 0.000002, 0.000004, "1.23e-05 + 2.0e-06 - 4.0e-06"), + (1234.5, 0.03, 0.03, "1234.50 ± 0.03"), + (1234.5, 5, 5, "1234 ± 5"), + (1234.5, 2, 2, "1234.5 ± 2.0"), ) @pytest.mark.parametrize("value,err_u,err_l,test_str", possibilities) def test_unc_printout(value, err_u, err_l, test_str): - if sys.version_info < (3, 0): - test_str = test_str.replace(u"±", u"+/-") - assert str_with_unc(value, err_u, err_l) == test_str diff --git a/tests/pdgid/__init__.py b/tests/pdgid/__init__.py index f4bad91d..a47ee414 100644 --- a/tests/pdgid/__init__.py +++ b/tests/pdgid/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/tests/pdgid/test_functions.py b/tests/pdgid/test_functions.py index f57d2a58..d646cb88 100644 --- a/tests/pdgid/test_functions.py +++ b/tests/pdgid/test_functions.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -from __future__ import absolute_import, division, print_function from particle.pdgid import ( A, diff --git a/tests/pdgid/test_literals.py b/tests/pdgid/test_literals.py index b616f627..a6c3f618 100644 --- a/tests/pdgid/test_literals.py +++ b/tests/pdgid/test_literals.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/particle for details. -from __future__ import division from particle.pdgid import literals as lid diff --git a/tests/pdgid/test_pdgid.py b/tests/pdgid/test_pdgid.py index a105eb95..80f7143f 100644 --- a/tests/pdgid/test_pdgid.py +++ b/tests/pdgid/test_pdgid.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/tests/pythia/__init__.py b/tests/pythia/__init__.py index f4bad91d..a47ee414 100644 --- a/tests/pythia/__init__.py +++ b/tests/pythia/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/tests/pythia/test_pythiaid.py b/tests/pythia/test_pythiaid.py index 249dfb8f..e36dbcff 100644 --- a/tests/pythia/test_pythiaid.py +++ b/tests/pythia/test_pythiaid.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE diff --git a/tests/test_package.py b/tests/test_package.py index 0757ef25..ec935441 100644 --- a/tests/test_package.py +++ b/tests/test_package.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (c) 2018-2021, Eduardo Rodrigues and Henry Schreiner. # # Distributed under the 3-clause BSD license, see accompanying file LICENSE