BUG: Fixes rounding error in Timestamp.floor()
State: closed

- [x] closes #19206 
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry


Labels:
name: Datetime
description: Datetime data dtype
name: Dtype Conversions
description: Unexpected or buggy dtype conversions

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

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

```diff
@@            Coverage Diff             @@
##           master   #19240      +/-   ##
==========================================
+ Coverage    91.6%   91.62%   +0.02%     
==========================================
  Files         150      150              
  Lines       48750    48742       -8     
==========================================
+ Hits        44657    44661       +4     
+ Misses       4093     4081      -12
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.99% <100%> (+0.02%)` | :arrow_up: |
| #single | `41.76% <50%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/19240?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/19240/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZWxpa2UucHk=) | `97.05% <100%> (-0.05%)` | :arrow_down: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/19240/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `66.95% <0%> (+1.73%)` | :arrow_up: |

------

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

Probably a separate issue, but there appears to be no warning if you specify a Timestamp with a string that causes the underlying int64 to overflow. This works:
```
In [135]: pd.Timestamp(9223372036854775807)
Out[135]: Timestamp('2262-04-11 23:47:16.854775807')

In [136]: pd.Timestamp(9223372036854775808)
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
<ipython-input-136-49b799c43d55> in <module>()
----> 1 pd.Timestamp(9223372036854775808)
pandas/_libs/tslib.pyx in pandas._libs.tslib.Timestamp.__new__ (pandas/_libs/tslib.c:10051)()
pandas/_libs/tslib.pyx in pandas._libs.tslib.convert_to_tsobject (pandas/_libs/tslib.c:27665)()
OverflowError: Python int too large to convert to C long
```
but this is silent:
```
In [138]: pd.Timestamp('2262-04-11 23:47:16.854775807')
Out[138]: Timestamp('2262-04-11 23:47:16.854775807')

In [139]: pd.Timestamp('2262-04-11 23:47:16.854775808')
Out[139]: Timestamp('2262-04-11 23:47:16.854775')
```
Shouldn't this throw an exception?
Hello @cbertinato! Thanks for updating the PR.







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

##### Comment last updated on February 07, 2018 at 14:29 Hours UTC
@cbertinato this is all correct
```
In [1]: pd.Timestamp.max
Out[1]: Timestamp('2262-04-11 23:47:16.854775807')

In [2]: pd.Timestamp.max.value
Out[2]: 9223372036854775807

In [3]: pd.Timestamp(pd.Timestamp.max.value)
Out[3]: Timestamp('2262-04-11 23:47:16.854775807')

In [4]: pd.Timestamp(pd.Timestamp.max.value + 1)
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
<ipython-input-4-cef6abffd699> in <module>()
----> 1 pd.Timestamp(pd.Timestamp.max.value + 1)

~/pandas/pandas/_libs/tslibs/timestamps.pyx in pandas._libs.tslibs.timestamps.Timestamp.__new__()
    579             tz, tzinfo = tzinfo, None
    580 
--> 581         ts = convert_to_tsobject(ts_input, tz, unit, 0, 0)
    582 
    583         if ts.value == NPY_NAT:

~/pandas/pandas/_libs/tslibs/conversion.pyx in pandas._libs.tslibs.conversion.convert_to_tsobject()
    287         else:
    288             ts = ts * cast_from_unit(None, unit)
--> 289             obj.value = ts
    290             dt64_to_dtstruct(ts, &obj.dts)
    291     elif is_float_object(ts):

OverflowError: Python int too large to convert to C long

In [5]: pd.Timestamp('2262-04-11 23:47:16.854775808')
Out[5]: Timestamp('2262-04-11 23:47:16.854775')

In [6]: pd.Timestamp('2262-04-11 23:47:16.854775808').value
Out[6]: 9223372036854775000
```

[138] & [139] might be some nanosecond rounding; I suppose you could make an issue about it
Moved the function common to both Timestamps and DTIs out of the Timestamp round function, but left it in timestamp.pyx. Not sure whether to move it out of there completely. Also moved all tests into the refactored test modules.
thanks @cbertinato nice patch! keep em coming!