11class OpenMLDataFeature (object ):
2- """Data Feature (a.k.a. Attribute) object.
2+ """
3+ Data Feature (a.k.a. Attribute) object.
34
4- Parameters
5- ----------
6- index : int
7- The index of this feature
8- name : str
9- Name of the feature
10- data_type : str
11- can be nominal, numeric, string, date (corresponds to arff)
12- nominal_values : list(str)
13- list of the possible values, in case of nominal attribute
14- number_missing_values : int
15- """
5+ Parameters
6+ ----------
7+ index : int
8+ The index of this feature
9+ name : str
10+ Name of the feature
11+ data_type : str
12+ can be nominal, numeric, string, date (corresponds to arff)
13+ nominal_values : list(str)
14+ list of the possible values, in case of nominal attribute
15+ number_missing_values : int
16+ """
1617 LEGAL_DATA_TYPES = ['nominal' , 'numeric' , 'string' , 'date' ]
1718
1819 def __init__ (self , index , name , data_type , nominal_values ,
@@ -22,8 +23,16 @@ def __init__(self, index, name, data_type, nominal_values,
2223 if data_type not in self .LEGAL_DATA_TYPES :
2324 raise ValueError ('data type should be in %s, found: %s' %
2425 (str (self .LEGAL_DATA_TYPES ), data_type ))
25- if nominal_values is not None and type (nominal_values ) != list :
26- raise ValueError ('Nominal_values is of wrong datatype' )
26+ if data_type == 'nominal' :
27+ if nominal_values is None :
28+ raise TypeError ('Dataset features require attribute `nominal_values` for nominal '
29+ 'feature type.' )
30+ elif not isinstance (nominal_values , list ):
31+ raise TypeError ('Argument `nominal_values` is of wrong datatype, should be list, '
32+ 'but is {}' .format (type (nominal_values )))
33+ else :
34+ if nominal_values is not None :
35+ raise TypeError ('Argument `nominal_values` must be None for non-nominal feature.' )
2736 if type (number_missing_values ) != int :
2837 raise ValueError ('number_missing_values is of wrong datatype' )
2938
0 commit comments