Add more overflow tests for timedelta64 operations
State: closed

- [ ] closes #xxxx (Replace xxxx with the Github issue number)
- [x] [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
- [x] 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 PR adds more specific tests, to verify the current, sometimes inconsistent behavior. Much of it has been reported/discussed in previous threads, and some appears to reflect intentional tradeoffs, e.g. allowing rounding error to avoid overflows. Other behavior seems likely unintentional:

- Inconsistent usage of `ValueError` and `OverflowError`
- Spurious `OverflowError`s for 1-element `Series` w/ valid values

Since this is my first time poking around pandas/numpy internals, it seemed best to make sure the right tests are in the right places before attempting any fixes.



### Open Questions
- What exception should be raised if `Series.sum()` would yield an invalid `Timedelta`: `ValueError`, `OutOfBoundsTimedelta`, something else? (I can rewrite the tests to mark those cases that currently raise the "wrong" exception as `xfail` for now.)
- Is silently introducing rounding error considered ok, or should a warning be emitted?
- Is this the right spot for these tests? AFAICT, a lot of this behavior is determined by `pandas.core.nanops`, particularly special-casing of `timedelta64` in `nansum()`: https://github.com/pandas-dev/pandas/blob/4cf8d55b1549be756857d82480afec7072028a73/pandas/core/nanops.py#L618-L621 My assumption was that tests against the public API would be preferred, but please LMK if that's not the case.



### Prior Art
- https://github.com/pandas-dev/pandas/issues/43178
- https://github.com/pandas-dev/pandas/issues/9442
- https://github.com/pandas-dev/pandas/pull/10926

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

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-15 19:13:51 UTC
i'll take a look today
My inclination is to avoid making the new file, keep reduction tests in test_reductions, arithmetic tests in tests.arithmetic, scalar tests in tests.scalar.timedelta

OK, i've done a lot of nitpicking, time for some positive reinforcement.  thanks for the PR!  getting consistent exceptions and messages is not easy, glad to have you working on it
> OK, i've done a lot of nitpicking, time for some positive reinforcement. thanks for the PR! getting consistent exceptions and messages is not easy, glad to have you working on it

Happy to help, and thanks for the specific feedback! (FWIW, I appreciate the detailed guidance, especially when jumping into a new-to-me codebase 😀)
will take another look tomorrow
@jbrockmendel happy for you to merge this when you are ready
> happy for you to merge this when you are ready

@jreback appreciate that! Alas, no green button for me&mdash;I haven't got write access 🙃
> > happy for you to merge this when you are ready
> 
> @jreback appreciate that! Alas, no green button for me—I haven't got write access 🙃

@patrickmckenna that was to @jbrockmendel  :->
Hah, whoops! 🤦‍♂️😅 
Please LMK if there's more that needs doing here. Unsure what to do about the few red x's, which appear to be (transient?) failures during CI setup.
This pull request is stale because it has been open for thirty days with no activity. Please [update](https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#updating-your-pull-request) and respond to this comment if you're still interested in working on this.
Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen.