diff --git a/histbook/hist.py b/histbook/hist.py index f7ec660..dbe858b 100644 --- a/histbook/hist.py +++ b/histbook/hist.py @@ -107,6 +107,8 @@ def recurse(node): def _fill(self, arrays): self.fields # for the side-effect of creating self._instructions + maybeconstants = {"pi": numpy.pi, "Pi": numpy.pi, "e": numpy.e, "E": numpy.e, "inf": numpy.inf, "Inf": numpy.inf, "infinity": numpy.inf, "Infinity": numpy.inf, "nan": numpy.nan, "NaN": numpy.nan, "Nan": numpy.nan} + length = None firstinstruction = None firstarray = None @@ -115,7 +117,10 @@ def _fill(self, arrays): try: array = arrays[instruction.extern.value] except KeyError: - raise ValueError("required field {0} not found in fill arguments".format(repr(str(instruction.extern)))) + if instruction.extern.value in maybeconstants: + continue + else: + raise ValueError("required field {0} not found in fill arguments".format(repr(str(instruction.extern)))) if not isinstance(array, numpy.ndarray): array = numpy.array(array) @@ -139,7 +144,10 @@ def _fill(self, arrays): try: array = arrays[instruction.extern.value] except KeyError: - raise ValueError("required field {0} not found in fill arguments".format(repr(str(instruction.extern)))) + if instruction.extern.value in maybeconstants: + array = numpy.full(length, maybeconstants[instruction.extern.value]) + else: + raise ValueError("required field {0} not found in fill arguments".format(repr(str(instruction.extern)))) if not isinstance(array, numpy.ndarray): array = numpy.array(array)