Skip to content

Commit 2623152

Browse files
committed
Raise correct TypeError and improve type check
1 parent 9c50420 commit 2623152

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

openml/datasets/data_feature.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class OpenMLDataFeature(object):
1818
nominal_values : list(str)
1919
list of the possible values, in case of nominal attribute
2020
number_missing_values : int
21+
Number of rows that have a missing value for this feature.
2122
"""
2223

2324
LEGAL_DATA_TYPES = ["nominal", "numeric", "string", "date"]
@@ -30,8 +31,8 @@ def __init__(
3031
nominal_values: List[str],
3132
number_missing_values: int,
3233
):
33-
if type(index) != int:
34-
raise ValueError("Index is of wrong datatype")
34+
if not isinstance(index, int):
35+
raise TypeError(f"Index must be `int` but is {type(index)}")
3536
if data_type not in self.LEGAL_DATA_TYPES:
3637
raise ValueError(
3738
"data type should be in %s, found: %s" % (str(self.LEGAL_DATA_TYPES), data_type)
@@ -50,8 +51,9 @@ def __init__(
5051
else:
5152
if nominal_values is not None:
5253
raise TypeError("Argument `nominal_values` must be None for non-nominal feature.")
53-
if type(number_missing_values) != int:
54-
raise ValueError("number_missing_values is of wrong datatype")
54+
if not isinstance(number_missing_values, int):
55+
msg = f"number_missing_values must be int but is {type(number_missing_values)}"
56+
raise TypeError(msg)
5557

5658
self.index = index
5759
self.name = str(name)

0 commit comments

Comments
 (0)