More tslibs TODOS: small optimizations, trim namespaces
State: closed

A few methods of `Timedelta` and `Timestamp` that don't need to be user-facing are changed from `cpdef` to `cdef`.  To make the wheels turn, `Timestamp` methods that _call_ those methods are moved from `Timestamp` to `_Timestamp`.

Stronger typing for `_Timestamp. _get_start_end_field` and a couple others.

`@cython.final` supposedly allows for a small optimization because cython does not need to check at runtime whether a method has been overridden.  Applied to `Timestamp.__add__`, `Timestamp.__sub__`



Labels:
name: Datetime
description: Datetime data dtype
name: Clean

Comments:
Asked on the cython mailing list: turns out `@cython.final` doesn't apply to special methods including `__add__` and `__sub__`.  Will remove.
Looks like because of cython implementation details, making `_round` cdef (and therefore not in the namespace) requires setting default values for `freq` in round, ceil, floor methods.  Any objection to making those default to "D"?
> Looks like because of cython implementation details, making _round cdef (and therefore not in the namespace) requires setting default values for freq in round, ceil, floor methods. Any objection to making those default to "D"?

don't set defaults, this is a required user-settable parameter. move them back to the class impl. not really sure these belong in the c class def anyhow (no benefit).
> move them back to the class impl. not really sure these belong in the c class def anyhow (no benefit).

Sure.  The idea was to get `_round` out of the user-facing namespace.  Not that big a deal.  Will change shortly.
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=h1) Report
> Merging [#18446](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/fedc503f0d25b04850a931398fc0556d892d69ea?src=pr&el=desc) will **increase** coverage by `0.17%`.
> The diff coverage is `n/a`.

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

```diff
@@            Coverage Diff             @@
##           master   #18446      +/-   ##
==========================================
+ Coverage   91.35%   91.53%   +0.17%     
==========================================
  Files         163      163              
  Lines       49691    50730    +1039     
==========================================
+ Hits        45397    46437    +1040     
+ Misses       4294     4293       -1
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.38% <ø> (+0.24%)` | :arrow_up: |
| #single | `39.66% <ø> (-0.08%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.8% <0%> (-0.1%)` | :arrow_down: |
| [pandas/core/indexes/multi.py](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9tdWx0aS5weQ==) | `96.4% <0%> (-0.01%)` | :arrow_down: |
| [pandas/core/api.py](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXBpLnB5) | `100% <0%> (ø)` | :arrow_up: |
| [pandas/io/pytables.py](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree#diff-cGFuZGFzL2lvL3B5dGFibGVzLnB5) | `92.84% <0%> (ø)` | :arrow_up: |
| [pandas/core/reshape/api.py](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9hcGkucHk=) | `100% <0%> (ø)` | :arrow_up: |
| [pandas/core/sparse/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3BhcnNlL2ZyYW1lLnB5) | `94.78% <0%> (ø)` | :arrow_up: |
| [pandas/io/parsers.py](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree#diff-cGFuZGFzL2lvL3BhcnNlcnMucHk=) | `95.59% <0%> (ø)` | :arrow_up: |
| [pandas/core/reshape/melt.py](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9tZWx0LnB5) | `96.22% <0%> (+0.03%)` | :arrow_up: |
| [pandas/core/indexes/interval.py](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9pbnRlcnZhbC5weQ==) | `92.64% <0%> (+0.11%)` | :arrow_up: |
| ... and [4 more](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18446?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/18446?src=pr&el=footer). Last update [fedc503...e4d5f7f](https://codecov.io/gh/pandas-dev/pandas/pull/18446?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/18446?src=pr&el=h1) Report
> Merging [#18446](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/fedc503f0d25b04850a931398fc0556d892d69ea?src=pr&el=desc) will **increase** coverage by `0.17%`.
> The diff coverage is `n/a`.

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

```diff
@@            Coverage Diff             @@
##           master   #18446      +/-   ##
==========================================
+ Coverage   91.35%   91.53%   +0.17%     
==========================================
  Files         163      163              
  Lines       49691    50730    +1039     
==========================================
+ Hits        45397    46437    +1040     
+ Misses       4294     4293       -1
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.38% <ø> (+0.24%)` | :arrow_up: |
| #single | `39.66% <ø> (-0.08%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.8% <0%> (-0.1%)` | :arrow_down: |
| [pandas/core/indexes/multi.py](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9tdWx0aS5weQ==) | `96.4% <0%> (-0.01%)` | :arrow_down: |
| [pandas/io/pytables.py](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree#diff-cGFuZGFzL2lvL3B5dGFibGVzLnB5) | `92.84% <0%> (ø)` | :arrow_up: |
| [pandas/io/parsers.py](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree#diff-cGFuZGFzL2lvL3BhcnNlcnMucHk=) | `95.59% <0%> (ø)` | :arrow_up: |
| [pandas/core/reshape/api.py](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9hcGkucHk=) | `100% <0%> (ø)` | :arrow_up: |
| [pandas/core/api.py](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXBpLnB5) | `100% <0%> (ø)` | :arrow_up: |
| [pandas/core/sparse/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3BhcnNlL2ZyYW1lLnB5) | `94.78% <0%> (ø)` | :arrow_up: |
| [pandas/core/reshape/melt.py](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9tZWx0LnB5) | `96.22% <0%> (+0.03%)` | :arrow_up: |
| [pandas/core/indexes/interval.py](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9pbnRlcnZhbC5weQ==) | `92.64% <0%> (+0.11%)` | :arrow_up: |
| ... and [4 more](https://codecov.io/gh/pandas-dev/pandas/pull/18446?src=pr&el=tree-more) | |

------

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

> why do we care about _get_start_end_field in the user namespace, its a private method?

Not sure anymore.  I probably put it on the todo list in my youth.  Will mark it as fine-as-is.

> type declarations are fine (pls run an asv to confirm)

OK.  I'll close this for now and circle back; avoid clogging the CI queue.