-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: DataFrame.append fails to append tz-aware column to empty DataFrame #12985
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
Comments
hmm, thought we fixed all of the concat issues. |
I'm able to make this problem go away with this patch:
I'd submit a PR but I'm not sure if that works the way the |
this patch may solve a couple of issues |
@ajenkins-cargometrics Do you want to do a PR for this patch? |
If you are happy with this patch I can make a PR with tests tonight? We're very keen to see this in 19 if it's not too late. |
if u want to out up a PR with tests great |
Hi, sorry for ignoring this for a bit. The reason I hadn't submitted a PR is because it turns out my simple fix doesn't really work correctly. I wrote a test for it, which you can see here: https://github.com/pydata/pandas/compare/master...ajenkins-cargometrics:GH12985?expand=1 which fails because the dtypes of the columns end up changing when appending to an empty DataFrame. I tried changing the test to pass It seems that a more complicated fix is necessary to preserve custom dtypes when appending to an empty DataFrame. It wasn't obvious to me where to make this fix, and unfortunately I don't have a lot of time right now to work on it. |
This wasn't obvious to me, but it doesn't just fail for empty dataframes. import pandas as pd
df1 = pd.DataFrame({'a': pd.Categorical(['a', 'b', 'c']), 'b': [pd.NaT]*3})
df2 = pd.DataFrame({'a': pd.Categorical(['a', 'b', 'a', 'c']), 'b': pd.date_range('2015', periods=4, tz='utc')})
df1.append(df2) I've tried, but not found, ways to preserve the extended dtype on the empty columns; probably because these internals are quite new to me. Would it be unacceptable to introduce ajenkins-cargometrics' change, which might convert 'b' above to object but at least not break or reduce any information? IMO it would be an improvement. |
you can try to introduce that fix and see what happens (need several addtl tests) |
…ware (due to this issue: pandas-dev/pandas#12985)
I just faced this problem. Is this bug open for almost a year since reported? |
dupe of #12396 |
I have also just encountered this bug. |
This is something that works in pandas 0.16.2 but fails in pandas 0.18. If you append to an empty DataFrame, and the DataFrame you are appending contains a tz-aware datetime column, the append fails.
Here is the failure I get:
The error is because pandas is passing an instance of DatetimeTZDtype to numpy, and numpy doesn't recognize it as a valid dtype.
output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: