Skip to content

Commit

Permalink
Clarify why indexing with int is not supported.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-work authored and ottonemo committed Dec 11, 2017
1 parent b9b2f49 commit 3450e43
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions skorch/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class SliceDict(dict):
Use this if your input data is a dictionary and you have problems
with sklearn not being able to slice it. Wrap your dict with
SliceDict and it should usually work.
Note: SliceDict cannot be indexed by integers, if you want one
row, say row 3, use `[3:4]`.
Examples
--------
Expand Down Expand Up @@ -41,6 +44,9 @@ def __len__(self):

def __getitem__(self, sl):
if isinstance(sl, int):
# Indexing with integers is not well-defined because that
# recudes the dimension of arrays by one, messing up
# lengths and shapes.
raise ValueError("SliceDict cannot be indexed by integers.")
if isinstance(sl, str):
return super(SliceDict, self).__getitem__(sl)
Expand Down

0 comments on commit 3450e43

Please sign in to comment.