Skip to content

Commit e08aa91

Browse files
Merge pull request #501 from 27rabbitlt/fix_imagnary_eval_1.1e1j
fix imaginary evaluation 1.1e1j
2 parents 2378606 + b1a916c commit e08aa91

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

numexpr/necompiler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def __str__(self):
265265

266266
_flow_pat = r'[\;\[\:]'
267267
_dunder_pat = r'(^|[^\w])__[\w]+__($|[^\w])'
268-
_attr_pat = r'\.\b(?!(real|imag|(\d*[eE]?[+-]?\d+)|\d*j)\b)'
268+
_attr_pat = r'\.\b(?!(real|imag|(\d*[eE]?[+-]?\d+)|(\d*[eE]?[+-]?\d+j)|(\d*j))\b)'
269269
_blacklist_re = re.compile(f'{_flow_pat}|{_dunder_pat}|{_attr_pat}')
270270

271271
def stringToExpression(s, types, context, sanitize: bool=True):

numexpr/tests/test_numexpr.py

+3
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,9 @@ def test_sanitize(self):
583583
evaluate('1.5j')
584584
evaluate('3.j')
585585

586+
#pass imaginary with scientific notation
587+
evaluate('1.2e3+4.5e6j')
588+
586589
# pass forbidden characters within quotes
587590
x = np.array(['a', 'b'], dtype=bytes)
588591
evaluate("x == 'b:'")

0 commit comments

Comments
 (0)