def coerce_indexer_dtype(indexer, categories):
length = len(categories)<EOL>if length < _int8_max:<EOL><INDENT>return ensure_int8(indexer)<EOL><DEDENT>elif length < _int16_max:<EOL><INDENT>return ensure_int16(indexer)<EOL><DEDENT>elif length < _int32_max:<EOL><INDENT>return ensure_int32(indexer)<EOL><DEDENT>return ensure_int64(indexer)<EOL>
coerce the indexer input array to the smallest dtype possible