Skip to content

BUG/ERR: raise when trying to set a subset of values in a datetime64[ns, tz] columns with another tz #11259

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 1 commit into from
Oct 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2099,7 +2099,7 @@ def _try_coerce_args(self, values, other):
if is_null_datelike_scalar(other):
other = tslib.iNaT
elif isinstance(other, self._holder):
if other.tz != self.tz:
if other.tz != self.values.tz:
raise ValueError("incompatible or non tz-aware value")
other = other.tz_localize(None).asi8
else:
Expand Down
24 changes: 0 additions & 24 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4322,30 +4322,6 @@ def test_constructor_with_datetime_tz(self):
result = result.set_index('foo')
tm.assert_index_equal(df.index,idx)

# indexing
result = df2.iloc[1]
expected = Series([Timestamp('2013-01-02 00:00:00-0500', tz='US/Eastern'), np.nan, np.nan],
index=list('ABC'), dtype='object', name=1)
assert_series_equal(result, expected)
result = df2.loc[1]
expected = Series([Timestamp('2013-01-02 00:00:00-0500', tz='US/Eastern'), np.nan, np.nan],
index=list('ABC'), dtype='object', name=1)
assert_series_equal(result, expected)

# indexing - fast_xs
df = DataFrame({'a': date_range('2014-01-01', periods=10, tz='UTC')})
result = df.iloc[5]
expected = Timestamp('2014-01-06 00:00:00+0000', tz='UTC', offset='D')
self.assertEqual(result, expected)

result = df.loc[5]
self.assertEqual(result, expected)

# indexing - boolean
result = df[df.a > df.a[3]]
expected = df.iloc[4:]
assert_frame_equal(result, expected)

def test_constructor_for_list_with_dtypes(self):
intname = np.dtype(np.int_).name
floatname = np.dtype(np.float_).name
Expand Down
52 changes: 52 additions & 0 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,58 @@ def test_loc_setitem_multiindex(self):
result = df.loc[(t,n),'X']
self.assertEqual(result,3)

def test_indexing_with_datetime_tz(self):

# 8260
# support datetime64 with tz

idx = Index(date_range('20130101',periods=3,tz='US/Eastern'),
name='foo')
dr = date_range('20130110',periods=3)
df = DataFrame({'A' : idx, 'B' : dr})
df['C'] = idx
df.iloc[1,1] = pd.NaT
df.iloc[1,2] = pd.NaT

# indexing
result = df.iloc[1]
expected = Series([Timestamp('2013-01-02 00:00:00-0500', tz='US/Eastern'), np.nan, np.nan],
index=list('ABC'), dtype='object', name=1)
assert_series_equal(result, expected)
result = df.loc[1]
expected = Series([Timestamp('2013-01-02 00:00:00-0500', tz='US/Eastern'), np.nan, np.nan],
index=list('ABC'), dtype='object', name=1)
assert_series_equal(result, expected)

# indexing - fast_xs
df = DataFrame({'a': date_range('2014-01-01', periods=10, tz='UTC')})
result = df.iloc[5]
expected = Timestamp('2014-01-06 00:00:00+0000', tz='UTC', offset='D')
self.assertEqual(result, expected)

result = df.loc[5]
self.assertEqual(result, expected)

# indexing - boolean
result = df[df.a > df.a[3]]
expected = df.iloc[4:]
assert_frame_equal(result, expected)

# indexing - setting an element
df = DataFrame( data = pd.to_datetime(['2015-03-30 20:12:32','2015-03-12 00:11:11']) ,columns=['time'] )
df['new_col']=['new','old']
df.time=df.set_index('time').index.tz_localize('UTC')
v = df[df.new_col=='new'].set_index('time').index.tz_convert('US/Pacific')

# trying to set a single element on a part of a different timezone
def f():
df.loc[df.new_col=='new','time'] = v
self.assertRaises(ValueError, f)

v = df.loc[df.new_col=='new','time'] + pd.Timedelta('1s')
df.loc[df.new_col=='new','time'] = v
assert_series_equal(df.loc[df.new_col=='new','time'],v)

def test_loc_setitem_dups(self):

# GH 6541
Expand Down