Skip to content

Behavior of numeric ops on Index has changed #8608

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
bryevdv opened this issue Oct 23, 2014 · 4 comments · Fixed by #8634
Closed

Behavior of numeric ops on Index has changed #8608

bryevdv opened this issue Oct 23, 2014 · 4 comments · Fixed by #8634
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@bryevdv
Copy link

bryevdv commented Oct 23, 2014

The following used to work:

In [7]: import pandas as pd

In [8]: import numpy as np

In [9]: a = np.zeros(5, dtype=np.float)

In [10]: df = pd.DataFrame({"foo": [10, 20, 30, 40, 50]})

In [11]: df.index
Out[11]: Int64Index([0, 1, 2, 3, 4], dtype='int64')

In [12]: df.index * 3.2
Out[12]: Int64Index([0.0, 3.2, 6.4, 9.6, 12.8], dtype='float64')

In [13]: a - df.index * 3.2
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-8a6574b7beca> in <module>()
----> 1 a - df.index * 3.2

TypeError: unsupported operand type(s) for -: 'numpy.ndarray' and 'Int64Index'

In [14]: pd.__version__
Out[14]: '0.15.0'
@jorisvandenbossche jorisvandenbossche added the Regression Functionality that used to work in a prior pandas version label Oct 23, 2014
@jorisvandenbossche jorisvandenbossche added this to the 0.15.1 milestone Oct 23, 2014
@jreback
Copy link
Contributor

jreback commented Oct 23, 2014

@bryevdv workaround till fixed is this:

In [19]: a-df.index.to_series()*3.2
Out[19]: 
0     0.0
1    -3.2
2    -6.4
3    -9.6
4   -12.8
dtype: float64

@jreback jreback added the Indexing Related to indexing on series/frames, not to indexes themselves label Oct 23, 2014
@TomAugspurger
Copy link
Contributor

also

In [23]: np.subtract(a, df.index) * 3.2
Out[23]: Int64Index([0.0, -3.2, -6.4, -9.6, -12.8], dtype='float64')

@cpcloud
Copy link
Member

cpcloud commented Oct 23, 2014

Also strange that it's returning an integer index with float values.

@bryevdv
Copy link
Author

bryevdv commented Oct 23, 2014

Yes that's why I included that line but I should have mentioned explicitly.

On Oct 23, 2014, at 07:17, Phillip Cloud [email protected] wrote:

Also strange that it's returning an integer index with float values.


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants