Skip to content

Commit 298b241

Browse files
kamal94jreback
authored andcommitted
BUG: fixed index power operation
The power operation on a range of indexes was fixed. closes #14973 Author: Kamal Kamalaldin <[email protected]> Closes #14996 from kamal94/master and squashes the following commits: 66c2338 [Kamal Kamalaldin] Merge branch 'master' of git://github.com/pandas-dev/pandas 14c47a8 [Kamal Kamalaldin] DOC: updated wording of a previous fix a6c9458 [Kamal Kamalaldin] BUG: fixed index power operation
1 parent 4a4635d commit 298b241

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ Performance Improvements
283283
Bug Fixes
284284
~~~~~~~~~
285285

286+
- Bug in ``Index`` power operations with reversed operands (:issue:`14973`)
286287
- Bug in ``TimedeltaIndex`` addition where overflow was being allowed without error (:issue:`14816`)
287288
- Bug in ``DataFrame`` construction in which unsigned 64-bit integer elements were being converted to objects (:issue:`14881`)
288289
- Bug in ``astype()`` where ``inf`` values were incorrectly converted to integers. Now raises error now with ``astype()`` for Series and DataFrames (:issue:`14265`)

pandas/indexes/base.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -3543,7 +3543,9 @@ def _evaluate_numeric_binop(self, other):
35433543
operator.sub, '__sub__', reversed=True)
35443544
cls.__mul__ = cls.__rmul__ = _make_evaluate_binop(
35453545
operator.mul, '__mul__')
3546-
cls.__pow__ = cls.__rpow__ = _make_evaluate_binop(
3546+
cls.__rpow__ = _make_evaluate_binop(
3547+
operator.pow, '__pow__', reversed=True)
3548+
cls.__pow__ = _make_evaluate_binop(
35473549
operator.pow, '__pow__')
35483550
cls.__mod__ = _make_evaluate_binop(
35493551
operator.mod, '__mod__')

pandas/tests/indexes/test_numeric.py

+9
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ def test_numeric_compat(self):
105105
for r, e in zip(result, expected):
106106
tm.assert_index_equal(r, e)
107107

108+
# test power calculations both ways, GH 14973
109+
expected = pd.Float64Index(2.0**idx.values)
110+
result = 2.0**idx
111+
tm.assert_index_equal(result, expected)
112+
113+
expected = pd.Float64Index(idx.values**2.0)
114+
result = idx**2.0
115+
tm.assert_index_equal(result, expected)
116+
108117
def test_explicit_conversions(self):
109118

110119
# GH 8608

0 commit comments

Comments
 (0)