Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/source/v0.15.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -770,3 +770,8 @@ Bug Fixes
needed interpolating (:issue:`7173`).
- Bug where ``col_space`` was ignored in ``DataFrame.to_string()`` when ``header=False``
(:issue:`8230`).
- Bug with ``DatetimeIndex.asof`` incorrectly matching partial strings and
returning the wrong date (:issue:`8245`).



5 changes: 3 additions & 2 deletions pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,15 +1052,16 @@ def asof(self, label):
if isinstance(label, (Index, ABCSeries, np.ndarray)):
raise TypeError('%s' % type(label))

if not isinstance(label, Timestamp):
label = Timestamp(label)

if label not in self:
loc = self.searchsorted(label, side='left')
if loc > 0:
return self[loc - 1]
else:
return np.nan

if not isinstance(label, Timestamp):
label = Timestamp(label)
return label

def asof_locs(self, where, mask):
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,12 @@ def test_asof(self):
d = self.dateIndex[0].to_datetime()
tm.assert_isinstance(self.dateIndex.asof(d), Timestamp)

def test_asof_datetime_partial(self):
idx = pd.date_range('2010-01-01', periods=2, freq='m')
expected = Timestamp('2010-01-31')
result = idx.asof('2010-02')
self.assertEqual(result, expected)

def test_nanosecond_index_access(self):
s = Series([Timestamp('20130101')]).values.view('i8')[0]
r = DatetimeIndex([s + 50 + i for i in range(100)])
Expand Down