PERF: do NPY_NAT check inside get_datetime64_nanos
State: closed

Bonus of a little simplification in `array_to_datetime`

The perf pickup comes from changing a python call `ts.view('i8')` to a cython call `get_datetime64_value(ts)`.

```
In [3]: val = np.datetime64('NaT', 'D')
In [4]: %timeit pd.Timestamp(val)
```

master (leaving out "The slowest run [...]"
```
100000 loops, best of 3: 2.33 µs per loop
1000000 loops, best of 3: 2.02 µs per loop
100000 loops, best of 3: 2.44 µs per loop
100000 loops, best of 3: 1.4 µs per loop
1000000 loops, best of 3: 2.32 µs per loop
```

PR
```
1000000 loops, best of 3: 533 ns per loop
1000000 loops, best of 3: 758 ns per loop
1000000 loops, best of 3: 734 ns per loop
1000000 loops, best of 3: 570 ns per loop
1000000 loops, best of 3: 779 ns per loop
```

```
In [9]: val2 = np.datetime64(55, 'us')
In [10]: %timeit pd.Timestamp(val2)
```

master
```
100000 loops, best of 3: 3.58 µs per loop
100000 loops, best of 3: 3.49 µs per loop
100000 loops, best of 3: 3.65 µs per loop
100000 loops, best of 3: 2.99 µs per loop
```

PR
```
1000000 loops, best of 3: 1.61 µs per loop
1000000 loops, best of 3: 1.76 µs per loop
1000000 loops, best of 3: 1.66 µs per loop
1000000 loops, best of 3: 1.49 µs per loop
```

Labels:
name: Datetime
description: Datetime data dtype
name: Performance
description: Memory or execution speed performance

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

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

```diff
@@             Coverage Diff             @@
##           master   #24031       +/-   ##
===========================================
+ Coverage   42.46%   92.35%   +49.88%     
===========================================
  Files         161      161               
  Lines       51557    51557               
===========================================
+ Hits        21892    47613    +25721     
+ Misses      29665     3944    -25721
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.75% <ø> (?)` | |
| #single | `42.46% <ø> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24031?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/computation/pytables.py](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vcHl0YWJsZXMucHk=) | `92.37% <0%> (+0.3%)` | :arrow_up: |
| [pandas/io/pytables.py](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3B5dGFibGVzLnB5) | `92.3% <0%> (+0.92%)` | :arrow_up: |
| [pandas/util/\_test\_decorators.py](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvX3Rlc3RfZGVjb3JhdG9ycy5weQ==) | `93.24% <0%> (+4.05%)` | :arrow_up: |
| [pandas/compat/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree#diff-cGFuZGFzL2NvbXBhdC9fX2luaXRfXy5weQ==) | `58.36% <0%> (+8.17%)` | :arrow_up: |
| [pandas/core/config\_init.py](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29uZmlnX2luaXQucHk=) | `99.24% <0%> (+9.84%)` | :arrow_up: |
| [pandas/core/reshape/util.py](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS91dGlsLnB5) | `100% <0%> (+11.53%)` | :arrow_up: |
| [pandas/compat/numpy/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree#diff-cGFuZGFzL2NvbXBhdC9udW1weS9fX2luaXRfXy5weQ==) | `92.85% <0%> (+14.28%)` | :arrow_up: |
| [pandas/core/computation/common.py](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vY29tbW9uLnB5) | `85.71% <0%> (+14.28%)` | :arrow_up: |
| [pandas/core/api.py](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXBpLnB5) | `100% <0%> (+14.81%)` | :arrow_up: |
| [pandas/core/indexes/api.py](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9hcGkucHk=) | `99% <0%> (+14.85%)` | :arrow_up: |
| ... and [119 more](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree-more) | |

------

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

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

```diff
@@             Coverage Diff             @@
##           master   #24031       +/-   ##
===========================================
+ Coverage   42.46%   92.35%   +49.88%     
===========================================
  Files         161      161               
  Lines       51557    51557               
===========================================
+ Hits        21892    47613    +25721     
+ Misses      29665     3944    -25721
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.75% <ø> (?)` | |
| #single | `42.46% <ø> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24031?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/computation/pytables.py](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vcHl0YWJsZXMucHk=) | `92.37% <0%> (+0.3%)` | :arrow_up: |
| [pandas/io/pytables.py](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3B5dGFibGVzLnB5) | `92.3% <0%> (+0.92%)` | :arrow_up: |
| [pandas/util/\_test\_decorators.py](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvX3Rlc3RfZGVjb3JhdG9ycy5weQ==) | `93.24% <0%> (+4.05%)` | :arrow_up: |
| [pandas/compat/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree#diff-cGFuZGFzL2NvbXBhdC9fX2luaXRfXy5weQ==) | `58.36% <0%> (+8.17%)` | :arrow_up: |
| [pandas/core/config\_init.py](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29uZmlnX2luaXQucHk=) | `99.24% <0%> (+9.84%)` | :arrow_up: |
| [pandas/core/reshape/util.py](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS91dGlsLnB5) | `100% <0%> (+11.53%)` | :arrow_up: |
| [pandas/compat/numpy/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree#diff-cGFuZGFzL2NvbXBhdC9udW1weS9fX2luaXRfXy5weQ==) | `92.85% <0%> (+14.28%)` | :arrow_up: |
| [pandas/core/computation/common.py](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vY29tbW9uLnB5) | `85.71% <0%> (+14.28%)` | :arrow_up: |
| [pandas/core/api.py](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXBpLnB5) | `100% <0%> (+14.81%)` | :arrow_up: |
| [pandas/core/indexes/api.py](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9hcGkucHk=) | `99% <0%> (+14.85%)` | :arrow_up: |
| ... and [119 more](https://codecov.io/gh/pandas-dev/pandas/pull/24031/diff?src=pr&el=tree-more) | |

------

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

thanks @jbrockmendel