BUG: Assorted DatetimeIndex bugfixes
State: closed

Bit of a hodge-podge.

- Deprecate `time_rule` in `offsets.generate_range`
- Improve error messages if NaT gets passed to date_range, or in validate_frequency (closes #11587)
- Preserve timezone in DatetimeIndex->CategoricalIndex->DatetimeIndex (closes #18664)
- Preserve freq when indexing DTI/TDI with Ellipsis (closes #21282)
- [x] closes #11587

@TomAugspurger nothing here is urgent, so if this overlaps with DTA it can stay on the backburner.

Labels:
name: Datetime
description: Datetime data dtype
name: Deprecate
description: Functionality to remove in pandas

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

 - There are no PEP8 issues in the file [`pandas/core/arrays/datetimelike.py`](https://github.com/jbrockmendel/pandas/blob/12e0f4ee38c80e0f1d1b33a92976f1ce9fd196b1/pandas/core/arrays/datetimelike.py) !

 - There are no PEP8 issues in the file [`pandas/core/arrays/datetimes.py`](https://github.com/jbrockmendel/pandas/blob/12e0f4ee38c80e0f1d1b33a92976f1ce9fd196b1/pandas/core/arrays/datetimes.py) !

 - There are no PEP8 issues in the file [`pandas/tests/indexes/datetimes/test_construction.py`](https://github.com/jbrockmendel/pandas/blob/12e0f4ee38c80e0f1d1b33a92976f1ce9fd196b1/pandas/tests/indexes/datetimes/test_construction.py) !

 - There are no PEP8 issues in the file [`pandas/tests/indexes/datetimes/test_date_range.py`](https://github.com/jbrockmendel/pandas/blob/12e0f4ee38c80e0f1d1b33a92976f1ce9fd196b1/pandas/tests/indexes/datetimes/test_date_range.py) !

 - There are no PEP8 issues in the file [`pandas/tests/indexes/datetimes/test_indexing.py`](https://github.com/jbrockmendel/pandas/blob/12e0f4ee38c80e0f1d1b33a92976f1ce9fd196b1/pandas/tests/indexes/datetimes/test_indexing.py) !

 - There are no PEP8 issues in the file [`pandas/tests/indexes/period/test_indexing.py`](https://github.com/jbrockmendel/pandas/blob/12e0f4ee38c80e0f1d1b33a92976f1ce9fd196b1/pandas/tests/indexes/period/test_indexing.py) !

 - There are no PEP8 issues in the file [`pandas/tests/indexes/timedeltas/test_indexing.py`](https://github.com/jbrockmendel/pandas/blob/12e0f4ee38c80e0f1d1b33a92976f1ce9fd196b1/pandas/tests/indexes/timedeltas/test_indexing.py) !

 - There are no PEP8 issues in the file [`pandas/tests/tseries/offsets/test_offsets.py`](https://github.com/jbrockmendel/pandas/blob/12e0f4ee38c80e0f1d1b33a92976f1ce9fd196b1/pandas/tests/tseries/offsets/test_offsets.py) !

 - There are no PEP8 issues in the file [`pandas/tseries/offsets.py`](https://github.com/jbrockmendel/pandas/blob/12e0f4ee38c80e0f1d1b33a92976f1ce9fd196b1/pandas/tseries/offsets.py) !


# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24157?src=pr&el=h1) Report
> Merging [#24157](https://codecov.io/gh/pandas-dev/pandas/pull/24157?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/c91115172ce1e7324ff9422cb38f520496df2573?src=pr&el=desc) will **decrease** coverage by `49.17%`.
> The diff coverage is `50%`.

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

```diff
@@             Coverage Diff             @@
##           master   #24157       +/-   ##
===========================================
- Coverage    92.2%   43.02%   -49.18%     
===========================================
  Files         162      162               
  Lines       51700    51714       +14     
===========================================
- Hits        47670    22251    -25419     
- Misses       4030    29463    +25433
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `?` | |
| #single | `43.02% <50%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24157?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/arrays/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/24157/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2RhdGV0aW1lcy5weQ==) | `65.01% <25%> (-33.55%)` | :arrow_down: |
| [pandas/tseries/offsets.py](https://codecov.io/gh/pandas-dev/pandas/pull/24157/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvb2Zmc2V0cy5weQ==) | `46.43% <50%> (-50.41%)` | :arrow_down: |
| [pandas/core/arrays/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/24157/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2RhdGV0aW1lbGlrZS5weQ==) | `48.98% <83.33%> (-47.38%)` | :arrow_down: |
| [pandas/io/formats/latex.py](https://codecov.io/gh/pandas-dev/pandas/pull/24157/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvbGF0ZXgucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/core/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/24157/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY2F0ZWdvcmljYWwucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/sas/sas\_constants.py](https://codecov.io/gh/pandas-dev/pandas/pull/24157/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfY29uc3RhbnRzLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/plotting.py](https://codecov.io/gh/pandas-dev/pandas/pull/24157/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvcGxvdHRpbmcucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/24157/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvY29udmVydGVyLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/formats/html.py](https://codecov.io/gh/pandas-dev/pandas/pull/24157/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvaHRtbC5weQ==) | `0% <0%> (-98.62%)` | :arrow_down: |
| [pandas/core/groupby/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/24157/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9jYXRlZ29yaWNhbC5weQ==) | `0% <0%> (-95.46%)` | :arrow_down: |
| ... and [122 more](https://codecov.io/gh/pandas-dev/pandas/pull/24157/diff?src=pr&el=tree-more) | |

------

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

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

```diff
@@            Coverage Diff             @@
##           master   #24157      +/-   ##
==========================================
- Coverage   92.22%   92.22%   -0.01%     
==========================================
  Files         162      162              
  Lines       51785    51796      +11     
==========================================
+ Hits        47758    47767       +9     
- Misses       4027     4029       +2
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.62% <100%> (-0.01%)` | :arrow_down: |
| #single | `43.01% <70.58%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24157?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/arrays/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/24157/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2RhdGV0aW1lbGlrZS5weQ==) | `96.41% <100%> (+0.05%)` | :arrow_up: |
| [pandas/tseries/offsets.py](https://codecov.io/gh/pandas-dev/pandas/pull/24157/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvb2Zmc2V0cy5weQ==) | `96.84% <100%> (-0.01%)` | :arrow_down: |
| [pandas/core/arrays/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/24157/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2RhdGV0aW1lcy5weQ==) | `98.22% <100%> (-0.35%)` | :arrow_down: |

------

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

Azure fail is in developer.rst, unrelated.
@datapythonista is the azure fail caused by something in this PR?  It looks unrelated but re-pushing didn’t fix it.
master was broken (I merged an old PR that didn't have some linting), but it's been fixed in #24160

If you merge master and push again, the CI should pass now.
> pls add to #6581 for the deprecation

Will do.  Actually, is this private enough that a deprecation cycle is unnecessary?  If so we should just remove the arg now and move the whole func to arrays.datetimes, since that is the only place it is used
@TomAugspurger does this step on your toes?
linting issue. ping on green.
Ping
thanks!