Skip to content

Commit

Permalink
BUG: Preserve timezone in unaligned assignments
Browse files Browse the repository at this point in the history
closes #12981

Author: ajenkins-cargometrics <ajenkins@cargometrics.com>

Closes #12982 from ajenkins-cargometrics/GH12981 and squashes the following commits:

6689f57 [ajenkins-cargometrics] TST: Add test with mask on LHS for test_setitem_with_unaligned_tz_aware_datetime_column
1347398 [ajenkins-cargometrics] BUG: Preserve timezone in unaligned assignments
  • Loading branch information
ajenkins-cargometrics authored and jreback committed Apr 26, 2016
1 parent 2fd0a06 commit cc67b72
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.18.1.txt
Expand Up @@ -387,6 +387,7 @@ Bug Fixes


- Bug in ``read_csv`` with the C engine when specifying ``skiprows`` with newlines in quoted items (:issue:`10911`, `12775`)
- Bug in ``DataFrame`` timezone lost when assigning tz-aware datetime ``Series`` with alignment (:issue `12981`)



Expand Down
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Expand Up @@ -2538,7 +2538,7 @@ def reindexer(value):

# GH 4107
try:
value = value.reindex(self.index).values
value = value.reindex(self.index)._values
except Exception as e:

# duplicate axis
Expand Down
16 changes: 15 additions & 1 deletion pandas/tests/frame/test_indexing.py
Expand Up @@ -1940,6 +1940,20 @@ def test_setitem_with_unaligned_sparse_value(self):
exp = pd.Series([1, 0, 0], name='new_column')
assert_series_equal(df['new_column'], exp)

def test_setitem_with_unaligned_tz_aware_datetime_column(self):
# GH 12981
# Assignment of unaligned offset-aware datetime series.
# Make sure timezone isn't lost
column = pd.Series(pd.date_range('2015-01-01', periods=3, tz='utc'),
name='dates')
df = pd.DataFrame({'dates': column})
df['dates'] = column[[1, 0, 2]]
assert_series_equal(df['dates'], column)

df = pd.DataFrame({'dates': column})
df.loc[[0, 1, 2], 'dates'] = column[[1, 0, 2]]
assert_series_equal(df['dates'], column)

def test_setitem_datetime_coercion(self):
# GH 1048
df = pd.DataFrame({'c': [pd.Timestamp('2010-10-01')] * 3})
Expand All @@ -1949,7 +1963,7 @@ def test_setitem_datetime_coercion(self):
df.loc[2, 'c'] = date(2005, 5, 5)
self.assertEqual(pd.Timestamp('2005-05-05'), df.loc[2, 'c'])

def test_datetimelike_setitem_with_inference(self):
def test_setitem_datetimelike_with_inference(self):
# GH 7592
# assignment of timedeltas with NaT

Expand Down

0 comments on commit cc67b72

Please sign in to comment.