8000 BUG: Fix #25959 - Don't call .array in DatetimeLikeArrayMixin's map by ThomasKluiters · Pull Request #25964 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fix #25959 - Don't call .array in DatetimeLikeArrayMixin's map #25964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 19, 2019
Prev Previous commit
Add regression test and fix PEP
  • Loading branch information
ThomasKluiters committed May 18, 2019
commit 36429a04c240577f17fc8eefdaa1fa50a19125c3
3 changes: 2 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3705,7 +3705,8 @@ def f(x):
if len(mapped) and isinstance(mapped[0], Series):
# GH 25959 use pd.array instead of tolist
# so extension arrays can be used
return self._constructor_expanddim(pd.array(mapped), index=self.index)
return self._constructor_expanddim(pd.array(mapped),
index=self.index)
else:
return self._constructor(mapped,
index=self.index).__finalize__(self)
Expand Down
9 changes: 8 additions & 1 deletion pandas/tests/series/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,9 +678,16 @@ def test_map_missing_mixed(self, vals, mapping, exp):
(tm.makeTimeSeries(nper=30),
DataFrame(np.repeat([[1, 2]], 30, axis=0), dtype='int64'))
])
def test_apply_on_date_time_index_aware_series(self, dti, exp):
def test_apply_series_on_date_time_index_aware_series(self, dti, exp):
# GH 25959
# Calling apply on a localized time series should not cause an error
index = dti.tz_localize('UTC').index
result = pd.Series(index).apply(lambda x: pd.Series([1, 2]))
assert_frame_equal(result, exp)

def test_apply_scaler_on_date_time_index_aware_series(self):
# GH 25959
# Calling apply on a localized time series should not cause an error
series = tm.makeTimeSeries(nper=30).tz_localize('UTC')
result = pd.Series(series.index).apply(lambda x: 1)
assert_series_equal(result, pd.Series(np.ones(30), dtype='int64'))
0