Skip to content

Conversation

jreback
Copy link
Contributor

@jreback jreback commented Jun 13, 2013

closes #3888

resolves the following inconsistencies in the Timestamp/to_datetime interface
Things that do the same thing will now do the same thing!

In [1]: to_datetime = pd.to_datetime

In [2]: to_datetime('')
Out[2]: NaT

In [3]: to_datetime(['', ''])
Out[3]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[NaT, NaT]
Length: 2, Freq: None, Timezone: None

In [4]: Timestamp(0)
Out[4]: Timestamp('1970-01-01 00:00:00', tz=None)

In [5]: to_datetime(0)
Out[5]: Timestamp('1970-01-01 00:00:00', tz=None)

In [6]: to_datetime(['2012'])[0]
Out[6]: Timestamp('2012-01-01 00:00:00', tz=None)

In [8]: to_datetime('2012')
Out[8]: Timestamp('2012-01-01 00:00:00', tz=None)

In [9]: array = ['20120101','20120101 12:01:01']

In [11]: list(to_datetime(array))
Out[11]: 
[Timestamp('2012-01-01 00:00:00', tz=None),
 Timestamp('2012-01-01 12:01:01', tz=None)]

In [13]: map(Timestamp,array)
Out[13]: 
[Timestamp('2012-01-01 00:00:00', tz=None),
 Timestamp('2012-01-01 12:01:01', tz=None)]

Note that the following is still inconsisten and will be fixed in a future PR

In [14]: Timestamp('2012')
Out[14]: Timestamp('2012-06-18 00:00:00', tz=None)

In [15]: to_datetime('2012')
Out[15]: Timestamp('2012-01-01 00:00:00', tz=None)

@nehalecky
Copy link
Contributor

Look forward to this begin merged as I ran into problems due to the very inconsistencies this PR addresses. Thanks for the nice work!

@jreback
Copy link
Contributor Author

jreback commented Jun 18, 2013

great.....if you have any other things you have notice, pls let me know!

jreback added a commit that referenced this pull request Jun 19, 2013
API: (GH3888) more consistency in the to_datetime return types (given string/array of string inputs)
@jreback jreback merged commit b03df73 into pandas-dev:master Jun 19, 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

Successfully merging this pull request may close these issues.

to_datetime passed string return datetime rather than Timestamp

2 participants