DataFrame constructor doesn't always upconvert datetime #2810

Closed
dalejung opened this Issue Feb 7, 2013 · 7 comments

Comments

Projects
None yet
3 participants
Contributor

dalejung commented Feb 7, 2013

import pandas as pd
ind = pd.date_range(start="2000-01-01", freq="D", periods=10)
datetimes = [ts.to_pydatetime() for ts in ind]
dates = [ts.date() for ts in ind]

df = pd.DataFrame({'datetimes': datetimes, 'dates':dates})
df.dtypes
# datetimes : object
# dates: object

Seems to be an issue with having another object dtype in the constructor. In this case dates.

Contributor

jreback commented Feb 7, 2013

#2752 fixes this as well

Contributor

jreback commented Feb 7, 2013

In [3]: import pandas as pd

In [4]: ind = pd.date_range(start="2000-01-01", freq="D", periods=10)

In [5]: datetimes = [ts.to_pydatetime() for ts in ind]

In [6]: dates = [ts.date() for ts in ind]

In [7]: df = pd.DataFrame({'datetimes': datetimes, 'dates':dates})

In [8]: df.dtypes
Out[8]: 
dates                object
datetimes    datetime64[ns]
Owner

wesm commented Feb 9, 2013

Need to make sure this upcast only happens when all the objects are timezone naive

Contributor

jreback commented Feb 9, 2013

will take a look

Contributor

jreback commented Feb 10, 2013

@wesm

this look right?

(so non-naive timezone datetimes are not cast to datetime64[ns]) - this is off of master btw

In [36]: dr = pd.date_range('2011/1/1', '2012/1/1', freq='W-FRI')

In [37]: dr_tz = dr.tz_localize('US/Eastern')

In [38]: datetimes_with_tz = [ts.to_pydatetime() for ts in dr_tz ]

In [43]: datetimes_naive = [ ts.to_pydatetime() for ts in dr ]

In [44]: df = pd.DataFrame({'dr' : dr, 'dr_
                                        tz' : dr_tz, 
                                        'datetimes_naive': datetimes_naive, 
                                        'datetimes_with_tz' : datetimes_with_tz })

In [45]: df.dtypes
Out[45]: 
datetimes_naive      datetime64[ns]
datetimes_with_tz            object
dr                   datetime64[ns]
dr_tz                datetime64[ns]
Dtype: object

Contributor

jreback commented Feb 10, 2013

#2834 has tests for this (but master has the above behavior)

Owner

wesm commented Feb 10, 2013

fixed as verified by #2834

wesm closed this Feb 10, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment