Skip to content
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

BUG: tz lost on combine first/fillna #7630

Closed
jreback opened this issue Jul 1, 2014 · 3 comments
Closed

BUG: tz lost on combine first/fillna #7630

jreback opened this issue Jul 1, 2014 · 3 comments
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Timezones Timezone data dtype
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Jul 1, 2014

http://stackoverflow.com/questions/24502838/pandas-tzinfo-lost-by-combine-first

In [10]: df1 = pd.DataFrame(columns=['UTCdatetime','abc'],
   ....:                   data=pd.to_datetime('20100101 01:01').tz_localize('UTC'),
   ....:                   index=pd.date_range('20140627', periods=1))

In [11]: print(df1)
                          UTCdatetime                        abc
2014-06-27  2010-01-01 01:01:00+00:00  2010-01-01 01:01:00+00:00

In [12]: df2 = pd.DataFrame(columns=['UTCdatetime','xyz'],
   ....:                   data=pd.to_datetime('20121212 12:12').tz_localize('UTC'),
   ....:                   index=pd.date_range('20140628', periods=1))

In [13]: 

In [13]: df1
Out[13]: 
                          UTCdatetime                        abc
2014-06-27  2010-01-01 01:01:00+00:00  2010-01-01 01:01:00+00:00

In [14]: df2
Out[14]: 
                          UTCdatetime                        xyz
2014-06-28  2012-12-12 12:12:00+00:00  2012-12-12 12:12:00+00:00

In [15]: df1.dtypes
Out[15]: 
UTCdatetime    object
abc            object
dtype: object

In [16]: df2.dtypes
Out[16]: 
UTCdatetime    object
xyz            object
dtype: object

In [17]: df2[['UTCdatetime']].combine_first(df1)
Out[17]: 
                   UTCdatetime                        abc
2014-06-27 2010-01-01 01:01:00  2010-01-01 01:01:00+00:00
2014-06-28 2012-12-12 12:12:00                        NaN

In [18]: df2[['UTCdatetime']].combine_first(df1).dtypes
Out[18]: 
UTCdatetime    datetime64[ns]
abc                    object
dtype: object
@jreback jreback added this to the 0.15.0 milestone Jul 1, 2014
@fantabolous
Copy link

This also happened with fillna, so perhaps it's a more wide-ranging problem?

    utcdate = pd.to_datetime('20000101', utc=True)
    df1 = pd.DataFrame(columns=['UTCdatetime'], data=utcdate, index=pd.date_range('20140627', periods=1))
    print(df1)
    df1 = df1.fillna(utcdate)
    print(df1)

                          UTCdatetime
2014-06-27  2000-01-01 00:00:00+00:00

           UTCdatetime
2014-06-27  2000-01-01

@jreback
Copy link
Contributor Author

jreback commented Jul 2, 2014

this is a related issue, its marked as a bug. feel free to do a pull-request to fix.

@jreback jreback changed the title BUG: tz lost on combine first BUG: tz lost on combine first/fillna Jul 2, 2014
@fantabolous
Copy link

Thanks. As much as I'd love to fix it pandas is my first foray into really programming so I think I'd probably do more harm than good at this stage.. ;) Later hopefully!

@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 6, 2015
@jreback jreback modified the milestones: 0.19.0, Next Major Release Aug 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants