[Numpy-discussion] numpy vs algebra Was: Integers to negative integer powers...

Stephan Hoyer shoyer at gmail.com
Tue Jan 3 19:09:55 EST 2017


On Tue, Jan 3, 2017 at 3:05 PM, Nathaniel Smith <njs at pobox.com> wrote:

> It's possible we should back off to just issuing a deprecation warning in
> 1.12?
>
> On Jan 3, 2017 1:47 PM, "Yaroslav Halchenko" <lists at onerussian.com> wrote:
>
>> hm... testing on current master (first result is from python's pow)
>>
>> $> python -c "import numpy; print('numpy version: ', numpy.__version__);
>> a=2; b=-2;  print(pow(a,b)); print(pow(numpy.array(a), b))"
>> ('numpy version: ', '1.13.0.dev0+02e2ea8')
>> 0.25
>> Traceback (most recent call last):
>>   File "<string>", line 1, in <module>
>> ValueError: Integers to negative integer powers are not allowed.
>>
>>
>> testing on Debian's packaged beta
>>
>> $> python -c "import numpy; print('numpy version: ', numpy.__version__);
>> a=2; b=-2;  print(pow(a,b)); print(pow(numpy.array(a), b))"
>> ('numpy version: ', '1.12.0b1')
>> 0.25
>> Traceback (most recent call last):
>>   File "<string>", line 1, in <module>
>> ValueError: Integers to negative integer powers are not allowed.
>>
>>
>> testing on stable debian box with elderly numpy, where it does behave
>> sensibly:
>>
>> $> python -c "import numpy; print('numpy version: ', numpy.__version__);
>> a=2; b=-2;  print(pow(a,b)); print(pow(numpy.array(a), b))"
>> ('numpy version: ', '1.8.2')
>> 0.25
>> 0
>>
>> what am I missing?
>>
>>
2 ** -2 should be 0.25.

On old versions of NumPy, you see the the incorrect answer 0. We are now
preferring to give an error rather than the wrong answer.


> >    The pandas test suite triggered this behavior, but not intentionally,
>> and
>> >    should be fixed in the next release:
>> >    https://github.com/pandas-dev/pandas/pull/14498
>>
>> I don't think that was the full set of cases, e.g.
>>
>> (git)hopa/sid-i386:~exppsy/pandas[bf-i386]
>> $> nosetests -s -v pandas/tests/test_expressions.
>> py:TestExpressions.test_mixed_arithmetic_series
>> test_mixed_arithmetic_series (pandas.tests.test_expressions.TestExpressions)
>> ... ERROR
>>
>> ======================================================================
>> ERROR: test_mixed_arithmetic_series (pandas.tests.test_expressions
>> .TestExpressions)
>> ----------------------------------------------------------------------
>> Traceback (most recent call last):
>>   File "/home/yoh/deb/gits/pkg-exppsy/pandas/pandas/tests/test_expressions.py",
>> line 223, in test_mixed_arithmetic_series
>>     self.run_series(self.mixed2[col], self.mixed2[col], binary_comp=4)
>>   File "/home/yoh/deb/gits/pkg-exppsy/pandas/pandas/tests/test_expressions.py",
>> line 164, in run_series
>>     test_flex=False, **kwargs)
>>   File "/home/yoh/deb/gits/pkg-exppsy/pandas/pandas/tests/test_expressions.py",
>> line 93, in run_arithmetic_test
>>     expected = op(df, other)
>>   File "/home/yoh/deb/gits/pkg-exppsy/pandas/pandas/core/ops.py", line
>> 715, in wrapper
>>     result = wrap_results(safe_na_op(lvalues, rvalues))
>>   File "/home/yoh/deb/gits/pkg-exppsy/pandas/pandas/core/ops.py", line
>> 676, in safe_na_op
>>     return na_op(lvalues, rvalues)
>>   File "/home/yoh/deb/gits/pkg-exppsy/pandas/pandas/core/ops.py", line
>> 652, in na_op
>>     raise_on_error=True, **eval_kwargs)
>>   File "/home/yoh/deb/gits/pkg-exppsy/pandas/pandas/computation/expressions.py",
>> line 210, in evaluate
>>     **eval_kwargs)
>>   File "/home/yoh/deb/gits/pkg-exppsy/pandas/pandas/computation/expressions.py",
>> line 63, in _evaluate_standard
>>     return op(a, b)
>> ValueError: Integers to negative integer powers are not allowed.
>>
>
Agreed, it looks like pandas still has this issue in the test suite.
Nonetheless, I don't think this should be an issue for users -- pandas
defines all handling of arithmetic to numpy.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20170103/fa4a6082/attachment.html>


More information about the NumPy-Discussion mailing list