Skip to content

Append with two DateTimeIndex returns Index and not DateTimeIndex #14795

Closed
@rsheftel

Description

@rsheftel

In 0.19.1 appending a DateTimeIndex to another DateTimeIndex where they have different time zones now returns an Index object. In 0.18.1 it would return a DateTimeIndex with a UTC time zone.

In 0.19.1 (and in 0.18.1) if the two DateTimeIndex have the same time zone a DateTimeIndex is returned. I believe the behavior in 0.18.1 of returning a DateTimeIndex with time zone UTC should be the correct behavior.

--- Example of the problem ---

import pandas as pd

df1 = pd.DataFrame({'a': [1, 2, 3]}, index=pd.date_range('1990-02-01 09:00:00', periods=3, freq='1min', tz='America/New_York'))
df2 = pd.DataFrame({'a': [4, 5, 6]}, index=pd.date_range('1990-02-01 08:03:00', periods=3, freq='1min', tz='America/Chicago'))

print(df1.index.tzinfo)  # America/New_York
print(df2.index.tzinfo)  # America/Chicago

result = df1.index.append(df2.index)

print(type(new_index))
print(type(result))

>> pandas 0.18.1 returns <class 'pandas.tseries.index.DatetimeIndex'>
>> pandas 0.19.1 returns <class 'pandas.indexes.base.Index'>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions