ENH: Added stride/offset aliases in to_datetime
State: closed

Added support for stride and offset aliases to the 'unit' keyword in
'to_datetime'.  Documented support for additional 'unit' intervals that
were available.

- [ ] closes #xxxx
- [ ] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry


Labels:
name: Enhancement
name: Datetime
description: Datetime data dtype

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

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

```diff
@@            Coverage Diff             @@
##           master   #26631      +/-   ##
==========================================
- Coverage   91.88%   91.87%   -0.01%     
==========================================
  Files         174      174              
  Lines       50692    50692              
==========================================
- Hits        46576    46572       -4     
- Misses       4116     4120       +4
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.41% <ø> (ø)` | :arrow_up: |
| #single | `41.8% <ø> (-0.09%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26631?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/tools/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/26631/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvdG9vbHMvZGF0ZXRpbWVzLnB5) | `85.05% <ø> (ø)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26631/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26631/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97% <0%> (-0.12%)` | :arrow_down: |

------

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

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

```diff
@@            Coverage Diff             @@
##           master   #26631      +/-   ##
==========================================
- Coverage   91.88%   91.87%   -0.01%     
==========================================
  Files         174      174              
  Lines       50692    50692              
==========================================
- Hits        46576    46572       -4     
- Misses       4116     4120       +4
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.41% <ø> (ø)` | :arrow_up: |
| #single | `41.8% <ø> (-0.09%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26631?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/tools/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/26631/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvdG9vbHMvZGF0ZXRpbWVzLnB5) | `85.05% <ø> (ø)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26631/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26631/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97% <0%> (-0.12%)` | :arrow_down: |

------

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

> Does this close an existing issue? Also tests are critical to make sure this actually works

I couldn't find an existing issue.  I had an issue that I didn't report, however.  I was trying to use `to_datetime` to make an hourly series and blindly used `to_datetime([1, 2], unit='H')` didn't work, which was puzzling.  So looked at the code finding that `to_datetime([1, 2], unit='h')` did work, but 'h' is not an offset alias.  Other strange things where, 'm' meant minutely, and 'M' meant monthly.

After working with the code found it easy to add stride.

Passed current tests, so I didn't break old behaviors.  

Where should I put new tests?

> Yearly and monthly offsets were deprecated recently. #16344.
> 
> Week offsets are on the chopping block too so it's best not to advertise them as well. [#14024 (comment)](https://github.com/pandas-dev/pandas/issues/14024#issuecomment-240680919)

There isn't a deprecation warning in `to_datetime()`.  Will add deprecation warning for 'Y', 'A', 'M', and 'W'.
> we have a bunch of tests for this already in pandas/tests/indexes/timedeltas/test_tools.py

No test for the added stride, also almost all of the tests are only for unit='D' and unit='s'.

> so I suppose some of these were not caught if you actually need to do this?

I think reasonable to add tests for stride and for other accepted units.  Working on it.

> also would need to do an asv run on appropriate benchmarks for this change

I have not done this before.  Will look around on how to make that happen.
can you merge master and respond to comments
Almost done.

Ran into this https://github.com/numpy/numpy/issues/8325, which affects several of the tests and for some time thought it was my code failing instead.  Tried to resolve/fix but just spun wheels instead.

Ran the benchmarks multiple times and got different answers each time.  For example, see the attached files of the results summaries from two benchmark runs.  Both done overnight while my Chromebook was not used for anything else.
[summary_results_2.txt](https://github.com/pandas-dev/pandas/files/3374138/summary_results_2.txt)
[summary_results_1.txt](https://github.com/pandas-dev/pandas/files/3374139/summary_results_1.txt)
Don't know what to do about that.  Copying pandas working directory to a beefier machine and see what happens.

Should I squash all commits into one?


> Almost done.
> 
> Ran into this [numpy/numpy#8325](https://github.com/numpy/numpy/issues/8325), which affects several of the tests and for some time thought it was my code failing instead. Tried to resolve/fix but just spun wheels instead.
> 
> Ran the benchmarks multiple times and got different answers each time. For example, see the attached files of the results summaries from two benchmark runs. Both done overnight while my Chromebook was not used for anything else.
> [summary_results_2.txt](https://github.com/pandas-dev/pandas/files/3374138/summary_results_2.txt)
> [summary_results_1.txt](https://github.com/pandas-dev/pandas/files/3374139/summary_results_1.txt)
> Don't know what to do about that. Copying pandas working directory to a beefier machine and see what happens.
> 
> Should I squash all commits into one?

we don't use numpy directly for (very little) nan operations, and not for timedeltas so not sure where you are hitting this.
> we don't use numpy directly for (very little) nan operations, and not for timedeltas so not sure where you are hitting this.

Initial bug report is https://github.com/pandas-dev/pandas/issues/26964 that shows the problem in pandas.  Closed it when I found that numpy had the same bug and thought, maybe incorrectly, that pandas was using numpy and therefore getting the same behavior.
Looks like a git merge issue. Let us know if you need help fixing.
Yep.  Need help with git.  I though everything looked good here, but obviously it is a mess.

I could send the log of what I had done if that is helpful.
In theory, a

```
git fetch upstream
git merge upstream/master
```

should get you straightened out.

 
@timcera can you merge master again? Looks like old builds are no longer available
numpydev is failing. Does this PR introduce new warnings from Numpy? Running with `pytest -wError` may help.
closing as stale; if you want to continue working, pls merge ``upstream/master`` and ping to re-open.