When slicing data time - indexed dataframe with date in string format, it works:
df.ix['2014-11-12'].head()
Out[55]:
calories gsr heart-rate skin-temp steps
date
2014-11-12 00:00:00 2.1 7.04640 NaN 85.7750 30
2014-11-12 00:01:00 1.5 7.40759 NaN 85.7375 0
2014-11-12 00:02:00 1.4 7.46220 49 85.5500 0
2014-11-12 00:03:00 1.4 7.55800 NaN 85.5500 0
2014-11-12 00:04:00 1.5 7.52163 NaN 85.5125 0
But when i try it with a date object, of datetime class , it slices only for time 00:00:00.
d1=datetime.date(2014,11,12)
df.ix[d1]
Out[57]:
calories 2.1000
gsr 7.0464
heart-rate NaN
skin-temp 85.7750
steps 30.0000
Name: 2014-11-12 00:00:00, dtype: float64
Comment From: jreback
conceptually similar to #10408. datetime.date
objects are not well supported (and likely will not be). simply use datetime.datetime
and better yet Timestamp/Period
objects and all will be happy.
I suppose one could call this a bug, and if you'd like to dig-in would take a fix.
Comment From: jorisvandenbossche
@jreback I don't know if we should call this a bug. Indexing with a datetime.date
does work, but it is the question how it should be interpreted (if it should do partial string indexing or not):
As a timestamp (what you would get from pd.Timestamp(d1)
), so then the above behaviour is correct. Or as a 'date' and so similar to providing a string with that date and do a partial string indexing-like thing.
I see the potential confusion in a different result of df.ix['2014-11-12']
and df.ix[date(2014,11,12)]
. But personally I would keep the 'partial string indexing' feature restricted to strings.
Comment From: jreback
@jorisvandenbossche hmm, good point. Yeh string indexing encompases internals, but Timestamp/datetime.datetime
is an instant in time, its the slicing that actually introduces the interval
so
df.ix[date(2014,11,12):date(2014,11,13)]
would be a day.
Introducing objects that expand into a slice then would be a fairly big API change.
Comment From: jorisvandenbossche
Yes, indeed. Therefore I would close this as not-a-bug.
It can be a bit questionable if a date
should be regarded as a instant in time like datetime
, but I wouldn't start doing slices with single date
objects like with strings.
Comment From: mroeschke
Agreed that partial string indexing should be reserved for datetime strings only. Closing as this would provide too much API creep.