Skip to content

Commit e04f343

Browse files
tsdlovelljreback
authored andcommitted
BUG: fix issue with concat of localized timestamps
closes #12467 closes #12462
1 parent 1fe02d5 commit e04f343

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

doc/source/whatsnew/v0.18.1.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Bug Fixes
192192

193193

194194
- Bug in ``.drop()`` with a non-unique ``MultiIndex``. (:issue:`12701`)
195-
195+
- Bug in ``.concat`` of datetime tz-aware and naive DataFrames (:issue:`12467`)
196196

197197

198198
- Bug in ``Timestamp.__repr__`` that caused ``pprint`` to fail in nested structures (:issue:`12622`)

pandas/tests/frame/test_combine_concat.py

+23
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,29 @@ def test_combine_multiple_frames_dtypes(self):
4646
expected = Series(dict(float64=2, float32=2))
4747
assert_series_equal(results, expected)
4848

49+
def test_combine_multiple_tzs(self):
50+
# GH 12467
51+
# combining datetime tz-aware and naive DataFrames
52+
ts1 = Timestamp('2015-01-01', tz=None)
53+
ts2 = Timestamp('2015-01-01', tz='UTC')
54+
ts3 = Timestamp('2015-01-01', tz='EST')
55+
56+
df1 = DataFrame(dict(time=[ts1]))
57+
df2 = DataFrame(dict(time=[ts2]))
58+
df3 = DataFrame(dict(time=[ts3]))
59+
60+
results = pd.concat([df1, df2]).reset_index(drop=True)
61+
expected = DataFrame(dict(time=[ts1, ts2]), dtype=object)
62+
assert_frame_equal(results, expected)
63+
64+
results = pd.concat([df1, df3]).reset_index(drop=True)
65+
expected = DataFrame(dict(time=[ts1, ts3]), dtype=object)
66+
assert_frame_equal(results, expected)
67+
68+
results = pd.concat([df2, df3]).reset_index(drop=True)
69+
expected = DataFrame(dict(time=[ts2, ts3]))
70+
assert_frame_equal(results, expected)
71+
4972
def test_append_series_dict(self):
5073
df = DataFrame(np.random.randn(5, 4),
5174
columns=['foo', 'bar', 'baz', 'qux'])

pandas/tseries/common.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def convert_to_pydatetime(x, axis):
260260
# if dtype is of datetimetz or timezone
261261
if x.dtype.kind == _NS_DTYPE.kind:
262262
if getattr(x, 'tz', None) is not None:
263-
x = x.asobject
263+
x = x.asobject.values
264264
else:
265265
shape = x.shape
266266
x = tslib.ints_to_pydatetime(x.view(np.int64).ravel())
@@ -271,6 +271,8 @@ def convert_to_pydatetime(x, axis):
271271
x = tslib.ints_to_pytimedelta(x.view(np.int64).ravel())
272272
x = x.reshape(shape)
273273

274+
if axis == 1:
275+
x = np.atleast_2d(x)
274276
return x
275277

276278
if typs is None:

0 commit comments

Comments
 (0)