Add/reorganize scalar Timedelta tests
State: closed

- [ ] closes #xxxx (Replace xxxx with the Github issue number)
- [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature
- [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).
- [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.

This is a companion of sorts to https://github.com/pandas-dev/pandas/pull/46854. It adds more thorough tests, and groups them by type, but doesn't change any behavior.

/cc @jbrockmendel @jreback 


Labels:
name: Testing
description: pandas testing functions or related to the test suite
name: Timedelta
description: Timedelta data type

Comments:
Hello @patrickmckenna! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:















There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers: 

##### Comment last updated at 2022-05-17 01:55:27 UTC
it looks like this PR has evolved to involve a lot of stuff.  i'd suggest breaking it into tightly-scoped pieces for easier (faster) review
> it looks like this PR has evolved to involve a lot of stuff. i'd suggest breaking it into tightly-scoped pieces for easier (faster) review

Yes, it's comically large at the moment, apologies. Fully understand and agree it needs to be smaller to make review not a PITA. (I'd been keeping it open, as a draft, to simplify running the full test suite as I iterated on a few ideas.)

I'll push a few more changes and add some high-level comments shortly, to figure out how best to split this up.

It's a tale of two cities on the perf front. A local run just now:

```
       before           after         ratio
     [c22bc653]       [99f927ee]
     <td64-tests^2>       <td64-tests>
+      2.97±0.2μs      4.66±0.08μs     1.57  tslibs.timedelta.TimedeltaConstructor.time_from_missing
+     7.85±0.05μs         11.5±2μs     1.47  tslibs.timedelta.TimedeltaConstructor.time_from_string
+     3.59±0.06μs      5.18±0.06μs     1.44  tslibs.timedelta.TimedeltaConstructor.time_from_np_timedelta
-        8.78±1μs      7.17±0.09μs     0.82  tslibs.timedelta.TimedeltaConstructor.time_from_unit
-      8.54±0.8μs      5.66±0.03μs     0.66  tslibs.timedelta.TimedeltaConstructor.time_from_components
-      6.87±0.5μs      1.57±0.02μs     0.23  tslibs.timedelta.TimedeltaConstructor.time_from_int
```

Looking into the regressions.
> Looking into the regressions.

Better now:

```
> asv continuous -f 1.1 upstream/main HEAD -b tslibs.timedelta.TimedeltaConstructor
...
       before           after         ratio
     [a853022e]       [d0967da6]
                      <tmp/td64-perf>
-        15.4±2μs       11.2±0.7μs     0.73  tslibs.timedelta.TimedeltaConstructor.time_from_iso_format
-      8.72±0.8μs       5.75±0.2μs     0.66  tslibs.timedelta.TimedeltaConstructor.time_from_components
-      8.20±0.4μs       5.06±0.3μs     0.62  tslibs.timedelta.TimedeltaConstructor.time_from_string
-      6.52±0.1μs       1.60±0.2μs     0.25  tslibs.timedelta.TimedeltaConstructor.time_from_int
-      3.24±0.3μs          744±6ns     0.23  tslibs.timedelta.TimedeltaConstructor.time_from_missing

SOME BENCHMARKS HAVE CHANGED SIGNIFICANTLY.
PERFORMANCE INCREASED.
```
> > it looks like this PR has evolved to involve a lot of stuff. i'd suggest breaking it into tightly-scoped pieces for easier (faster) review
> 
> Yes, it's comically large at the moment, apologies. Fully understand and agree it needs to be smaller to make review not a PITA. (I'd been keeping it open, as a draft, to simplify running the full test suite as I iterated on a few ideas.)
> 
> I'll push a few more changes and add some high-level comments shortly, to figure out how best to split this up.

I've extracted the functional updates, which touch many fewer lines, into https://github.com/pandas-dev/pandas/pull/47004, so this PR can focus on de-duping/expanding test coverage.
Once https://github.com/pandas-dev/pandas/pull/46854 and https://github.com/pandas-dev/pandas/pull/47004 merge, I can drastically cut the scope of this PR, and focus it on just consolidating/deduping scalar `Timedelta` tests. In particular, my thought is to move everything from `timedelta/test_{constructors,formats}.py` to `timedelta/test_timedelta.py`, to avoid having related yet incomplete test cases spread across three modules.

If that's not useful, or isn't worth prioritizing, please LMK.
> If that's not useful, or isn't worth prioritizing, please LMK.

honestly im having trouble motivating myself to carefully review this, but i'll give it another go once the other PRs are done. id advise against spending much time here in the interim
Think it might be easier to just close this for now. If there are elements worth reviewing and merging, they can always be cherry-picked into a much more narrowly-scoped PR. Or this can be reopened.

(As mentioned, I left this open in its current form only to simplify checking CI results especially the Windows and 32-bit runs. But it's probably too big now to easily whittle down into something reasonable and useful.)