WIP: ensure names are pinned correctly
State: closed

Discussed in #24397, this defines a metaclass for PandasObject that does two things:

- at class-definition, iterate over all the methods in the class namespace and assert that the method's `__name__` matches the namespace name.
- define comparisons on the _classes_ so we can simplify the `NotImplemented` checks to `if type(self) < type(other)`

The `__name__` have a whole bunch that currently fail, will whittle those down.

Labels:
name: Bug
name: Internals
description: Related to non-user accessible pandas implementation

Comments:
Hello @jbrockmendel! Thanks for updating the PR.







Cheers ! There are no PEP8 issues in this Pull Request. :beers: 

##### Comment last updated on January 10, 2019 at 02:41 Hours UTC
Are we sure we want pandas objects to have a metaclass? 

Any Python (sub)class may only have one metaclass, so by implementing one in pandas itself we would restrict users of pandas from implementing their own metaclass on subclassed pandas objects, when/if they need it. I think that’s an important issue and makes me leaning on -1 on this.

Can’t these checks not be implemented using other methods, e.g. using simple pytests tests?
> Can’t these checks not be implemented using other methods, e.g. using simple pytests tests?

Yah, I came to the same conclusion and changed the name-checking bit to go into tests.base.  The class inequality thing I think is neat, but is really unrelated to the rest of the PR.

> The class inequality thing I think is neat, but is really unrelated to the rest of the PR.

IMO, it’s unconventional, so usage of this pattern will surprise users and require them to dig (quite deep) into the pandas source code to understand what the comparisons mean. I think just using issubclass directly is much better/clearer, and will also leave the metaclass slot open for users to use in their own subclasses.

So, I’m -1 on adding the metaclass to PandasObject...
>  So, I’m -1 on adding the metaclass to PandasObject

While I might want to revisit it at some point, it is definitely not relevant to this PR, so just reverted it.
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24429?src=pr&el=h1) Report
> Merging [#24429](https://codecov.io/gh/pandas-dev/pandas/pull/24429?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/7e64d9c99b14f6596bf1b72e25a7cb451d0159f1?src=pr&el=desc) will **decrease** coverage by `49.3%`.
> The diff coverage is `n/a`.

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

```diff
@@             Coverage Diff             @@
##           master   #24429       +/-   ##
===========================================
- Coverage   92.31%      43%   -49.31%     
===========================================
  Files         163      163               
  Lines       51987    51987               
===========================================
- Hits        47990    22356    -25634     
- Misses       3997    29631    +25634
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `?` | |
| #single | `43% <ø> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24429?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/formats/latex.py](https://codecov.io/gh/pandas-dev/pandas/pull/24429/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvbGF0ZXgucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/core/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/24429/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY2F0ZWdvcmljYWwucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/sas/sas\_constants.py](https://codecov.io/gh/pandas-dev/pandas/pull/24429/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfY29uc3RhbnRzLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/plotting.py](https://codecov.io/gh/pandas-dev/pandas/pull/24429/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvcGxvdHRpbmcucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/24429/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvY29udmVydGVyLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/formats/html.py](https://codecov.io/gh/pandas-dev/pandas/pull/24429/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvaHRtbC5weQ==) | `0% <0%> (-98.65%)` | :arrow_down: |
| [pandas/core/groupby/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/24429/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9jYXRlZ29yaWNhbC5weQ==) | `0% <0%> (-95.46%)` | :arrow_down: |
| [pandas/io/sas/sas7bdat.py](https://codecov.io/gh/pandas-dev/pandas/pull/24429/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXM3YmRhdC5weQ==) | `0% <0%> (-91.17%)` | :arrow_down: |
| [pandas/io/sas/sas\_xport.py](https://codecov.io/gh/pandas-dev/pandas/pull/24429/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfeHBvcnQucHk=) | `0% <0%> (-90.15%)` | :arrow_down: |
| [pandas/core/tools/numeric.py](https://codecov.io/gh/pandas-dev/pandas/pull/24429/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvdG9vbHMvbnVtZXJpYy5weQ==) | `10.44% <0%> (-89.56%)` | :arrow_down: |
| ... and [121 more](https://codecov.io/gh/pandas-dev/pandas/pull/24429/diff?src=pr&el=tree-more) | |

------

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

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

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

```diff
@@            Coverage Diff             @@
##           master   #24429      +/-   ##
==========================================
+ Coverage   92.38%   92.38%   +<.01%     
==========================================
  Files         166      166              
  Lines       52310    52324      +14     
==========================================
+ Hits        48326    48341      +15     
+ Misses       3984     3983       -1
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.8% <100%> (ø)` | :arrow_up: |
| #single | `43.08% <96.42%> (+0.01%)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24429?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/arrays/sparse.py](https://codecov.io/gh/pandas-dev/pandas/pull/24429/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL3NwYXJzZS5weQ==) | `92.17% <100%> (ø)` | :arrow_up: |
| [pandas/core/indexes/frozen.py](https://codecov.io/gh/pandas-dev/pandas/pull/24429/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9mcm96ZW4ucHk=) | `93.33% <100%> (+1.22%)` | :arrow_up: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/24429/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `88.09% <0%> (+0.09%)` | :arrow_up: |

------

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

looks ok, but this raises a number of questions about existing behaviors as you have noted.
Ref #23551 need to see what it would take to handle that here
Do we want to move forward with something like this?  If not let’s close