Skip to content

Commit

Permalink
loc of bad element raises KeyError
Browse files Browse the repository at this point in the history
  • Loading branch information
mrocklin committed Jul 20, 2015
1 parent 319e1e8 commit 7ba29bd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dask/dataframe/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ def _loc_series(self, ind):
def _loc_element(self, ind):
name = 'loc-element' + next(tokens)
part = _partition_of_index_value(self.divisions, ind)
if ind < self.divisions[0] or ind > self.divisions[-1]:
raise KeyError('the label [%s] is not in the index' % str(ind))
dsk = {(name, 0): (lambda df: df.loc[ind], (self._name, part))}
return type(self)(merge(self.dask, dsk), name,
self.column_info, [ind, ind])
Expand Down
4 changes: 4 additions & 0 deletions dask/dataframe/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ def test_loc():
assert eq(d.loc[:8], full.loc[:8])
assert eq(d.loc[3:], full.loc[3:])

assert raises(KeyError, lambda: d.loc[1000])
assert eq(d.loc[1000:], full.loc[1000:])
assert eq(d.loc[-2000:-1000], full.loc[-2000:-1000])



def test_loc_with_text_dates():
Expand Down

0 comments on commit 7ba29bd

Please sign in to comment.