Skip to content
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.22.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Conversion
Indexing
^^^^^^^^

-
- Bug in ``numpy`` ``array_wrap`` with a pandas ``Series``/``Index`` (:issue:`14042`)
-
-

Expand Down
8 changes: 7 additions & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,13 @@ def __array_wrap__(self, result, context=None):

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)

if issubclass(self, ABCDatetimeIndex) and 'tz' in attrs:
from pandas.core.indexes.datetimes import _new_DatetimeIndex
attrs['data'] = result
return _new_DatetimeIndex(self, attrs)
else:
return Index(result, **attrs)

@cache_readonly
def dtype(self):
Expand Down
16 changes: 16 additions & 0 deletions pandas/tests/indexes/datetimes/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,3 +794,19 @@ def test_slice_duplicate_monotonic(self):
result = idx._maybe_cast_slice_bound('2017-01-01', 'left', 'loc')
expected = Timestamp('2017-01-01')
assert result == expected

def test_split_datetime_index_with_timezone(self):
# https://github.com/pandas-dev/pandas/issues/14042
# check if timezone is correctly handled in array_wrapper
tz = 'Asia/Seoul'
index = date_range('2000-01-01', periods=10, freq='D', tz=tz)
series = Series(index, np.arange(10))
index_split = np.split(index, indices_or_sections=5)
series_split = np.split(series, indices_or_sections=5)
for i in range(5):
index_expected = date_range('2000-01-{0:02d}'.format(2 * i + 1),
periods=2, freq='D', tz=tz)
series_expected = Series(index_expected,
np.arange(2 * i, 2 * i + 2))
tm.assert_index_equal(index_split[i], index_expected)
tm.assert_series_equal(series_split[i], series_expected)