diff --git a/pymbolic/compiler.py b/pymbolic/compiler.py index c652d52fdcdd4bf14849c3d78ace8dc8676698db..96ff2c9a347800cfdbbfb823be1eb747853b55f4 100644 --- a/pymbolic/compiler.py +++ b/pymbolic/compiler.py @@ -29,26 +29,21 @@ from pymbolic.mapper.stringifier import (StringifyMapper, PREC_NONE, PREC_SUM, PREC_POWER) -def _constant_mapper(c): - # work around numpy bug #1137 (locale-sensitive repr) - # http://projects.scipy.org/numpy/ticket/1137 - try: - import numpy - except ImportError: - pass - else: - if isinstance(c, numpy.floating): - c = float(c) - elif isinstance(c, numpy.complexfloating): - c = complex(c) - - return repr(c) - - class CompileMapper(StringifyMapper): - def __init__(self): - StringifyMapper.__init__(self, - constant_mapper=_constant_mapper) + def map_constant(self, expr, enclosing_prec): + # work around numpy bug #1137 (locale-sensitive repr) + # http://projects.scipy.org/numpy/ticket/1137 + try: + import numpy + except ImportError: + pass + else: + if isinstance(expr, numpy.floating): + expr = float(expr) + elif isinstance(expr, numpy.complexfloating): + expr = complex(expr) + + return repr(expr) def map_polynomial(self, expr, enclosing_prec): # Use Horner's scheme to evaluate the polynomial diff --git a/pymbolic/mapper/stringifier.py b/pymbolic/mapper/stringifier.py index f1afc0f8d31494176e97b215c73fb9e8d6366152..79fd743bce772323c078a7793353fe160b8214f5 100644 --- a/pymbolic/mapper/stringifier.py +++ b/pymbolic/mapper/stringifier.py @@ -95,7 +95,7 @@ class StringifyMapper(pymbolic.mapper.Mapper): "achieve the desired effect. " "The 'constant_mapper' argument will " "disappear after June 2020.", - DeprecationWarning) + DeprecationWarning, stacklevel=2) self.constant_mapper = constant_mapper