Indexing a pandas DatetimeIndex (with dtype numpy datetime64[ns]) returns either:
- another DatetimeIndex for multiple indices
- a pandas Timestamp for single index
The confusing part is that Timestamps do not equal np.datetime64, so that:
import numpy as np
import pandas as pd
a_datetimeindex = pd.date_range('1/1/2016', '1/2/2016', freq = 'D')
print np.in1d(a_datetimeindex[0], a_datetimeindex)
Returns false. But:
print np.in1d(a_datetimeindex[0:1], a_datetimeindex)
print np.in1d(np.datetime64(a_datetimeindex[0]), a_datetimeindex)
Returns the right results.
I guess that is because np.datetime64[ns] has accuracy to the nanosecond, but the Timestamp is truncated?
My question is, is there a way to create the DatetimeIndex so that it always indexes to the same (or comparable) data type?