Implement npy_dtime.pyx
State: closed

`npy_dtime` is a `util`-like module for `tslibs`.  Actually, a better analogy would be src/datetime.pxd (which it ultimately is intended to replace).

Upcoming steps require `_check_dts_bounds` and `OutOfBoundsDatetime` be in a module upstream from `tslib`.  The exception `OutOfBoundsDatetime` cannot be defined in a pxd file, so this can't just be shunted into src/datetime.pxd.

Using a .pyx file instead of a .pxd file is that dependency specification in setup.py gets less fragile.  After updating e.g. `tslibs.fields` to `cimport` from `npy_dtime`, it will no longer need `tseries_depends` and `pandas/_libs/src/datetime/np_datetime.c` etc in its `ext_data` entry.

This also implements two small convenience functions `dtstruct_to_dt64` and `dt64_to_dtstruct` that pass through to `pandas_datetimestruct_to_datetime` and `pandas_datetime_to_datetimestruct` respectively in the overwhelmingly-most-common case where `unit=PANDAS_FR_ns`.  To keep the footprint small this PR only demonstrates their usage in one location in `strptime`.  It's a lot less verbose, ultimately gets rid of a lot of unsightly wrapped lines.



Labels:
name: Datetime
description: Datetime data dtype
name: Clean

Comments:
Hello @jbrockmendel! Thanks for updating the PR.



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

##### Comment last updated on October 29, 2017 at 20:27 Hours UTC
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17805?src=pr&el=h1) Report
> Merging [#17805](https://codecov.io/gh/pandas-dev/pandas/pull/17805?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/e63c935d5a0705f83fc726932eb82bac4c272106?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `n/a`.

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

```diff
@@            Coverage Diff             @@
##           master   #17805      +/-   ##
==========================================
- Coverage   91.26%   91.24%   -0.02%     
==========================================
  Files         163      163              
  Lines       49978    49978              
==========================================
- Hits        45611    45602       -9     
- Misses       4367     4376       +9
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.04% <ø> (ø)` | :arrow_up: |
| #single | `40.24% <ø> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17805?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17805?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17805?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.74% <0%> (-0.1%)` | :arrow_down: |

------

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

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

```diff
@@            Coverage Diff             @@
##           master   #17805      +/-   ##
==========================================
- Coverage   91.24%   91.22%   -0.02%     
==========================================
  Files         163      163              
  Lines       50091    50099       +8     
==========================================
- Hits        45704    45703       -1     
- Misses       4387     4396       +9
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.03% <ø> (ø)` | :arrow_up: |
| #single | `40.24% <ø> (-0.06%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17805?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17805?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17805?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.75% <0%> (-0.1%)` | :arrow_down: |
| [pandas/core/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/17805?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY2F0ZWdvcmljYWwucHk=) | `95.79% <0%> (+0.04%)` | :arrow_up: |

------

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

The flake8 warning is pretty unavoidable here.
This is a blocker for upcoming work.
can we name this something else, maybe just spell it out

numpy_datetime or numpy_compat
np_datetime would be consistent
Changing to np_datetime, though with some misgivings about the exact name match.
suggestions for moving this down the field?
> suggestions for moving this down the field?

what do you mean?
> what do you mean?

The circleci errors are in test_grouped_box_multiple_axes and test_boxplot_legacy, which I think are unrelated, and the travis error is a flake8 complaint that is pretty unavoidable.  Not sure what needs to be done to get this approved+merged.
> The circleci errors are in test_grouped_box_multiple_axes and test_boxplot_legacy, which I think are unrelated, and the travis error is a flake8 complaint that is pretty unavoidable. Not sure what needs to be done to get this approved+merged.

did you rebase on master? these are working ok there.
> did you rebase on master? these are working ok there.

Looks like that fixed the CircleCI error, good call.  Looks like a build stalled on Travis; just took another swing at fixing the flake8 error and re-pushed.  With a little luck we'll get to all-green.
fyi i always keep master up to date and anytime i push i rebase
makes it easier
Adding the "void" to `check_dts_bounds` caused a bunch of errors because exceptions were ignored (i.e. no `except -1`).  The current implementation in `tslib` doesn't have the void, so I just reverted that.
some linting errors.
thanks!