Pandas中的虫子数据框.append():第二次重置为UTC时区

2024-04-29 20:13:39 发布

您现在位置:Python中文网/ 问答频道 /正文

以下是可再现性问题:

import pandas as pd

data=range(50)
df1=pd.DataFrame(data, index=pd.date_range('2013-8-1 8:00:00',freq='1S',periods=len(data))).tz_localize('Europe/Berlin')
t1=pd.date_range(df1.index[0],df1.index[-1],freq='10S')
res1=df1.groupby(df1.index).last().reindex(t1, method='ffill')
res1.index.tzinfo.zone # 'Europe/Berlin'

df2=pd.DataFrame(data, index=pd.date_range('2013-8-2 8:00:00',freq='1S',periods=len(data))).tz_localize('Europe/Berlin')
t2=pd.date_range(df2.index[0],df2.index[-1],freq='10S')
res2=df2.groupby(df2.index).last().reindex(t2, method='ffill')
res2.index.tzinfo.zone # 'Europe/Berlin'


tot=pd.DataFrame()
tot=tot.append(res1)
tot.index.tzinfo.zone #'Europe/Berlin'
tot=tot.append(res2)
tot.index.tzinfo.zone # BUG: UTC !!!!!!!!!!!!!!!!!!!!!!!!!!!!! 

# concat works instead
tot_list=[]
tot_list.append(res1)
tot_list.append(res2)
tot=pd.concat(tot_list)
tot.index.tzinfo.zone #'Europe/Berlin'

所以我们打电话给托特=合计附加(res2)第二次时区切换到UTC Alt,尽管所有涉及的对象都有柏林时区(tot,res1,res2)。你知道吗

所以我想我们可以安全地将其声明为bug。有什么意见吗?你知道吗

在任何情况下,concat产生的输出都不同于后续的append调用。这可能是一个要添加的测试用例。。。你知道吗


Tags: zonedatadateindexrangepddf1df2