Skip to content

Commit abd0dc9

Browse files
committed
TENTATIVE: Fix for combine_first; tests for combine_first and where.
No solution yet for where, and combine_first might require cleanup.
1 parent bf1c3dc commit abd0dc9

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

pandas/core/series.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2305,7 +2305,11 @@ def combine_first(self, other):
23052305
# TODO: do we need name?
23062306
name = ops.get_op_result_name(self, other) # noqa
23072307
rs_vals = com._where_compat(isna(this), other._values, this._values)
2308-
return self._constructor(rs_vals, index=new_index).__finalize__(self)
2308+
result = self._constructor(rs_vals, index=new_index).__finalize__(self)
2309+
# TODO DK can we simplify this using internals rather than public astype
2310+
if is_datetime64tz_dtype(self.dtype):
2311+
result = result.astype(self.dtype)
2312+
return result
23092313

23102314
def update(self, other):
23112315
"""

pandas/tests/series/indexing/test_boolean.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,19 @@ def test_where_datetime_conversion():
551551
assert_series_equal(rs, expected)
552552

553553

554+
def test_where_dt_tz_values(self):
555+
dts1 = pd.date_range('20150101', '20150105', tz='America/New_York')
556+
df1 = pd.DataFrame({'date':dts1})
557+
dts2 = pd.date_range('20150103', '20150107', tz='America/New_York')
558+
df2 = pd.DataFrame({'date':dts2})
559+
result = df1.date.where(df1.date < df1.date[3], df2.date)
560+
exp_vals = pd.DatetimeIndex(['20150101', '20150102', '20150103',
561+
'20150106', '20150107'],
562+
tz='America/New_York')
563+
exp = Series(exp_vals)
564+
assert_series_equal(exp, result)
565+
566+
554567
def test_mask():
555568
# compare with tested results in test_where
556569
s = Series(np.random.randn(5))

pandas/tests/series/test_combine_concat.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,19 @@ def get_result_type(dtype, dtype2):
170170
]).dtype
171171
assert result.kind == expected
172172

173+
def test_combine_first_dt_tz_values(self):
174+
dts1 = pd.date_range('20150101', '20150105', tz='America/New_York')
175+
df1 = pd.DataFrame({'date':dts1})
176+
dts2 = pd.date_range('20160514', '20160518', tz='America/New_York')
177+
df2 = pd.DataFrame({'date':dts2}, index=range(3, 8))
178+
result = df1.date.combine_first(df2.date)
179+
exp_vals = pd.DatetimeIndex(['20150101', '20150102', '20150103',
180+
'20150104', '20150105', '20160516',
181+
'20160517', '20160518'],
182+
tz='America/New_York')
183+
exp = pd.Series(exp_vals, name='date')
184+
assert_series_equal(exp, result)
185+
173186
def test_concat_empty_series_dtypes(self):
174187

175188
# booleans

0 commit comments

Comments
 (0)