Raise KeyError in prob functions for undefined functions/categories

This commit is contained in:
John J. Camilleri
2021-09-27 14:33:14 +02:00
parent 19251e5e61
commit 7dafeee57b
2 changed files with 21 additions and 11 deletions

View File

@@ -295,7 +295,12 @@ PGF_categoryProbability(PGFObject *self, PyObject *args)
return NULL;
}
return PyFloat_FromDouble((double)prob);
double dprob = (double) prob;
if (dprob == INFINITY) {
PyErr_Format(PyExc_KeyError, "category '%s' is not defined", s);
return NULL;
}
return PyFloat_FromDouble(dprob);
}
static PyObject *
@@ -315,7 +320,12 @@ PGF_functionProbability(PGFObject *self, PyObject *args)
return NULL;
}
return PyFloat_FromDouble((double)prob);
double dprob = (double) prob;
if (dprob == INFINITY) {
PyErr_Format(PyExc_KeyError, "function '%s' is not defined", s);
return NULL;
}
return PyFloat_FromDouble(dprob);
}
static PyObject *
@@ -331,7 +341,8 @@ PGF_exprProbability(PGFObject *self, PyObject *args)
return NULL;
}
return PyFloat_FromDouble((double)prob);
double dprob = (double) prob;
return PyFloat_FromDouble(dprob);
}
static PyGetSetDef PGF_getseters[] = {