Skip to content

pd.concat reset the tz-aware index to UTC #18422

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
alessioarena opened this issue Nov 22, 2017 · 5 comments
Closed

pd.concat reset the tz-aware index to UTC #18422

alessioarena opened this issue Nov 22, 2017 · 5 comments
Labels
Reshaping Concat, Merge/Join, Stack/Unstack, Explode Timezones Timezone data dtype

Comments

@alessioarena
Copy link

Hi,

Having two DataFrames with index being tz-aware Timestamp objects

print(concat_df[0].index.tz, concat_df[1].index.tz)
fxt = pd.concat(concat_df, axis=1)
print(fxt.index.tz)

This leads to the following output

Australia/Melbourne Australia/Melbourne
UTC

I believe this may be in some way related to #7562

pandas version = 0.21.0

@jreback
Copy link
Contributor

jreback commented Nov 22, 2017

pls show a copy pastable example

@sinhrks sinhrks added Can't Repro Reshaping Concat, Merge/Join, Stack/Unstack, Explode Timezones Timezone data dtype labels Nov 22, 2017
@sinhrks
Copy link
Member

sinhrks commented Nov 22, 2017

Thanks for the report. Unfortunatelly, I couldn't reproduce the issue using 0.21.0. Can you attach reproducible code and pd.show_versions()?

import pandas as pd

idx = pd.date_range('2011-01-01', periods=3, freq='H', 
                    tz='Australia/Melbourne')
df = pd.DataFrame({'a': [1, 2, 3]}, index=idx)

res = pd.concat([df, df], axis=1)
res.index.tz
# <DstTzInfo 'Australia/Melbourne' LMT+9:40:00 STD>

@alessioarena
Copy link
Author

Hi there,

Unfortunately those files are quite large, and I cannot upload them.
I tried to make some synthetic data and also could not reproduce it.

However I have some additional information about this issue:

The first dataset (df_concat[0]) has a Timestamp object converted from UTC as following:

dft['local_time'] = pd.to_datetime(dft.timestamp_utc, utc=True, format="%d/%m/%Y %H:%M:%S")
dft.index = dft.index.tz_convert('Australia/Melbourne')

This lead to
<DstTzInfo 'Australia/Melbourne' LMT+9:40:00 STD>

The second dataset (df_concat[1]) has the Timestamp object being localized as following
df.index = df.index.tz_localize('Australia/Melbourne', ambiguous=np.ones(len(df.index), dtype=bool))
This lead to
<DstTzInfo 'Australia/Melbourne' AEDT+11:00:00 DST>

As you can see the resulting timezones are both Australia/Melbourne, but they are expressed differently.
I believe that this is the cause of the problem describe, and I also suspect that the datasets are misaligned during this operation. I will do more testing on this and update you.

@antvig
Copy link

antvig commented Nov 27, 2017

Hi,
I get the same issue, one of my DataFrame index is <DstTzInfo 'Europe/Paris' CET+1:00:00 STD>, and the other one is <DstTzInfo 'Europe/Paris' LMT+0:09:00 STD>.
When I concatenate the two dataframe, the resulting dataframe index is in UTC.

I work with Pandas 18.0 but I guess this is the same "issue" (maybe it's not really an issue)

@jreback
Copy link
Contributor

jreback commented Nov 27, 2017

closing as no repro.

If you have a copy-pastable example pls open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reshaping Concat, Merge/Join, Stack/Unstack, Explode Timezones Timezone data dtype
Projects
None yet
Development

No branches or pull requests

4 participants