def _dt_array_cmp(cls, op):
opname = '<STR_LIT>'.format(name=op.__name__)<EOL>nat_result = opname == '<STR_LIT>'<EOL>def wrapper(self, other):<EOL><INDENT>if isinstance(other, (ABCDataFrame, ABCSeries, ABCIndexClass)):<EOL><INDENT>return NotImplemented<EOL><DEDENT>other = lib.item_from_zerodim(other)<EOL>if isinstance(other, (datetime, np.datetime64, str)):<EOL><INDENT>if isinstance(other, (datetime, np.datetime64)):<EOL><INDENT>self._assert_tzawareness_compat(other)<EOL><DEDENT>try:<EOL><INDENT>other = _to_M8(other, tz=self.tz)<EOL><DEDENT>except ValueError:<EOL><INDENT>return ops.invalid_comparison(self, other, op)<EOL><DEDENT>result = op(self.asi8, other.view('<STR_LIT>'))<EOL>if isna(other):<EOL><INDENT>result.fill(nat_result)<EOL><DEDENT><DEDENT>elif lib.is_scalar(other) or np.ndim(other) == <NUM_LIT:0>:<EOL><INDENT>return ops.invalid_comparison(self, other, op)<EOL><DEDENT>elif len(other) != len(self):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>if isinstance(other, list):<EOL><INDENT>try:<EOL><INDENT>other = type(self)._from_sequence(other)<EOL><DEDENT>except ValueError:<EOL><INDENT>other = np.array(other, dtype=np.object_)<EOL><DEDENT><DEDENT>elif not isinstance(other, (np.ndarray, ABCIndexClass, ABCSeries,<EOL>DatetimeArray)):<EOL><INDENT>return ops.invalid_comparison(self, other, op)<EOL><DEDENT>if is_object_dtype(other):<EOL><INDENT>with np.errstate(all='<STR_LIT:ignore>'):<EOL><INDENT>result = ops._comp_method_OBJECT_ARRAY(op,<EOL>self.astype(object),<EOL>other)<EOL><DEDENT>o_mask = isna(other)<EOL><DEDENT>elif not (is_datetime64_dtype(other) or<EOL>is_datetime64tz_dtype(other)):<EOL><INDENT>return ops.invalid_comparison(self, other, op)<EOL><DEDENT>else:<EOL><INDENT>self._assert_tzawareness_compat(other)<EOL>if isinstance(other, (ABCIndexClass, ABCSeries)):<EOL><INDENT>other = other.array<EOL><DEDENT>if (is_datetime64_dtype(other) and<EOL>not is_datetime64_ns_dtype(other) or<EOL>not hasattr(other, '<STR_LIT>')):<EOL><INDENT>other = type(self)._from_sequence(other)<EOL><DEDENT>result = op(self.view('<STR_LIT>'), other.view('<STR_LIT>'))<EOL>o_mask = other._isnan<EOL><DEDENT>result = com.values_from_object(result)<EOL>if o_mask.any():<EOL><INDENT>result[o_mask] = nat_result<EOL><DEDENT><DEDENT>if self._hasnans:<EOL><INDENT>result[self._isnan] = nat_result<EOL><DEDENT>return result<EOL><DEDENT>return compat.set_function_name(wrapper, opname, cls)<EOL>
Wrap comparison operations to convert datetime-like to datetime64