API: (GH3888) more consistency in the to_datetime return types (given string/array of string inputs) by jreback · Pull Request #3890 · pandas-dev/pandas (original) (raw)

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)]
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)