Skip to content

Int64Index does not support modulo operator under pandas 0.15 #10786

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
nmusolino opened this issue Aug 10, 2015 · 1 comment
Closed

Int64Index does not support modulo operator under pandas 0.15 #10786

nmusolino opened this issue Aug 10, 2015 · 1 comment
Labels
Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves

Comments

@nmusolino
Copy link
Contributor

In pandas 0.15, a DataFrame's index no longer supports the modulo operator. I believe the following code used to work under pandas 0.14, but under pandas 0.15, a TypeError indicating "unsupported operand types" is raised:

In [1]: import pandas                                                                                                                                                                                                                        

In [2]: print pandas.version.version                                                                                                                                                                                                         
0.15.2

In [3]: df = pandas.DataFrame({ 'i': xrange(10) })                                                                                                                                                                                           

In [4]: df.index                                                                                                                                                                                                                             
Out[4]: Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype='int64')

In [5]: r = df.index % 2                                                                                                                                                                                                                     
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-405b698d3a56> in <module>()
----> 1 r = df.index % 2

TypeError: unsupported operand type(s) for %: 'Int64Index' and 'int'

In [6]: r = df.index.to_series() % 2

In [7]: 

Line 6 shows that a workaround exists, using the to_series() function.

This issue is very similar to Issue #8608, which dealt with other arithemtic operations on an index. Pandas commit 2fcbc7f fixed that issue by adding addition, subtraction, multiplication, division, and unary operators, but not the modulo operator.

@jorisvandenbossche
Copy link
Member

This is a duplicate of #9244, so closing.
But thanks for the report!

@jorisvandenbossche jorisvandenbossche added Indexing Related to indexing on series/frames, not to indexes themselves Duplicate Report Duplicate issue or pull request labels Aug 10, 2015
@jorisvandenbossche jorisvandenbossche added this to the No action milestone Aug 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

No branches or pull requests

2 participants