Repository: pandas-dev/pandas

Issue:
to_datetime passed string return datetime rather than Timestamp
It seems it returns different objects when passed array vs string:

```
In [1]: pd.to_datetime(['2012'])[0]
Out[1]: Timestamp('2012-01-01 00:00:00', tz=None)

In [2]: pd.to_datetime('2012')
Out[2]: datetime.datetime(2012, 1, 1, 0, 0)
```

Also worth mentioning (though different):

```
In [3]: pd.Timestamp('2012')
Out[3]: Timestamp('2012-06-13 00:00:00', tz=None)
```

Seems a little inconsistent... (cc #3859)



Discussion:
```
to_datetime('')
NaT
```

now....before return the empty_string...

better?


Resolving patch:
diff --git a/pandas/core/generic.py b/pandas/core/generic.py
--- a/pandas/core/generic.py
+++ b/pandas/core/generic.py
@@ -1159,9 +1159,13 @@ def truncate(self, before=None, after=None, copy=True):
     -------
     truncated : type of caller
     """
-    from pandas.tseries.tools import to_datetime
-    before = to_datetime(before)
-    after = to_datetime(after)
+
+    # if we have a date index, convert to dates, otherwise
+    # treat like a slice
+    if self.index.is_all_dates:
+        from pandas.tseries.tools import to_datetime
+        before = to_datetime(before)
+        after = to_datetime(after)
 
     if before is not None and after is not None:
         if before > after:
diff --git a/pandas/tseries/tools.py b/pandas/tseries/tools.py
--- a/pandas/tseries/tools.py
+++ b/pandas/tseries/tools.py
@@ -99,16 +99,7 @@ def _convert_f(arg):
             except (ValueError, TypeError):
                 raise e
 
-    if arg is None:
-        return arg
-    elif isinstance(arg, datetime):
-        return arg
-    elif isinstance(arg, Series):
-        values = arg.values
-        if not com.is_datetime64_dtype(values):
-            values = _convert_f(values)
-        return Series(values, index=arg.index, name=arg.name)
-    elif isinstance(arg, (np.ndarray, list)):
+    def _convert_listlike(arg):        
         if isinstance(arg, list):
             arg = np.array(arg, dtype='O')
 
@@ -122,24 +113,23 @@ def _convert_f(arg):
                         return DatetimeIndex._simple_new(values, None, tz=tz)
                     except (ValueError, TypeError):
                         raise e
-            return arg
+                return arg
 
-        try:
-            return _convert_f(arg)
-        except ValueError:
-            raise
-        return arg
+        return _convert_f(arg)
 
-    try:
-        if not arg:
-            return arg
-        default = datetime(1, 1, 1)
-        return parse(arg, dayfirst=dayfirst, default=default)
-    except Exception:
-        if errors == 'raise':
-            raise
+    if arg is None:
         return arg
+    elif isinstance(arg, datetime):
+        return arg
+    elif isinstance(arg, Series):
+        values = arg.values
+        if not com.is_datetime64_dtype(values):
+            values = _convert_f(values)
+        return Series(values, index=arg.index, name=arg.name)
+    elif isinstance(arg, (np.ndarray, list)):
+        return _convert_listlike(arg)
 
+    return _convert_listlike(np.array([ arg ], dtype='O'))[0]
 
 class DateParseError(ValueError):
     pass


Test patch:
diff --git a/pandas/tseries/tests/test_timeseries.py b/pandas/tseries/tests/test_timeseries.py
--- a/pandas/tseries/tests/test_timeseries.py
+++ b/pandas/tseries/tests/test_timeseries.py
@@ -825,13 +825,36 @@ def test_nat_scalar_field_access(self):
 
         self.assertEquals(NaT.weekday(), -1)
 
-    def test_to_datetime_empty_string(self):
+    def test_to_datetime_types(self):
+
+        # empty string
         result = to_datetime('')
-        self.assert_(result == '')
+        self.assert_(result is NaT)
 
         result = to_datetime(['', ''])
         self.assert_(isnull(result).all())
 
+        # ints
+        result = Timestamp(0)
+        expected = to_datetime(0)
+        self.assert_(result == expected)
+
+        # GH 3888 (strings)
+        expected = to_datetime(['2012'])[0]
+        result = to_datetime('2012')
+        self.assert_(result == expected)
+
+        ### array = ['2012','20120101','20120101 12:01:01']
+        array = ['20120101','20120101 12:01:01']
+        expected = list(to_datetime(array))
+        result = map(Timestamp,array)
+        tm.assert_almost_equal(result,expected)
+
+        ### currently fails ###
+        ### result = Timestamp('2012')
+        ### expected = to_datetime('2012')
+        ### self.assert_(result == expected)
+
     def test_to_datetime_other_datetime64_units(self):
         # 5/25/2012
         scalar = np.int64(1337904000000000).view('M8[us]')