Skip to content

Commit beecc43

Browse files
committed
Update classlabel test
1 parent 6ddd1bd commit beecc43

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/datasets/features/features.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,8 +830,9 @@ def _strvalue2int(self, value: str):
830830
int_value = int(value)
831831
except ValueError:
832832
failed_parse = True
833-
if int_value < -1 or int_value >= self.num_classes:
834-
failed_parse = True
833+
else:
834+
if int_value < -1 or int_value >= self.num_classes:
835+
failed_parse = True
835836
if failed_parse:
836837
raise ValueError(f"Invalid string class label {value}")
837838
return int_value

tests/features/test_features.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def test_classlabel_str2int():
253253
classlabel = ClassLabel(names=names)
254254
for label in names:
255255
assert classlabel.str2int(label) == names.index(label)
256-
with pytest.raises(KeyError):
256+
with pytest.raises(ValueError):
257257
classlabel.str2int("__bad_label_name__")
258258
with pytest.raises(ValueError):
259259
classlabel.str2int(1)

0 commit comments

Comments
 (0)