BUG: Casting tz-aware DatetimeIndex to object-dtype ndarray/Index
State: closed

Also fixes bug with `DateOffset == "infer"` incorrectly raising instead of returning `False`.

Also fixes bug(?) with `pd.Index(dtindex, dtype=object)` returning an index of datetimes instead of Timestamps, potentially losing nanoseconds.

- [x] closes #23491
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry


Labels:
name: Datetime
description: Datetime data dtype
name: Timezones
description: Timezone data dtype

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

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

 - There are no PEP8 issues in the file [`pandas/core/indexes/base.py`](https://github.com/jbrockmendel/pandas/blob/ca9e8af967817b7a922868ae7405d0eb6ed8fba2/pandas/core/indexes/base.py) !

 - There are no PEP8 issues in the file [`pandas/tests/arrays/test_datetimelike.py`](https://github.com/jbrockmendel/pandas/blob/ca9e8af967817b7a922868ae7405d0eb6ed8fba2/pandas/tests/arrays/test_datetimelike.py) !

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

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

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

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


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

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

```diff
@@            Coverage Diff             @@
##           master   #23524      +/-   ##
==========================================
- Coverage   92.25%   92.25%   -0.01%     
==========================================
  Files         161      161              
  Lines       51262    51278      +16     
==========================================
+ Hits        47292    47304      +12     
- Misses       3970     3974       +4
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.63% <91.3%> (-0.01%)` | :arrow_down: |
| #single | `42.32% <43.47%> (-0.02%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/23524?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/arrays/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/23524/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2RhdGV0aW1lcy5weQ==) | `98.44% <100%> (+0.02%)` | :arrow_up: |
| [pandas/core/indexes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/23524/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9iYXNlLnB5) | `96.45% <100%> (ø)` | :arrow_up: |
| [pandas/tseries/offsets.py](https://codecov.io/gh/pandas-dev/pandas/pull/23524/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvb2Zmc2V0cy5weQ==) | `97.07% <85.71%> (-0.15%)` | :arrow_down: |
| [pandas/io/pytables.py](https://codecov.io/gh/pandas-dev/pandas/pull/23524/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3B5dGFibGVzLnB5) | `92.34% <0%> (-0.09%)` | :arrow_down: |

------

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

> Also fixes bug(?) with pd.Index(dtindex, dtype=object) returning an index of datetimes instead of Timestamps, potentially losing nanoseconds.

Seems like a fine change, but needs a release note.
> Seems like a fine change, but needs a release note.

Good point; done.
thanks @jbrockmendel 

#23593 is the followup to address ``__array__``.