ENH: Allow Timestamp to accept Nanosecond argument
State: closed

- [x] closes #18898
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

Needed to add a new `nanos` argument to `convert_to_tsobject` arguments from `Timestamp.__new__` dispatches to this function (and `datetime.datetime` cannot take a nanosecond argument).

Labels:
name: Datetime
description: Datetime data dtype
name: API Design

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

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

```diff
@@            Coverage Diff             @@
##           master   #19889      +/-   ##
==========================================
+ Coverage   91.65%   91.68%   +0.02%     
==========================================
  Files         150      150              
  Lines       48915    48915              
==========================================
+ Hits        44835    44847      +12     
+ Misses       4080     4068      -12
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.06% <ø> (+0.02%)` | :arrow_up: |
| #single | `41.83% <ø> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/19889?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/19889/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/19889?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/19889?src=pr&el=footer). Last update [10cc8f4...1c6e23d](https://codecov.io/gh/pandas-dev/pandas/pull/19889?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/19889?src=pr&el=h1) Report
> Merging [#19889](https://codecov.io/gh/pandas-dev/pandas/pull/19889?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/1e4c50a56f7e953ab84308f000dff6fc1ac71171?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `n/a`.

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

```diff
@@            Coverage Diff             @@
##           master   #19889      +/-   ##
==========================================
+ Coverage   91.66%   91.66%   +<.01%     
==========================================
  Files         150      150              
  Lines       48969    48976       +7     
==========================================
+ Hits        44886    44896      +10     
+ Misses       4083     4080       -3
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.04% <ø> (ø)` | :arrow_up: |
| #single | `41.86% <ø> (+0.01%)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/19889?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/19889/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZWxpa2UucHk=) | `96.83% <0%> (-0.5%)` | :arrow_down: |
| [pandas/core/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/19889/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc2VyaWVzLnB5) | `94.24% <0%> (-0.18%)` | :arrow_down: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/19889/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.5% <0%> (-0.11%)` | :arrow_down: |
| [pandas/core/sparse/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/19889/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3BhcnNlL3Nlcmllcy5weQ==) | `95.2% <0%> (-0.05%)` | :arrow_down: |
| [pandas/core/indexes/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/19889/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy90aW1lZGVsdGFzLnB5) | `91.17% <0%> (-0.04%)` | :arrow_down: |
| [pandas/core/strings.py](https://codecov.io/gh/pandas-dev/pandas/pull/19889/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3RyaW5ncy5weQ==) | `98.31% <0%> (ø)` | :arrow_up: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/19889/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.18% <0%> (ø)` | :arrow_up: |
| [pandas/io/parsers.py](https://codecov.io/gh/pandas-dev/pandas/pull/19889/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3BhcnNlcnMucHk=) | `95.32% <0%> (ø)` | :arrow_up: |
| [pandas/core/dtypes/concat.py](https://codecov.io/gh/pandas-dev/pandas/pull/19889/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2NvbmNhdC5weQ==) | `99.16% <0%> (+0.01%)` | :arrow_up: |
| [pandas/core/indexes/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/19889/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9wZXJpb2QucHk=) | `94.65% <0%> (+1.3%)` | :arrow_up: |

------

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

Unfortunately I recently switched to a new environment (Ubuntu app on Windows) and am having some trouble running `asv continuous` (conda related setup issue I think). Here were some `%timeit`s I was able to run in the meantime.

```
This Branch 

In [1]: from pandas import *

In [2]: from datetime import *

In [3]: %timeit Timestamp('2017-08-25 08:16:14')
2.6 µs ± 89.8 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

In [4]: %timeit Timestamp(datetime(2000, 1, 2, 3, 4, 5, 6))
1.67 µs ± 37.6 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

In [6]: %timeit Timestamp(year=2000, month=1, day=2, hour=3, minute=4, second=5, microsecond=6)
3.05 µs ± 88.7 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

In [9]: import pytz

In [10]: %timeit Timestamp(2000, 1, 2, 3, 4, 5, 6, 1, pytz.UTC)
3.32 µs ± 130 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

Master

In [1]: import pytz

In [2]: from pandas import *

In [3]: from datetime import *

In [4]: %timeit Timestamp('2017-08-25 08:16:14')
2.48 µs ± 60.6 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

In [5]: %timeit Timestamp(datetime(2000, 1, 2, 3, 4, 5, 6))
2.08 µs ± 44.3 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

In [6]: %timeit Timestamp(year=2000, month=1, day=2, hour=3, minute=4, second=5, microsecond=6)
3.57 µs ± 84.1 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

In [8]: %timeit Timestamp(2000, 1, 2, 3, 4, 5, 6, pytz.UTC)
3.38 µs ± 57 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
```
Ping, all green
thanks @mroeschke keep em coming!