<s> from . base import FieldType , DerivedType <EOL> from dedupe import predicates <EOL> from categorical import CategoricalComparator <EOL> class CategoricalType ( FieldType ) : <EOL> type = "<STR_LIT>" <EOL> _predicate_functions = [ predicates . wholeFieldPredicate ] <EOL> def _categories ( self , definition ) : <EOL> try : <EOL> categories = definition [ "<STR_LIT>" ] <EOL> except KeyError : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> return categories <EOL> def __init__ ( self , definition ) : <EOL> super ( CategoricalType , self ) . __init__ ( definition ) <EOL> categories = self . _categories ( definition ) <EOL> self . comparator = CategoricalComparator ( categories ) <EOL> self . higher_vars = [ ] <EOL> for higher_var in self . comparator . dummy_names : <EOL> dummy_var = DerivedType ( { '<STR_LIT:name>' : higher_var , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . has_missing } ) <EOL> self . higher_vars . append ( dummy_var ) <EOL> def __len__ ( self ) : <EOL> return len ( self . higher_vars ) </s>
