get localized Timestamp using ".at" cannot get the time zone info · Issue #15822 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

data = {'name':['John', 'Anderson'], 'date':[pd.Timestamp(2017,3,13,13,32,56), pd.Timestamp(2017,2,16,12,10,3)]}
test_df = pd.DataFrame(data=data)
test_df['date'] = test_df['date'].map(lambda x:x.tz_localize('Asia/Shanghai'))

In [18]: test_df.at[0,'date']
Out[18]: Timestamp('2017-03-13 05:32:56')

In [19]: test_df.loc[0,'date']
Out[19]: Timestamp('2017-03-13 13:32:56+0800', tz='Asia/Shanghai')

Problem description

The sample code is as above.
I have a column in DataFrame that contains the datetime values which are Timestamp object in pandas.
After I localise the timestamp, while using .at getter and .loc getter, I get different results.
One is without time zone info, the other is with time zone info.

Is this a bug? How can I get the timestamp with time zone info using ".at" getter?

Expected Output

test_df.at[0,'date']
Timestamp('2017-03-13 13:32:56+0800', tz='Asia/Shanghai')

Output of pd.show_versions()

# Paste the output here pd.show_versions() here

In [20]: pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 2.7.6.final.0
python-bits: 64
OS: Linux
OS-release: 3.19.0-66-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_HK.UTF-8
LOCALE: None.None

pandas: 0.19.2
nose: 1.3.7
pip: 9.0.1
setuptools: 25.1.1
Cython: 0.24.1
numpy: 1.12.1
scipy: 0.18.1
statsmodels: None
xarray: None
IPython: 5.0.0
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999
httplib2: 0.8
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
boto: None
pandas_datareader: None