BUG: divmod return type
State: closed

Closes https://github.com/pandas-dev/pandas/issues/22930

Labels:
name: Numeric Operations
description: Arithmetic, Comparison, and Logical operations
name: ExtensionArray
description: Extending pandas with custom dtypes or arrays.

Comments:
Hello @TomAugspurger! Thanks for submitting the PR.

 - There are no PEP8 issues in the file [`pandas/core/arrays/base.py`](https://github.com/TomAugspurger/pandas/blob/52538fa03a8c9722ab5c86c88419105b6ebfe5a1/pandas/core/arrays/base.py) !

 - There are no PEP8 issues in the file [`pandas/tests/extension/decimal/array.py`](https://github.com/TomAugspurger/pandas/blob/52538fa03a8c9722ab5c86c88419105b6ebfe5a1/pandas/tests/extension/decimal/array.py) !

 - There are no PEP8 issues in the file [`pandas/tests/extension/test_ops.py`](https://github.com/TomAugspurger/pandas/blob/52538fa03a8c9722ab5c86c88419105b6ebfe5a1/pandas/tests/extension/test_ops.py) !


# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22932?src=pr&el=h1) Report
> Merging [#22932](https://codecov.io/gh/pandas-dev/pandas/pull/22932?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/fe67b94e7681c1f21fc2be212514ca0d67a6603c?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/22932/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/22932?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #22932      +/-   ##
==========================================
- Coverage    92.2%   92.19%   -0.01%     
==========================================
  Files         169      169              
  Lines       50822    50837      +15     
==========================================
+ Hits        46858    46870      +12     
- Misses       3964     3967       +3
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.61% <100%> (-0.01%)` | :arrow_down: |
| #single | `42.34% <0%> (-0.02%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/22932?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/arrays/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/22932/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2Jhc2UucHk=) | `95.89% <100%> (+0.17%)` | :arrow_up: |
| [pandas/core/reshape/merge.py](https://codecov.io/gh/pandas-dev/pandas/pull/22932/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9tZXJnZS5weQ==) | `93.89% <0%> (-0.26%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/22932/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `86.18% <0%> (-0.05%)` | :arrow_down: |
| [pandas/core/strings.py](https://codecov.io/gh/pandas-dev/pandas/pull/22932/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3RyaW5ncy5weQ==) | `98.63% <0%> (ø)` | :arrow_up: |
| [pandas/core/dtypes/cast.py](https://codecov.io/gh/pandas-dev/pandas/pull/22932/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2Nhc3QucHk=) | `88.58% <0%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22932?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22932?src=pr&el=footer). Last update [fe67b94...ec814db](https://codecov.io/gh/pandas-dev/pandas/pull/22932?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

FYI, this, and the following are holding up PeriodArray a bit, so if I could get a quick +/- 1 on

- https://github.com/pandas-dev/pandas/pull/22938
- https://github.com/pandas-dev/pandas/pull/22936
- https://github.com/pandas-dev/pandas/pull/22935

it'd be appreciated. (cc @jbrockmendel for this one in particular.)
> FYI, this, and the following are holding up PeriodArray a bit

Just a question, I would expect that Period does not need the ScalarOpsMixin? (it has its own vectorized implementations?)
Hmm, yes you're right. I'll look on my other branch to see if / why I was hitting this...
This may be over-optimizing for code-sharing, but it might be worth updating `ops._construct_result` and `ops._construct_divmod_result` for compat with EA (instead of just `Series`) and use the same pattern as `_arith_method_SERIES`

```
construct_result = (_construct_divmod_result
                    if op is divmod else _construct_result)
```

Now that I look at it, it looks like `ops.dispatch_to_extension_op` hard-codes `_construct_result` so will fail on divmod/rdivmod
Can you add a test that does `divmod(Series[EA], Series[EA])`? (or `divmod(Series[EA], EA)`, or ...).  I think that will necessitate a small fix in `ops.dispatch_to_extension_op`, but that should be fixed at the same time as this.  (or heck, add the test(s) and xfail it and I'll fix it in a follow-up)

Pending that: LGTM.
I'll make those fixes to ops.dispatch_to_extension_op here. Will see what we can share.
Added a test with `divmod(Series[EA], EA])`.

> Now that I look at it, it looks like ops.dispatch_to_extension_op hard-codes _construct_result so will fail on divmod/rdivmod

It seems correct on master, maybe someone (probably you) fixed it in the meantime?

> but it might be worth updating ops._construct_result and ops._construct_divmod_result for compat with EA

Perhaps leave for https://github.com/pandas-dev/pandas/issues/22974, as I think there are some details to work out. I haven't put any tests in place for `divmod(EA, Series[EA])` yet, since I think master is incorrect. Right now that's a tuple of `(EA, EA)`, but should maybe be a tuple of `(Series[EA], Series[EA])`.
> Perhaps leave for #22974, as I think there are some details to work out

Sounds good.
Updated.

1. Deduplicated the try / except, now that we do it in 3 places instead of 2
2. changed some tests that were unexpectedly passing, when they should be skips.
Good to merge this then?