Skip to content

Regression: divmod(my_series, some_integer) no longer works since version 0.13. #8174

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
mdickinson opened this issue Sep 4, 2014 · 1 comment · Fixed by #14208
Closed
Labels
API Design Numeric Operations Arithmetic, Comparison, and Logical operations
Milestone

Comments

@mdickinson
Copy link

In Pandas version 0.12, you could apply the Python built-in divmod function to a Series and an integer:

Enthought Canopy Python 2.7.6 | 64-bit | (default, Jun  4 2014, 16:42:26) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> pd.__version__
'0.12.0'
>>> divmod(pd.Series(range(4)), 2)
(0    0
1    0
2    1
3    1
dtype: int64, 0    0
1    1
2    0
3    1
dtype: int64)
>>> 

With version >= 0.13, it appears that this usage is no longer supported:

Enthought Canopy Python 2.7.6 | 64-bit | (default, Jun  4 2014, 16:42:26) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> pd.__version__
'0.14.1'
>>> divmod(pd.Series(range(4)), 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for divmod(): 'Series' and 'int'

Was this change intentional?

Some context: I was using this to read a climate datafile that had a 4-digit column holding combined month and day values. The original code looked something like: month, day = divmod(df['MODA'], 100), but broke after upgrading to version 0.14.

@jreback
Copy link
Contributor

jreback commented Sep 4, 2014

__divmod__ was not included when Series was refactored in 0.13.

You can simply do:

s // 2, s % 2 if you want to get the same results

If you would like to add the method, a PR would be accepted.

I don't think was included as no tests for this (and to be honest never seen it used; its more of a 'functional' way of working with objects)

@jreback jreback added this to the 0.15.1 milestone Sep 4, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 6, 2015
@jreback jreback modified the milestones: 0.19.0, Next Major Release Sep 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants