Skip to content

Commit 03bee8d

Browse files
committed
BUG: fix data borking in to_datetime called on Series with datetime64 values already. close #2699
1 parent d19c205 commit 03bee8d

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

RELEASE.rst

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ pandas 0.10.1
8181
- Fix a Cython C int64 boxing issue causing read_csv to return incorrect
8282
results (GH2599_)
8383
- Fix groupby summing performance issue on boolean data (GH2692_)
84+
- Don't bork Series containing datetime64 values with to_datetime (GH2699_)
8485

8586
**API Changes**
8687

@@ -103,6 +104,7 @@ pandas 0.10.1
103104
.. _GH2637: https://github.com/pydata/pandas/issues/2637
104105
.. _GH2690: https://github.com/pydata/pandas/issues/2690
105106
.. _GH2692: https://github.com/pydata/pandas/issues/2692
107+
.. _GH2699: https://github.com/pydata/pandas/issues/2699
106108

107109
pandas 0.10.0
108110
=============

pandas/tseries/tests/test_timeseries.py

+7
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,13 @@ def test_to_datetime_default(self):
673673
xp = datetime(2001, 1, 1)
674674
self.assert_(rs, xp)
675675

676+
def test_to_datetime_on_datetime64_series(self):
677+
# #2699
678+
s = Series(date_range('1/1/2000', periods=10))
679+
680+
result = to_datetime(s)
681+
self.assertEquals(result[0], s[0])
682+
676683
def test_nat_vector_field_access(self):
677684
idx = DatetimeIndex(['1/1/2000', None, None, '1/4/2000'])
678685

pandas/tseries/tools.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ def _convert_f(arg):
8989
elif isinstance(arg, datetime):
9090
return arg
9191
elif isinstance(arg, Series):
92-
values = _convert_f(arg.values)
92+
values = arg.values
93+
if not com.is_datetime64_dtype(values):
94+
values = _convert_f(values)
9395
return Series(values, index=arg.index, name=arg.name)
9496
elif isinstance(arg, (np.ndarray, list)):
9597
if isinstance(arg, list):

0 commit comments

Comments
 (0)