pydata/pandas — pull request #2595 by jreback (2012-12-25 04:48:59+00:00)
Title: BUG: provide for automatic conversion of object -> datetime64[ns] 

```
In [1]: import numpy as np

In [2]: import pandas as pd
```

This currently works

```
In [12]: df = pd.DataFrame(np.random.randn(8,2),pd.date_range('20010102',periods=8),columns=['A','B'])

In [13]: df['timestamp'] = pd.Timestamp('20010103')

In [14]: x = df.convert_objects()

In [15]: x
Out[15]:
A B timestamp
2001-01-02 -0.228005 -1.376432 2001-01-03 00:00:00
2001-01-03 -0.555251 0.277356 2001-01-03 00:00:00
2001-01-04 -0.295289 0.534981 2001-01-03 00:00:00
2001-01-05 -0.332815 -1.436975 2001-01-03 00:00:00
2001-01-06 -1.848818 0.405773 2001-01-03 00:00:00
2001-01-07 -0.734903 -0.174140 2001-01-03 00:00:00
2001-01-08 -0.388864 -0.765329 2001-01-03 00:00:00
2001-01-09 -0.341015 0.170630 2001-01-03 00:00:00

In [16]: x.get_dtype_counts()
Out[16]:
datetime64[ns] 1
float64 2

In [21]: x.ix[3,'timestamp'] = iNaT

In [22]: x
Out[22]:
A B timestamp
2001-01-02 -0.228005 -1.376432 2001-01-03 00:00:00
2001-01-03 -0.555251 0.277356 2001-01-03 00:00:00
2001-01-04 -0.295289 0.534981 2001-01-03 00:00:00
2001-01-05 -0.332815 -1.436975 NaT
2001-01-06 -1.848818 0.405773 2001-01-03 00:00:00
2001-01-07 -0.734903 -0.174140 2001-01-03 00:00:00
2001-01-08 -0.388864 -0.765329 2001-01-03 00:00:00
2001-01-09 -0.341015 0.170630 2001-01-03 00:00:00

```

This leaves you in limbo, as you have basically a datatime64 column, but with a float nan in it (so it has to stay object)
```
In [3]: df = pd.DataFrame(np.random.randn(8,2),pd.date_range('20010102',periods=8),columns=['A','B'])

In [4]: df
Out[4]:
A B
2001-01-02 0.939393 -2.524448
2001-01-03 -1.059561 0.104651
2001-01-04 -0.842478 1.033888
2001-01-05 -1.009903 -0.334782
2001-01-06 -0.452043 -0.382408
2001-01-07 -0.058516 1.162884
2001-01-08 0.660251 0.688290
2001-01-09 0.069637 0.366915

In [5]: df['timestamp'] = pd.Timestamp('20010103')

In [6]: df
Out[6]:
A B timestamp
2001-01-02 0.939393 -2.524448 2001-01-03 00:00:00
2001-01-03 -1.059561 0.104651 2001-01-03 00:00:00
2001-01-04 -0.842478 1.033888 2001-01-03 00:00:00
2001-01-05 -1.009903 -0.334782 2001-01-03 00:00:00
2001-01-06 -0.452043 -0.382408 2001-01-03 00:00:00
2001-01-07 -0.058516 1.162884 2001-01-03 00:00:00
2001-01-08 0.660251 0.688290 2001-01-03 00:00:00
2001-01-09 0.069637 0.366915 2001-01-03 00:00:00

In [7]: df.get_dtype_counts()
Out[7]:
float64 2
object 1

In [8]: df.convert_objects().get_dtype_counts()
Out[8]:
datetime64[ns] 1
float64 2

In [9]: df.ix[3,'timestamp'] = np.nan

In [10]: df
Out[10]:
A B timestamp
2001-01-02 0.939393 -2.524448 2001-01-03 00:00:00
2001-01-03 -1.059561 0.104651 2001-01-03 00:00:00
2001-01-04 -0.842478 1.033888 2001-01-03 00:00:00
2001-01-05 -1.009903 -0.334782 NaN
2001-01-06 -0.452043 -0.382408 2001-01-03 00:00:00
2001-01-07 -0.058516 1.162884 2001-01-03 00:00:00
2001-01-08 0.660251 0.688290 2001-01-03 00:00:00
2001-01-09 0.069637 0.366915 2001-01-03 00:00:00

In [11]: df.convert_objects().get_dtype_counts()
Out[11]:
float64 2
object 1
```

This PR enables this syntax:

```
In [3]: df = pd.DataFrame(np.random.randn(8,2),pd.date_range('20010102',periods=8),columns=['A','B'])

In [4]: df['timestamp'] = pd.Timestamp('20010103')

# datetime64[ns] out of the box
In [5]: df.get_dtype_counts()
Out[5]:
datetime64[ns] 1
float64 2

# use the traditional nan, which is mapped to iNaT internally
In [6]: df.ix[2:4,'timestamp'] = np.nan

In [7]: df
Out[7]:
A B timestamp
2001-01-02 0.234354 -3.167626 2001-01-03 00:00:00
2001-01-03 0.141300 -0.548670 2001-01-03 00:00:00
2001-01-04 0.738884 -0.104497 NaT
2001-01-05 0.873046 1.193593 NaT
2001-01-06 1.174226 1.697421 2001-01-03 00:00:00
2001-01-07 -0.069534 -0.145611 2001-01-03 00:00:00
2001-01-08 -0.951426 -1.158884 2001-01-03 00:00:00
2001-01-09 -0.322041 -0.800181 2001-01-03 00:00:00

```