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 }})
@@ -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
Current coverage is 85.24% (diff: 100%)
@@ master #14208 diff @@
Files 140 140
Lines 50559 50567 +8
Methods 0 0
Messages 0 0
Branches 0 0
- Hits 43099 43107 +8
Misses 7460 7460
Partials 0 0
Powered by Codecov. Last update 5e2f9da...08b3939
I moved this into add_special_arithmetic_methods
@@ -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
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.
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
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.
The clang build seemed to hang here, can we rerun it?
Thank you for rerunning, looks to be passing now
yarikoptic added a commit to neurodebian/pandas that referenced this pull request
- commit 'v0.19.0rc1-25-ga7469cf': (471 commits) ENH: Add divmod to series and index. (pandas-dev#14208) Fix generator tests to run (pandas-dev#14245) BUG: GH13629 Binned groupby median function with empty bins (pandas-dev#14225) TST/TEMP: fix pyqt to 4.x for plotting tests (pandas-dev#14240) DOC: added example to Series.map showing use of na_action parameter (GH14231) DOC: split docstring into multiple lines in excel.py (pandas-dev#14073) MAINT: Use module in _DeprecatedModule. (pandas-dev#14181) ENH: Allow true_values and false_values options in read_excel (pandas-dev#14002) DOC: fix incorrect example in unstack docstring (GH14206) (pandas-dev#14211) BUG: iloc fails with non lex-sorted MultiIndex pandas-dev#13797 BUG: add check for infinity in call of EngFormatter In gbq.to_gbq allow the DataFrame column order to differ from schema BLD: require cython if tempita is needed DOC: add source links to api docs (pandas-dev#14200) BUG: compat with Stata ver 111 Fix: F999 dictionary key '2000q4' repeated with different values (pandas-dev#14198) BLD: Test for Python 3.5 with C locale BUG: DatetimeTZBlock can't assign values near dst boundary BUG: union_categorical with Series and cat idx BUG: fix str.contains for series containing only nan values ...