BUG: Using DatetimeIndex.date with timezone returns incorrect date #2…
State: closed


- [ ] closes #21230, closes https://github.com/pandas-dev/pandas/issues/21267
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

Added 2 tests for DatetimeIndex.date in tests/indexes/datetimes/test_datetime.py. Please let me know if I should move them somewhere else.

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

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

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

```diff
@@            Coverage Diff             @@
##           master   #21281      +/-   ##
==========================================
+ Coverage   91.85%   91.85%   +<.01%     
==========================================
  Files         153      153              
  Lines       49549    49555       +6     
==========================================
+ Hits        45512    45518       +6     
  Misses       4037     4037
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.25% <100%> (ø)` | :arrow_up: |
| #single | `41.87% <0%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/21281?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/21281/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.8% <100%> (+0.02%)` | :arrow_up: |
| [pandas/core/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/21281/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc2VyaWVzLnB5) | `94.12% <0%> (ø)` | :arrow_up: |

------

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

ASV for this commit:
```
[  0.00%] · For pandas commit hash d962273a:
[  0.00%] ·· Building for conda-py3.6-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-pytest-scipy-sqlalchemy-xlrd-xlsxwriter-xlwt
[  0.00%] ·· Benchmarking conda-py3.6-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-pytest-scipy-sqlalchemy-xlrd-xlsxwriter-xlwt
[ 50.00%] ··· Running timeseries.DatetimeIndex.time_to_date                                                                     1.23±0.1ms;...
[ 50.00%] · For pandas commit hash 4274b840:
[ 50.00%] ·· Building for conda-py3.6-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-pytest-scipy-sqlalchemy-xlrd-xlsxwriter-xlwt
[ 50.00%] ·· Benchmarking conda-py3.6-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-pytest-scipy-sqlalchemy-xlrd-xlsxwriter-xlwt
[100.00%] ··· Running timeseries.DatetimeIndex.time_to_date                                                                    1.20±0.08ms;...
BENCHMARKS NOT SIGNIFICANTLY CHANGED.
```
> Can you do a similar change for time attribute (just above date in the code) ?

Then it would also close https://github.com/pandas-dev/pandas/issues/21267
Sure. There's some discussion in #21267 about whether `time` should return a time with the timezone in it. Could you tell me which is the correct behavior?
I think converting back to the 0.22 behaviour is the best for now (which I think is no timezone in the output?) We can still later discuss if we want to add the timezone or not.
@jorisvandenbossche regarding my comment (https://github.com/pandas-dev/pandas/issues/21267#issuecomment-394060416), it looks like the `time` behavior looks correct but there was some confusion stemming from the construction of the DatetimeIndex (#15938).




@jorisvandenbossche @mroeschke @jreback For #21267, it seems that whether the timezone should be returned still needs to be discussed. Is it ok if I change the behavior of `time` to match v0.22 for now (i.e: `time` does not return a Time with timezone information) since that was also an unintended change?
~~wouldn’t change this as it’s correct
pls update the doc string~~

looking at this again -

both .date and .time should be naive i think (and .date already is)

so ok to change .time back to naive

mention in docs that these are local (naive) date/times that are returned

pls create an issue about this for discussion as well (eg to in future make these tz-aware)


> wouldn’t change this as it’s correct

No, adding the timezone was unintended, and is inconsistent with how Timestamp itself works, and inconsistent with standard library (they both return naive local time). 
So I would just change it back to how it was.
@jreback sorry, missed the update of your comment. So yes, then we agree!
Is there any way to trigger a re-build on CircleCI? That build failed with this error:
```
CondaHTTPError: HTTP 522 ORIGIN CONNECTION TIME-OUT for url <https://repo.anaconda.com/pkgs/main/linux-64/libpq-10.3-h1ad7b7a_0.tar.bz2>
Elapsed: 00:42.034156
CF-RAY: 426f9db31db895a4-IAD

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
```
@tmnhat2001 Thanks a lot!
Thanks everyone.