ENH: Add divmod to series. by llllllllll · Pull Request #14208 · pandas-dev/pandas (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation22 Commits1 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

llllllllll

jreback

@@ -2952,3 +2952,19 @@ def __init__(self, *args, **kwargs):
# Add arithmetic!
ops.add_flex_arithmetic_methods(Series, **ops.series_flex_funcs)
ops.add_special_arithmetic_methods(Series, **ops.series_special_funcs)
def _construct_divmod_result(left, result, index, name, dtype):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be in ops.py

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just _construct_divmod_result or the line below as well?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of the ops are defined there

@codecov-io

Current coverage is 85.24% (diff: 100%)

Merging #14208 into master will increase coverage by <.01%

@@ master #14208 diff @@

Files 140 140
Lines 50559 50567 +8
Methods 0 0
Messages 0 0
Branches 0 0

Powered by Codecov. Last update 5e2f9da...08b3939

@llllllllll

I moved this into add_special_arithmetic_methods

jreback

@@ -168,6 +169,9 @@ def add_special_arithmetic_methods(cls, arith_method=None,
f(op, name, str_rep, default_axis=None, fill_zeros=None, **eval_kwargs)
comp_method : function, optional,
factory for rich comparison - signature: f(op, name, str_rep)
divmod_method : function, (optional)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need a separate method here? cannot this be piggy-packed on arithmetic?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if we wanted the API for dataframes to be a return of a tuple with the div result and the mod result but for consistency it could work. Also, there is no reflected or inplace divmod. I construct this function from _arith_method_SERIES right now but could move this into _create_methods

@llllllllll

I added divmod to indices and made it less special for series. I don't see a simple way to get divmod on dataframe right now though.

@llllllllll

jreback

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -3478,6 +3478,15 @@ def _evaluate_numeric_binop(self, other):
cls.__rdiv__ = _make_evaluate_binop(
operator.div, '__div__', reversed=True)
def divmod_constructor(result, **attrs):
return Index(result[0], **attrs), Index(result[1], **attrs)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think put the function in-line (as a lambda), since they are grouped might be more clear (but if not, then go with what you have)

@@ -1328,6 +1328,9 @@ Other API Changes
- ``pd.read_csv()`` in the C engine will now issue a ``ParserWarning`` or raise a ``ValueError`` when ``sep`` encoded is more than one character long (:issue:`14065`)
- ``DataFrame.values`` will now return ``float64`` with a ``DataFrame`` of mixed ``int64`` and ``uint64`` dtypes, conforming to ``np.find_common_type`` (:issue:`10364`, :issue:`13917`)
- ``pd.read_stata()`` can now handle some format 111 files, which are produced by SAS when generating Stata dta files (:issue:`11526`)
- ``Series`` and ``Index`` now support ``divmod`` which will return a tuple of
series or indices. This behaves like a standard binary operator with regards

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might need a mention in the docs somewhere (maybe in binary ops section) of basics?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

jorisvandenbossche

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor typo, for the rest looks good!

.. ipython:: python
div, rem = divmod(s, [2, 2, 3, 3, 4, 4, 5, 5, 6, 6]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing trailing parenthesis here

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated. I also built the docs locally and it seemed correct.

@llllllllll

The clang build seemed to hang here, can we rerun it?

@llllllllll

Thank you for rerunning, looks to be passing now

@llllllllll

@jreback

@llllllllll

yarikoptic added a commit to neurodebian/pandas that referenced this pull request

Oct 13, 2016

@yarikoptic