def union(self, other, sort=None):
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 isinstance(other, RangeIndex) and sort is None:<EOL><INDENT>start_s, step_s = self._start, self._step<EOL>end_s = self._start + self._step * (len(self) - <NUM_LIT:1>)<EOL>start_o, step_o = other._start, other._step<EOL>end_o = other._start + other._step * (len(other) - <NUM_LIT:1>)<EOL>if self._step < <NUM_LIT:0>:<EOL><INDENT>start_s, step_s, end_s = end_s, -step_s, start_s<EOL><DEDENT>if other._step < <NUM_LIT:0>:<EOL><INDENT>start_o, step_o, end_o = end_o, -step_o, start_o<EOL><DEDENT>if len(self) == <NUM_LIT:1> and len(other) == <NUM_LIT:1>:<EOL><INDENT>step_s = step_o = abs(self._start - other._start)<EOL><DEDENT>elif len(self) == <NUM_LIT:1>:<EOL><INDENT>step_s = step_o<EOL><DEDENT>elif len(other) == <NUM_LIT:1>:<EOL><INDENT>step_o = step_s<EOL><DEDENT>start_r = min(start_s, start_o)<EOL>end_r = max(end_s, end_o)<EOL>if step_o == step_s:<EOL><INDENT>if ((start_s - start_o) % step_s == <NUM_LIT:0> and<EOL>(start_s - end_o) <= step_s and<EOL>(start_o - end_s) <= step_s):<EOL><INDENT>return RangeIndex(start_r, end_r + step_s, step_s)<EOL><DEDENT>if ((step_s % <NUM_LIT:2> == <NUM_LIT:0>) and<EOL>(abs(start_s - start_o) <= step_s / <NUM_LIT:2>) and<EOL>(abs(end_s - end_o) <= step_s / <NUM_LIT:2>)):<EOL><INDENT>return RangeIndex(start_r, end_r + step_s / <NUM_LIT:2>, step_s / <NUM_LIT:2>)<EOL><DEDENT><DEDENT>elif step_o % step_s == <NUM_LIT:0>:<EOL><INDENT>if ((start_o - start_s) % step_s == <NUM_LIT:0> and<EOL>(start_o + step_s >= start_s) and<EOL>(end_o - step_s <= end_s)):<EOL><INDENT>return RangeIndex(start_r, end_r + step_s, step_s)<EOL><DEDENT><DEDENT>elif step_s % step_o == <NUM_LIT:0>:<EOL><INDENT>if ((start_s - start_o) % step_o == <NUM_LIT:0> and<EOL>(start_s + step_o >= start_o) and<EOL>(end_s - step_o <= end_o)):<EOL><INDENT>return RangeIndex(start_r, end_r + step_o, step_o)<EOL><DEDENT><DEDENT><DEDENT>return self._int64index.union(other, sort=sort)<EOL>
Form the union of two Index objects and sorts if possible

Parameters
----------
other : Index or array-like

sort : False or None, default None
    Whether to sort resulting index. ``sort=None`` returns a
    mononotically increasing ``RangeIndex`` if possible or a sorted
    ``Int64Index`` if not. ``sort=False`` always returns an
    unsorted ``Int64Index``

    .. versionadded:: 0.25.0

Returns
-------
union : Index