Skip to content

Commit 64b6c8c

Browse files
jrebackmattip
authored andcommitted
BUG: bug in .at/.loc indexing with a tz-aware columns
closes pandas-dev#15822 Author: Jeff Reback <[email protected]> Closes pandas-dev#15827 from jreback/at and squashes the following commits: 4fcd2c6 [Jeff Reback] BUG: bug in .at/.loc indexing with a tz-aware columns
1 parent f0c3954 commit 64b6c8c

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,7 @@ Bug Fixes
881881

882882
- Compat for 32-bit platforms for ``.qcut/cut``; bins will now be ``int64`` dtype (:issue:`14866`)
883883

884+
- Bug in ``.at`` when selecting from a tz-aware column (:issue:`15822`)
884885
- Bug in the display of ``.info()`` where a qualifier (+) would always be displayed with a ``MultiIndex`` that contains only non-strings (:issue:`15245`)
885886
- Bug in ``.replace()`` may result in incorrect dtypes. (:issue:`12747`, :issue:`15765`)
886887

pandas/core/frame.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,16 @@ def get_value(self, index, col, takeable=False):
19181918

19191919
series = self._get_item_cache(col)
19201920
engine = self.index._engine
1921-
return engine.get_value(series.get_values(), index)
1921+
1922+
try:
1923+
return engine.get_value(series._values, index)
1924+
except TypeError:
1925+
1926+
# we cannot handle direct indexing
1927+
# use positional
1928+
col = self.columns.get_loc(col)
1929+
index = self.index.get_loc(index)
1930+
return self.get_value(index, col, takeable=True)
19221931

19231932
def set_value(self, index, col, value, takeable=False):
19241933
"""

pandas/tests/indexing/test_scalar.py

+15
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,18 @@ def test_at_to_fail(self):
154154
# Check that we get the correct value in the KeyError
155155
self.assertRaisesRegexp(KeyError, r"\['y'\] not in index",
156156
lambda: df[['x', 'y', 'z']])
157+
158+
def test_at_with_tz(self):
159+
# gh-15822
160+
df = DataFrame({'name': ['John', 'Anderson'],
161+
'date': [Timestamp(2017, 3, 13, 13, 32, 56),
162+
Timestamp(2017, 2, 16, 12, 10, 3)]})
163+
df['date'] = df['date'].dt.tz_localize('Asia/Shanghai')
164+
165+
expected = Timestamp('2017-03-13 13:32:56+0800', tz='Asia/Shanghai')
166+
167+
result = df.loc[0, 'date']
168+
assert result == expected
169+
170+
result = df.at[0, 'date']
171+
assert result == expected

0 commit comments

Comments
 (0)