Skip to content

Conversation

@wooyekim
Copy link

Root cause: When a DatetimeIndex is created by array_wrap,
round-trip of timezone occured

Solution: Remove the timezone of the original index when creating
a DatetimeIndex via array_wrap and apply the timezone later

Root cause: When a DatetimeIndex is created by __array_wrap__, round-trip of timezone occured Solution: Remove the timezone of the original index when creating a DatetimeIndex via __array_wrap__ and apply the timezone later
@wooyekim wooyekim changed the title Issue14042 BUG: numpy.split on non-UTC changes original time (#14042) Aug 15, 2017
@codecov
Copy link

codecov bot commented Aug 15, 2017

Codecov Report

Merging #17255 into master will decrease coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@ Coverage Diff @@ ## master #17255 +/- ## ========================================== - Coverage 91.03% 90.99% -0.05%  ========================================== Files 162 162 Lines 49527 49533 +6 ========================================== - Hits 45086 45071 -15  - Misses 4441 4462 +21
Flag Coverage Δ
#multiple 88.77% <100%> (-0.03%) ⬇️
#single 40.25% <0%> (-0.07%) ⬇️
Impacted Files Coverage Δ
pandas/core/indexes/base.py 95.94% <100%> (+0.01%) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/plotting/_converter.py 63.23% <0%> (-1.82%) ⬇️
pandas/core/frame.py 97.72% <0%> (-0.1%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0f25426...d928221. Read the comment docs.

@codecov
Copy link

codecov bot commented Aug 15, 2017

Codecov Report

Merging #17255 into master will decrease coverage by 0.24%.
The diff coverage is 100%.

Impacted file tree graph

@@ Coverage Diff @@ ## master #17255 +/- ## ========================================== - Coverage 91.24% 90.99% -0.25%  ========================================== Files 163 162 -1 Lines 50091 49536 -555 ========================================== - Hits 45704 45074 -630  - Misses 4387 4462 +75
Flag Coverage Δ
#multiple 88.77% <100%> (-0.26%) ⬇️
#single 40.25% <0%> (-0.05%) ⬇️
Impacted Files Coverage Δ
pandas/core/indexes/base.py 95.94% <100%> (-0.48%) ⬇️
pandas/io/s3.py 0% <0%> (-85%) ⬇️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/tests/plotting/__init__.py 77.77% <0%> (-22.23%) ⬇️
pandas/core/tools/datetimes.py 66.85% <0%> (-16.12%) ⬇️
pandas/util/_decorators.py 66% <0%> (-14.71%) ⬇️
pandas/compat/pickle_compat.py 69.51% <0%> (-6.1%) ⬇️
pandas/core/dtypes/missing.py 87.19% <0%> (-3.43%) ⬇️
pandas/core/indexes/range.py 92.81% <0%> (-2.85%) ⬇️
pandas/util/_validators.py 93.75% <0%> (-2.6%) ⬇️
... and 88 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5959ee3...a1023f5. Read the comment docs.

- Fixes ``DataFrame.loc`` for setting with alignment and tz-aware ``DatetimeIndex`` (:issue:`16889`)
- Avoids ``IndexError`` when passing an Index or Series to ``.iloc`` with older numpy (:issue:`17193`)
- Allow unicode empty strings as placeholders in multilevel columns in Python 2 (:issue:`17099`)
- Fixes bug for ``numpy.split`` on pandas dataframe with non-utc timezone (:issue:`14042`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug in numpy array_wrap with a pandas Series/Index.

attrs = self._get_attributes_dict()
attrs = self._maybe_update_attributes(attrs)
return Index(result, **attrs)
from pandas.core.indexes.datetimes import DatetimeIndex
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add this

diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index de6221987..865e92201 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -99,6 +99,9 @@ def _new_Index(cls, d): if issubclass(cls, ABCPeriodIndex): from pandas.core.indexes.period import _new_PeriodIndex return _new_PeriodIndex(cls, **d) + elif issubclass(cls, ABCDatetimeIndex): + from pandas.core.indexes.datetimes import _new_DatetimeIndex + return _new_DatetimeIndex(cls, **d) return cls.__new__(cls, **d) 

then you can simply call
return _new_Index(result attrs)

assert result == expected

def test_split_date_range_with_timezone(self):
# https://github.com/pandas-dev/pandas/issues/14042
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a 1-liner about what you are testing here

# https://github.com/pandas-dev/pandas/issues/14042
idx = DatetimeIndex(['2016-01-01 00:00:00', '2016-01-02 00:00:00'],
tz='Asia/Seoul')
split = np.split(idx, indices_or_sections=[])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use an tm.assert_index_equal and test for each piece.

Also test using a Series (can be here is ok)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally we could exercise more numpy ufuncs for 1d reshaping ops here as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that Series does not suffer from this issue. But I'll leave the testcase.

@jreback jreback added Bug Compat pandas objects compatability with Numpy or Python functions Timezones Timezone data dtype labels Aug 15, 2017
@pep8speaks
Copy link

pep8speaks commented Aug 15, 2017

Hello @wooyekim! Thanks for updating the PR.

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

Comment last updated on October 29, 2017 at 14:37 Hours UTC
attrs = self._get_attributes_dict()
attrs = self._maybe_update_attributes(attrs)
return Index(result, **attrs)
from pandas.core.dtypes.generic import ABCDatetimeIndex
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if you saw my comment. pls move this logic to _new_Index (and the import can be at the top of the file)

@jreback
Copy link
Contributor

jreback commented Sep 13, 2017

can you rebase / update

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you rebase

- Bug in reindexing on an empty ``CategoricalIndex`` (:issue:`16770`)
- Fixes ``DataFrame.loc`` for setting with alignment and tz-aware ``DatetimeIndex`` (:issue:`16889`)
- Avoids ``IndexError`` when passing an Index or Series to ``.iloc`` with older numpy (:issue:`17193`)
- Allow unicode empty strings as placeholders in multilevel columns in Python 2 (:issue:`17099`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to 0.21.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Compat pandas objects compatability with Numpy or Python functions Timezones Timezone data dtype

3 participants