From 53361dd2f75598ff12ef31a8da4c19574954d572 Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Thu, 6 Apr 2023 16:18:19 -0500 Subject: [PATCH] fix(backport): Raise error when converting xml workspaces without data (#2166) * Backport PR https://github.com/scikit-hep/pyhf/pull/2109 --- src/pyhf/readxml.py | 5 + tests/test_import.py | 13 ++ .../config/HistFactorySchema.dtd | 160 ++++++++++++++++++ .../config/example.xml | 8 + .../config/example_channel.xml | 16 ++ 5 files changed, 202 insertions(+) create mode 100644 tests/test_import/xmlimport_noChannelDataPaths/config/HistFactorySchema.dtd create mode 100644 tests/test_import/xmlimport_noChannelDataPaths/config/example.xml create mode 100644 tests/test_import/xmlimport_noChannelDataPaths/config/example_channel.xml diff --git a/src/pyhf/readxml.py b/src/pyhf/readxml.py index 165d51685c..d1942bfe4e 100644 --- a/src/pyhf/readxml.py +++ b/src/pyhf/readxml.py @@ -279,6 +279,11 @@ def process_data( histopath = sample.attrib.get('HistoPath', histopath) histoname = sample.attrib['HistoName'] + if inputfile == "" or histoname == "": + raise NotImplementedError( + "Conversion of workspaces without data is currently not supported.\nSee https://github.com/scikit-hep/pyhf/issues/566" + ) + data, _ = import_root_histogram(resolver, inputfile, histopath, histoname) return data diff --git a/tests/test_import.py b/tests/test_import.py index 78f7b27ba1..7e1f52895b 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -491,6 +491,19 @@ def test_import_noChannelData(mocker, datadir): pyhf.readxml.parse(basedir.joinpath("config/example.xml"), basedir) +def test_import_noChannelDataPaths(mocker, datadir): + _data = [0.0] + _err = [1.0] + mocker.patch("pyhf.readxml.import_root_histogram", return_value=(_data, _err)) + + basedir = datadir.joinpath("xmlimport_noChannelDataPaths") + with pytest.raises( + NotImplementedError, + match="Conversion of workspaces without data is currently not supported.\nSee https://github.com/scikit-hep/pyhf/issues/566", + ): + pyhf.readxml.parse(basedir.joinpath("config/example.xml"), basedir) + + def test_import_missingPOI(mocker, datadir): _data = [0.0] _err = [1.0] diff --git a/tests/test_import/xmlimport_noChannelDataPaths/config/HistFactorySchema.dtd b/tests/test_import/xmlimport_noChannelDataPaths/config/HistFactorySchema.dtd new file mode 100644 index 0000000000..a1dbc10333 --- /dev/null +++ b/tests/test_import/xmlimport_noChannelDataPaths/config/HistFactorySchema.dtd @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/test_import/xmlimport_noChannelDataPaths/config/example.xml b/tests/test_import/xmlimport_noChannelDataPaths/config/example.xml new file mode 100644 index 0000000000..9e87233426 --- /dev/null +++ b/tests/test_import/xmlimport_noChannelDataPaths/config/example.xml @@ -0,0 +1,8 @@ + + + ./config/example_channel.xml + + SigXsecOverSM + Lumi alpha_syst1 + + diff --git a/tests/test_import/xmlimport_noChannelDataPaths/config/example_channel.xml b/tests/test_import/xmlimport_noChannelDataPaths/config/example_channel.xml new file mode 100644 index 0000000000..ca48ac5c28 --- /dev/null +++ b/tests/test_import/xmlimport_noChannelDataPaths/config/example_channel.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + +