Skip to content

Using the python power operator on numerical Index objects yields unexpected results #14973

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
sadruddin opened this issue Dec 23, 2016 · 3 comments
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations
Milestone

Comments

@sadruddin
Copy link

sadruddin commented Dec 23, 2016

Code Sample, a copy-pastable example if possible

index = pd.Float64Index(range(1, 11))

expected_pow_values = 2.0**index.values
actual_pow_values = 2.0**index
similar_pow_values = 2.0**np.arange(len(index))

expected_mul_values = 2.0*index.values
actual_mul_values = 2.0*index

other_way_around = index**2.0
same_as = index.values**2.0

Problem description

Using the pow '**' operator on an index object results in a behaviour different than when using the '' operator. The pow result implies that the values being used are not index.values, which one would expect given the behaviour of other operators (, -, +, / ...).
This problem only arises when the index object is the second argument.

Expected Output

expected output would be the result of 2.0**index.values

Output of pd.show_versions()

commit: None
python: 2.7.13.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 42 Stepping 7, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.19.1
nose: None
pip: 9.0.1
setuptools: 32.2.0
Cython: None
numpy: 1.12.0rc1
scipy: 0.18.1
statsmodels: 0.8.0rc1
xarray: None
IPython: 5.1.0
sphinx: 1.4.8
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.3
openpyxl: 2.4.1
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: None
lxml: 3.7.0
bs4: None
html5lib: 0.9999999
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None

@sadruddin sadruddin changed the title Using the python exponent operator on numerical Index objects yields unexpected results Using the python power operator on numerical Index objects yields unexpected results Dec 23, 2016
@jreback
Copy link
Contributor

jreback commented Dec 23, 2016

https://github.com/pandas-dev/pandas/blob/master/pandas/indexes/base.py#L3537

rpow needs to be a separate function (with reversed=True) as this is not a communative operation (unlike mul).

want to do a PR?

@jreback jreback added Bug Difficulty Novice Numeric Operations Arithmetic, Comparison, and Logical operations labels Dec 23, 2016
@jreback jreback added this to the Next Major Release milestone Dec 23, 2016
@kamal94
Copy link
Contributor

kamal94 commented Dec 24, 2016

I can work on this if no one is..?

@sadruddin
Copy link
Author

That would be great! I wouldn't have been able to look at it to try and fix it until the next couple of weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants