Skip to content

BUG: power with integer arrays giving confusing error #379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jorisvandenbossche opened this issue Apr 1, 2021 · 1 comment
Closed

BUG: power with integer arrays giving confusing error #379

jorisvandenbossche opened this issue Apr 1, 2021 · 1 comment

Comments

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Apr 1, 2021

Consider the following example:

import numpy as np
import numexpr as na

The power operation with an integer array and a scalar works:

In [60]: array = np.arange(20)
    ...: print(ne.evaluate("array ** 1"))
[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19]

But with two integer arrays I get a (wrong) error message:

In [61]: array = np.arange(20)
    ...: print(ne.evaluate("array ** array"))
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/miniconda3/envs/dev/lib/python3.7/site-packages/numexpr/necompiler.py in evaluate(ex, local_dict, global_dict, out, order, casting, **kwargs)
    826     try:
--> 827         compiled_ex = _numexpr_cache[numexpr_key]
    828     except KeyError:

KeyError: ('array ** array', (('optimization', 'aggressive'), ('truediv', False)), (('array', <class 'numpy.int64'>),))

During handling of the above exception, another exception occurred:
...

~/miniconda3/envs/dev/lib/python3.7/site-packages/numexpr/expressions.py in pow_op(a, b)
    287         b.astKind in ('int', 'long') and
    288         a.astKind in ('int', 'long') and
--> 289         numpy.any(b.value < 0)):
    290 
    291         raise ValueError(

TypeError: '<' not supported between instances of 'str' and 'int'

While power with 2 float arrays works fine:

In [62]: array = np.arange(20, dtype="float64")
    ...: print(ne.evaluate("array ** array"))
[1.00000000e+00 1.00000000e+00 4.00000000e+00 2.70000000e+01
 2.56000000e+02 3.12500000e+03 4.66560000e+04 8.23543000e+05
 1.67772160e+07 3.87420489e+08 1.00000000e+10 2.85311671e+11
 8.91610045e+12 3.02875107e+14 1.11120068e+16 4.37893890e+17
 1.84467441e+19 8.27240262e+20 3.93464081e+22 1.97841966e+24]

It could be that array ** array isn't implemented for integer arrays, but then the error message is a bit confusing.

I am using numexpr 2.7.3 on Linux (Ubuntu), installed from conda-forge.

@robbmcleod
Copy link
Member

This is a duplicate of #434 (or rather the other way around). Since this one fell through the cracks whereas #434 has a lively discussion I'll close this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants