Not exactly what you want I fear. But it might help:
I used this dataset http://archive.ics.uci.edu/ml/datasets/Occupancy+Detection+# for testing.
For datetime indexes dates and strings that parse to timestamps can be passed as indexing parameters and as before
and after
parameters for truncate
as well as pd.Timestamp
.
In [1]: import pandas as pd
In [2]: df = pd.read_csv('datatest2.txt', parse_dates=[1], index_col=[1])
In [3]: df.index
Out[3]:
DatetimeIndex(['2015-02-11 14:48:00', '2015-02-11 14:49:00',
'2015-02-11 14:50:00', '2015-02-11 14:51:00',
'2015-02-11 14:51:59', '2015-02-11 14:53:00',
'2015-02-11 14:54:00', '2015-02-11 14:55:00',
'2015-02-11 14:55:59', '2015-02-11 14:57:00',
...
'2015-02-18 09:10:00', '2015-02-18 09:10:59',
'2015-02-18 09:11:59', '2015-02-18 09:13:00',
'2015-02-18 09:14:00', '2015-02-18 09:15:00',
'2015-02-18 09:16:00', '2015-02-18 09:16:59',
'2015-02-18 09:17:59', '2015-02-18 09:19:00'],
dtype='datetime64[ns]', name='date', length=9752, freq=None)
In [4]: df['2015-02-12':'2015-02-13'].index
Out[4]:
DatetimeIndex(['2015-02-12 00:00:00', '2015-02-12 00:01:00',
'2015-02-12 00:02:00', '2015-02-12 00:03:00',
'2015-02-12 00:04:00', '2015-02-12 00:04:59',
'2015-02-12 00:06:00', '2015-02-12 00:07:00',
'2015-02-12 00:08:00', '2015-02-12 00:08:59',
...
'2015-02-13 23:50:00', '2015-02-13 23:51:00',
'2015-02-13 23:51:59', '2015-02-13 23:53:00',
'2015-02-13 23:54:00', '2015-02-13 23:55:00',
'2015-02-13 23:55:59', '2015-02-13 23:57:00',
'2015-02-13 23:57:59', '2015-02-13 23:58:59'],
dtype='datetime64[ns]', name='date', length=2880, freq=None)
In [5]: df.truncate(before=pd.Timestamp('2015-02-12'), after=pd.Timestamp('2015-02-14')).index
Out[5]:
DatetimeIndex(['2015-02-12 00:00:00', '2015-02-12 00:01:00',
'2015-02-12 00:02:00', '2015-02-12 00:03:00',
'2015-02-12 00:04:00', '2015-02-12 00:04:59',
'2015-02-12 00:06:00', '2015-02-12 00:07:00',
'2015-02-12 00:08:00', '2015-02-12 00:08:59',
...
'2015-02-13 23:51:00', '2015-02-13 23:51:59',
'2015-02-13 23:53:00', '2015-02-13 23:54:00',
'2015-02-13 23:55:00', '2015-02-13 23:55:59',
'2015-02-13 23:57:00', '2015-02-13 23:57:59',
'2015-02-13 23:58:59', '2015-02-14 00:00:00'],
dtype='datetime64[ns]', name='date', length=2881, freq=None)
In [6]: df.truncate(before='2015-02-12', after='2015-02-14').index
Out[6]:
DatetimeIndex(['2015-02-12 00:00:00', '2015-02-12 00:01:00',
'2015-02-12 00:02:00', '2015-02-12 00:03:00',
'2015-02-12 00:04:00', '2015-02-12 00:04:59',
'2015-02-12 00:06:00', '2015-02-12 00:07:00',
'2015-02-12 00:08:00', '2015-02-12 00:08:59',
...
'2015-02-13 23:51:00', '2015-02-13 23:51:59',
'2015-02-13 23:53:00', '2015-02-13 23:54:00',
'2015-02-13 23:55:00', '2015-02-13 23:55:59',
'2015-02-13 23:57:00', '2015-02-13 23:57:59',
'2015-02-13 23:58:59', '2015-02-14 00:00:00'],
dtype='datetime64[ns]', name='date', length=2881, freq=None)
In [7]: df.truncate(before='2015-02-12 01:00:00', after='2015-02-13 23:00:00').index
Out[7]:
DatetimeIndex(['2015-02-12 01:00:00', '2015-02-12 01:01:00',
'2015-02-12 01:01:59', '2015-02-12 01:02:59',
'2015-02-12 01:04:00', '2015-02-12 01:05:00',
'2015-02-12 01:06:00', '2015-02-12 01:07:00',
'2015-02-12 01:08:00', '2015-02-12 01:08:59',
...
'2015-02-13 22:51:00', '2015-02-13 22:52:00',
'2015-02-13 22:53:00', '2015-02-13 22:53:59',
'2015-02-13 22:54:59', '2015-02-13 22:56:00',
'2015-02-13 22:57:00', '2015-02-13 22:58:00',
'2015-02-13 22:59:00', '2015-02-13 22:59:59'],
dtype='datetime64[ns]', name='date', length=2761, freq=None)
Hence I think you need to only modify your function to validate whether valid dates (and times) were passed.