From 88bd4264483c188708ea08728fb95758f98553bc Mon Sep 17 00:00:00 2001 From: juacrumar Date: Mon, 3 Feb 2025 11:17:37 +0100 Subject: [PATCH 1/2] allows the vp API to take PDF objects directly --- validphys2/src/validphys/config.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/validphys2/src/validphys/config.py b/validphys2/src/validphys/config.py index 6565497d8d..0b23d4485c 100644 --- a/validphys2/src/validphys/config.py +++ b/validphys2/src/validphys/config.py @@ -7,6 +7,7 @@ import logging import numbers import pathlib +from typing import Union import pandas as pd @@ -17,6 +18,7 @@ from reportengine.helputils import get_parser_type from reportengine.namespaces import NSList from validphys.core import ( + PDF, CutsPolicy, DataGroupSpec, DataSetInput, @@ -147,10 +149,15 @@ def _check_pdf_usable(self, pdf_name: str): @element_of("pdfs") @_id_with_label - def parse_pdf(self, name: str, unpolarized_bc=None): + def parse_pdf(self, name: Union[str, PDF], unpolarized_bc=None): """A PDF set installed in LHAPDF. If an unpolarized boundary condition it defined, it will be registered as part of the PDF. + + If ``name`` is already an instance of a vp PDF object, return it unchanged. """ + # This allows passing pdf objects to the validphys API + if isinstance(name, PDF): + return name pdf = self._check_pdf_usable(name) if unpolarized_bc is not None: pdf.register_boundary(unpolarized_bc=unpolarized_bc) From aa07cc95fe04de2c646c371374983d466ea4642c Mon Sep 17 00:00:00 2001 From: juacrumar Date: Tue, 4 Feb 2025 07:57:49 +0100 Subject: [PATCH 2/2] remove type annotation --- validphys2/src/validphys/config.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/validphys2/src/validphys/config.py b/validphys2/src/validphys/config.py index 0b23d4485c..2a609a567a 100644 --- a/validphys2/src/validphys/config.py +++ b/validphys2/src/validphys/config.py @@ -7,7 +7,6 @@ import logging import numbers import pathlib -from typing import Union import pandas as pd @@ -149,13 +148,14 @@ def _check_pdf_usable(self, pdf_name: str): @element_of("pdfs") @_id_with_label - def parse_pdf(self, name: Union[str, PDF], unpolarized_bc=None): + def parse_pdf(self, name, unpolarized_bc=None): """A PDF set installed in LHAPDF. If an unpolarized boundary condition it defined, it will be registered as part of the PDF. If ``name`` is already an instance of a vp PDF object, return it unchanged. """ - # This allows passing pdf objects to the validphys API + # NB: for reportengine to check the inputs, name should have type: Union[str, PDF] + # to be changed when support for older versions of python is dropped if isinstance(name, PDF): return name pdf = self._check_pdf_usable(name)