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
2 changes: 2 additions & 0 deletions bindings/pyroot/pythonizations/src/RPyROOTApplication.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ static void ErrMsgHandler(int level, Bool_t abort, const char *location, const c
// the GIL.
if (!gGlobalMutex) {
// Either printout or raise exception, depending on user settings
auto state = PyGILState_Ensure();
PyErr_WarnExplicit(NULL, (char *)msg, (char *)location, 0, (char *)"ROOT", NULL);
PyGILState_Release(state);
} else {
::DefaultErrorHandler(level, abort, location, msg);
}
Expand Down
14 changes: 14 additions & 0 deletions bindings/pyroot/pythonizations/test/th1.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,19 @@ def func(x, pars):
self.assertGreater(r.Parameter(0), 0)


class TH1FitWarning(unittest.TestCase):
def test_fit_with_warning(self):
"""
Regression test for https://github.com/root-project/root/issues/22396
"""
import ROOT

h = ROOT.TH1D("test", "test", 100, 0, 1)
# Trying to fit a empty histogram will result in a warning on the C++ side which is re-raised as a Python
# warning by the ROOT CPython extension
with self.assertWarns(RuntimeWarning, msg="Fit data is empty"):
h.Fit("gaus", "S")


if __name__ == "__main__":
unittest.main()
Loading