Skip to content

Commit

Permalink
fix imaginary evaluation 1.1e1j
Browse files Browse the repository at this point in the history
  • Loading branch information
27rabbitlt committed Dec 20, 2024
1 parent 2378606 commit b1a916c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion numexpr/necompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def __str__(self):

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

def stringToExpression(s, types, context, sanitize: bool=True):
Expand Down
3 changes: 3 additions & 0 deletions numexpr/tests/test_numexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@ def test_sanitize(self):
evaluate('1.5j')
evaluate('3.j')

#pass imaginary with scientific notation
evaluate('1.2e3+4.5e6j')

# pass forbidden characters within quotes
x = np.array(['a', 'b'], dtype=bytes)
evaluate("x == 'b:'")
Expand Down

0 comments on commit b1a916c

Please sign in to comment.