Skip to content

BUG: bug in .at/.loc indexing with a tz-aware columns #15827

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

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ Bug Fixes

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

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

Expand Down
11 changes: 10 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1918,7 +1918,16 @@ def get_value(self, index, col, takeable=False):

series = self._get_item_cache(col)
engine = self.index._engine
return engine.get_value(series.get_values(), index)

try:
return engine.get_value(series._values, index)
except TypeError:

# we cannot handle direct indexing
# use positional
col = self.columns.get_loc(col)
index = self.index.get_loc(index)
return self.get_value(index, col, takeable=True)

def set_value(self, index, col, value, takeable=False):
"""
Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/indexing/test_scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,18 @@ def test_at_to_fail(self):
# Check that we get the correct value in the KeyError
self.assertRaisesRegexp(KeyError, r"\['y'\] not in index",
lambda: df[['x', 'y', 'z']])

def test_at_with_tz(self):
# gh-15822
df = DataFrame({'name': ['John', 'Anderson'],
'date': [Timestamp(2017, 3, 13, 13, 32, 56),
Timestamp(2017, 2, 16, 12, 10, 3)]})
df['date'] = df['date'].dt.tz_localize('Asia/Shanghai')

expected = Timestamp('2017-03-13 13:32:56+0800', tz='Asia/Shanghai')

result = df.loc[0, 'date']
assert result == expected

result = df.at[0, 'date']
assert result == expected