@classmethod<EOL><INDENT>def _add_comparison_methods(cls):<DEDENT>
def _make_compare(op):<EOL><INDENT>opname = '<STR_LIT>'.format(op=op.__name__)<EOL>def _evaluate_compare(self, other):<EOL><INDENT>if isinstance(other, CategoricalIndex):<EOL><INDENT>other = other._values<EOL><DEDENT>elif isinstance(other, Index):<EOL><INDENT>other = self._create_categorical(<EOL>other._values, dtype=self.dtype)<EOL><DEDENT>if isinstance(other, (ABCCategorical, np.ndarray,<EOL>ABCSeries)):<EOL><INDENT>if len(self.values) != len(other):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>if isinstance(other, ABCCategorical):<EOL><INDENT>if not self.values.is_dtype_equal(other):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT>result = op(self.values, other)<EOL>if isinstance(result, ABCSeries):<EOL><INDENT>result = result.values<EOL><DEDENT>return result<EOL><DEDENT>return compat.set_function_name(_evaluate_compare, opname, cls)<EOL><DEDENT>cls.__eq__ = _make_compare(operator.eq)<EOL>cls.__ne__ = _make_compare(operator.ne)<EOL>cls.__lt__ = _make_compare(operator.lt)<EOL>cls.__gt__ = _make_compare(operator.gt)<EOL>cls.__le__ = _make_compare(operator.le)<EOL>cls.__ge__ = _make_compare(operator.ge)<EOL>
add in comparison methods