def union(self, other, sort=None):
self._validate_sort_keyword(sort)<EOL>self._assert_can_do_setop(other)<EOL>if len(other) == <NUM_LIT:0> or self.equals(other) or len(self) == <NUM_LIT:0>:<EOL><INDENT>return super().union(other, sort=sort)<EOL><DEDENT>if not isinstance(other, DatetimeIndex):<EOL><INDENT>try:<EOL><INDENT>other = DatetimeIndex(other)<EOL><DEDENT>except TypeError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>this, other = self._maybe_utc_convert(other)<EOL>if this._can_fast_union(other):<EOL><INDENT>return this._fast_union(other, sort=sort)<EOL><DEDENT>else:<EOL><INDENT>result = Index.union(this, other, sort=sort)<EOL>if isinstance(result, DatetimeIndex):<EOL><INDENT>result._data._dtype = this.dtype<EOL>if (result.freq is None and<EOL>(this.freq is not None or other.freq is not None)):<EOL><INDENT>result.freq = to_offset(result.inferred_freq)<EOL><DEDENT><DEDENT>return result<EOL><DEDENT>
Specialized union for DatetimeIndex objects. If combine
overlapping ranges with the same DateOffset, will be much
faster than Index.union

Parameters
----------
other : DatetimeIndex or array-like
sort : bool or None, default None
    Whether to sort the resulting Index.

    * None : Sort the result, except when

      1. `self` and `other` are equal.
      2. `self` or `other` has length 0.
      3. Some values in `self` or `other` cannot be compared.
         A RuntimeWarning is issued in this case.

    * False : do not sort the result

    .. versionadded:: 0.25.0

Returns
-------
y : Index or DatetimeIndex