Skip to content
This repository has been archived by the owner on Mar 31, 2019. It is now read-only.

Commit

Permalink
fixes #23: named constants are recognized as constants only if not sp…
Browse files Browse the repository at this point in the history
…ecified in fill()
  • Loading branch information
jpivarski committed Jun 18, 2018
1 parent 3b21444 commit 0067ae6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions histbook/hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 0067ae6

Please sign in to comment.