BUG: fix index op names and pinning
State: closed

This is a moderately big one, but changes very little.

Fixes incorrect Index ops names and several methods that are defined but not pinned to the class (#19716).

Avoids the need to pass `reversed` and `str_rep` in a bunch of places, cleans up some of the Index classmethods.

Removes the no-longer-needed catching of AttributeError in RangeIndex ops.

The part that may be controversial (and almost certainly needs new tests) is that `Index.__rsub__` is implemented, since it doesn't currently exist.  This implements it in "the obvious way", but the fact that `Index.__sub__` isn't defined in the obvious way suggests this _might_ not be desired.  Comments welcome.

- [x] closes #19716
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry


Labels:
name: Datetime
description: Datetime data dtype
name: API Design
name: Numeric Operations
description: Arithmetic, Comparison, and Logical operations
name: Timedelta
description: Timedelta data type

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/19723?src=pr&el=h1) Report
> Merging [#19723](https://codecov.io/gh/pandas-dev/pandas/pull/19723?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/b585e3b5145a73cc7480db9a3b0c3ce7bd55511e?src=pr&el=desc) will **increase** coverage by `0.01%`.
> The diff coverage is `92.36%`.

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

```diff
@@            Coverage Diff             @@
##           master   #19723      +/-   ##
==========================================
+ Coverage   91.57%   91.58%   +0.01%     
==========================================
  Files         150      150              
  Lines       48903    48890      -13     
==========================================
- Hits        44785    44778       -7     
+ Misses       4118     4112       -6
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.96% <92.36%> (ø)` | :arrow_up: |
| #single | `41.83% <77.86%> (+0.04%)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/19723?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/19723/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.56% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/19723/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy90aW1lZGVsdGFzLnB5) | `90.63% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/19723/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9wZXJpb2QucHk=) | `93.02% <100%> (+0.14%)` | :arrow_up: |
| [pandas/core/indexes/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/19723/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZWxpa2UucHk=) | `97.33% <100%> (+0.43%)` | :arrow_up: |
| [pandas/core/indexes/range.py](https://codecov.io/gh/pandas-dev/pandas/pull/19723/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9yYW5nZS5weQ==) | `95.63% <85.71%> (-0.11%)` | :arrow_down: |
| [pandas/core/indexes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/19723/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9iYXNlLnB5) | `96.53% <91.3%> (+0.11%)` | :arrow_up: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/19723/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.23% <0%> (ø)` | :arrow_up: |
| ... and [1 more](https://codecov.io/gh/pandas-dev/pandas/pull/19723/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/19723?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/19723?src=pr&el=footer). Last update [b585e3b...0824382](https://codecov.io/gh/pandas-dev/pandas/pull/19723?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

its also not clear the changes are actually being tested.
> its also not clear the changes are actually being tested.

The added parameters in tests.indexes.test_base test the relevant changes here.  That test would fail under the status-quo.
> so leave out the rsub changes for now. the refactor part is ok

OK.  That will require special-casing to escape that case in tests.indexes.test_base; we can revisit later.
This one isn’t particularly conducive to splitting into smaller parts, but I could try if that’ll help.
The reset_index thing looks unrelated.  Am I reading it wrong?
the reset_index is unrelated
the i ops are the relevant parts 
This may be all set.
> pls change this

Sure, to `issubclass(index, ABCIndex)`?  Not worth arguing about, but whats the upside?  It's definitely not clearer (especially b/c it is easy for newcomers to not be aware that ABCIndex doesnt include subclasses)
>  It's definitely not clearer (especially b/c it is easy for newcomers to not be aware that ABCIndex doesnt include subclasses)

I for one didn't know (and wouldn't know directly from reading code, and find it also surprising) that `ABCIndex` is only the Index class and not its subclasses. `type(..) is Index` is much more explicit IMO.
> I for one didn't know (and wouldn't know directly from reading code, and find it also surprising) that ABCIndex is only the Index class and not its subclasses. type(..) is Index is much more explicit IMO.

But I have to agree it is clear from the abc code (I just don't interact much with that part of the code base that needs to use ABCs). I only intuitively would have expected the names to be the other way around :-)
> Does this need a whatsnew note?

I guess its technically user-facing, but it seems like it would be mostly clutter.  I'm fine either way.
needs a rebase
I messed up most recent merge, will fix in AM.
lgtm. ping on green. (I think just appeveyor left).
ping
thanks