BUG: DataFrame(dict_of_series) raises depending on order of dict · Issue #44091 · pandas-dev/pandas (original) (raw)
- I have checked that this issue has not already been reported.
- I have confirmed this bug exists on the latest version of pandas.
- I have confirmed this bug exists on the master branch of pandas.
Reproducible Example
dti = pd.date_range("2016-01-01", periods=3) ser1 = pd.Series(range(3), index=dti) ser2 = pd.Series(range(3), index=dti.tz_localize("UTC")) ser3 = pd.Series(range(3))
pd.DataFrame({"A": ser3, "B": ser2, "C": ser1}) # works fine
pd.DataFrame({"A": ser1, "B": ser2, "C": ser3}) TypeError: Cannot join tz-naive with tz-aware DatetimeIndex
Issue Description
When we pass a dict of Series, we end up going through indexes.api.union_indexes, which checks if our first index is a DatetimeIndex and if so dispatches to DatetimeIndex.union_many, which in this case raises. If the DatetimeIndex is not first, then it goes through Index.union and casts to object.
Then there's the issue that we don't pass sort
to union_many so it gets ignored.
Expected Behavior
Cast to object.
Installed Versions
Replace this line with the output of pd.show_versions()