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

Nathaniel Smith njs at pobox.com
Tue Jan 3 18:05:09 EST 2017


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:

>
> On Tue, 03 Jan 2017, Stephan Hoyer wrote:
>
> >    On Tue, Jan 3, 2017 at 9:00 AM, Yaroslav Halchenko <
> lists at onerussian.com>
> >    wrote:
>
> >      Sorry for coming too late to the discussion and after PR
> "addressing"
> >      the issue by issuing an error was merged [1].A  I got burnt by new
> >      behavior while trying to build fresh pandas release on Debian (we
> are
> >      freezing for release way too soon ;) ) -- some pandas tests failed
> since
> >      they rely on previous non-erroring behavior and we gotA  numpy
> 1.12.0~b1
> >      which included [1] in unstable/testing (candidate release) now.
>
> >      I quickly glanced over the discussion but I guess I have missed
> >      actual description of the problem being fixed here...A  what was
> it??
>
> >      previous behavior, int**int->int made sense to me as it seemed to be
> >      consistent with casting Python's pow result to int, somewhat
> fulfilling
> >      desired promise for in-place operations and being inline with
> built-in
> >      pow results as far as I see it (up to casting).
>
> >    I believe this is exactly the behavior we preserved. Rather, we turned
> >    some cases that previously often gave wrong results (involving
> negative
> >    integer powers) into errors.
>
> 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?
>
> >    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.
>
>
> and being paranoid, I have rebuilt exact current master  of pandas with
> master numpy in PYTHONPATH:
>
> (git)hopa:~exppsy/pandas[master]git
> $> PYTHONPATH=/home/yoh/proj/numpy 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.
>
> ----------------------------------------------------------------------
> Ran 1 test in 0.015s
>
> FAILED (errors=1)
>
> $> git describe --tags
> v0.19.0-303-gb957f6f
>
> $> PYTHONPATH=/home/yoh/proj/numpy 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.
>
>
> --
> Yaroslav O. Halchenko
> Center for Open Neuroscience     http://centerforopenneuroscience.org
> Dartmouth College, 419 Moore Hall, Hinman Box 6207, Hanover, NH 03755
> Phone: +1 (603) 646-9834                       Fax: +1 (603) 646-1419
> WWW:   http://www.linkedin.com/in/yarik
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> https://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20170103/0f05e9e5/attachment.html>


More information about the NumPy-Discussion mailing list