Skip to content

to_datetime conversion inconsistency in 0.15.0 #8615

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
pmart123 opened this issue Oct 23, 2014 · 4 comments
Closed

to_datetime conversion inconsistency in 0.15.0 #8615

pmart123 opened this issue Oct 23, 2014 · 4 comments

Comments

@pmart123
Copy link

to_datetime is not converting input consistently between a pandas series or a python list of either strings or datetime objects. for example:

import pandas as pd
s = pd.Series(['102214','102314'])
df = pd.Series({'dates':['102214','102314']})
lst = ['102214','102314']

pd.to_datetime(s,format='%m%d%y') and pd.to_datetime(df['dates'],format='%m%d%y') return a numpy.datetime64 ndarray, while pd.to_datetime(lst,format='%m%d%y') returns a pandas.DateTimeIndex object. Is this behavior an expected result in 0.15.0?

@jorisvandenbossche
Copy link
Member

The actual values will be the same, but the object type of the output that holds those values depends on the input type: by default it created a DatetimeIndex (eg for lists, arrays, etc as input), only when passed a Series, the output will also be a Series.

See http://pandas.pydata.org/pandas-docs/stable/timeseries.html#converting-to-timestamps as explained in the docs, but this should actually also be stated in the docstring here http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html

@jreback
Copy link
Contributor

jreback commented Oct 23, 2014

this is correct and expected

In [5]: pd.to_datetime(s,format='%m%d%y')
Out[5]: 
0   2014-10-22
1   2014-10-23
dtype: datetime64[ns]

In [6]: pd.to_datetime(df['dates'],format='%m%d%y')
Out[6]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2014-10-22, 2014-10-23]
Length: 2, Freq: None, Timezone: None

In [7]: pd.to_datetime(lst,format='%m%d%y')
Out[7]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2014-10-22, 2014-10-23]
Length: 2, Freq: None, Timezone: None

[6] and [7] are lists, while [5] is a series (so it returns the same).

@jorisvandenbossche
Copy link
Member

Are you interested in making a PR to add this to the docstring? (otherwise I will do it quickly)

@jorisvandenbossche
Copy link
Member

This was closed by #8921

@jorisvandenbossche jorisvandenbossche added this to the 0.15.2 milestone Jul 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants