Skip to content

Commit e97b3a6

Browse files
committed
BUG: truncate will only try to convert to dates for an all_dates index
1 parent e9db5f2 commit e97b3a6

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

pandas/core/generic.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1159,9 +1159,13 @@ def truncate(self, before=None, after=None, copy=True):
11591159
-------
11601160
truncated : type of caller
11611161
"""
1162-
from pandas.tseries.tools import to_datetime
1163-
before = to_datetime(before)
1164-
after = to_datetime(after)
1162+
1163+
# if we have a date index, convert to dates, otherwise
1164+
# treat like a slice
1165+
if self.index.is_all_dates:
1166+
from pandas.tseries.tools import to_datetime
1167+
before = to_datetime(before)
1168+
after = to_datetime(after)
11651169

11661170
if before is not None and after is not None:
11671171
if before > after:

pandas/tseries/tests/test_timeseries.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ def test_to_datetime_types(self):
846846

847847
### array = ['2012','20120101','20120101 12:01:01']
848848
array = ['20120101','20120101 12:01:01']
849-
expected = to_datetime(array)
849+
expected = list(to_datetime(array))
850850
result = map(Timestamp,array)
851851
tm.assert_almost_equal(result,expected)
852852

0 commit comments

Comments
 (0)