Skip to content

Commit

Permalink
BUG: fix issue with concat of localized timestamps
Browse files Browse the repository at this point in the history
closes #12467
closes #12462
  • Loading branch information
tsdlovell authored and jreback committed Apr 6, 2016
1 parent 1fe02d5 commit e04f343
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.18.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ Bug Fixes


- Bug in ``.drop()`` with a non-unique ``MultiIndex``. (:issue:`12701`)

- Bug in ``.concat`` of datetime tz-aware and naive DataFrames (:issue:`12467`)


- Bug in ``Timestamp.__repr__`` that caused ``pprint`` to fail in nested structures (:issue:`12622`)
Expand Down
23 changes: 23 additions & 0 deletions pandas/tests/frame/test_combine_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,29 @@ def test_combine_multiple_frames_dtypes(self):
expected = Series(dict(float64=2, float32=2))
assert_series_equal(results, expected)

def test_combine_multiple_tzs(self):
# GH 12467
# combining datetime tz-aware and naive DataFrames
ts1 = Timestamp('2015-01-01', tz=None)
ts2 = Timestamp('2015-01-01', tz='UTC')
ts3 = Timestamp('2015-01-01', tz='EST')

df1 = DataFrame(dict(time=[ts1]))
df2 = DataFrame(dict(time=[ts2]))
df3 = DataFrame(dict(time=[ts3]))

results = pd.concat([df1, df2]).reset_index(drop=True)
expected = DataFrame(dict(time=[ts1, ts2]), dtype=object)
assert_frame_equal(results, expected)

results = pd.concat([df1, df3]).reset_index(drop=True)
expected = DataFrame(dict(time=[ts1, ts3]), dtype=object)
assert_frame_equal(results, expected)

results = pd.concat([df2, df3]).reset_index(drop=True)
expected = DataFrame(dict(time=[ts2, ts3]))
assert_frame_equal(results, expected)

def test_append_series_dict(self):
df = DataFrame(np.random.randn(5, 4),
columns=['foo', 'bar', 'baz', 'qux'])
Expand Down
4 changes: 3 additions & 1 deletion pandas/tseries/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def convert_to_pydatetime(x, axis):
# if dtype is of datetimetz or timezone
if x.dtype.kind == _NS_DTYPE.kind:
if getattr(x, 'tz', None) is not None:
x = x.asobject
x = x.asobject.values
else:
shape = x.shape
x = tslib.ints_to_pydatetime(x.view(np.int64).ravel())
Expand All @@ -271,6 +271,8 @@ def convert_to_pydatetime(x, axis):
x = tslib.ints_to_pytimedelta(x.view(np.int64).ravel())
x = x.reshape(shape)

if axis == 1:
x = np.atleast_2d(x)
return x

if typs is None:
Expand Down

0 comments on commit e04f343

Please sign in to comment.