Skip to content

DataFrame constructor doesn't always upconvert datetime #2810

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

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

DataFrame constructor doesn't always upconvert datetime #2810

dalejung opened this issue Feb 7, 2013 · 7 comments
Milestone

Comments

@dalejung
Copy link
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.

@jreback
Copy link
Contributor

jreback commented Feb 7, 2013

#2752 fixes this as well

@jreback
Copy link
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]

@wesm
Copy link
Member

wesm commented Feb 9, 2013

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

@jreback
Copy link
Contributor

jreback commented Feb 9, 2013

will take a look

@jreback
Copy link
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

@jreback
Copy link
Contributor

jreback commented Feb 10, 2013

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

@wesm
Copy link
Member

wesm commented Feb 10, 2013

fixed as verified by #2834

@wesm wesm closed this as completed Feb 10, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants