# xarray.CFTimeIndex.union

#### CFTimeIndex.union(other, sort=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/../.pixi/envs/doc/lib/python3.15/site-packages/pandas/core/indexes/base.py#L3173-L3313)

Form the union of two Index objects.

If the Index objects are incompatible, both Index objects will be
cast to dtype(‘object’) first.

* **Parameters:**
  * **other** ([`Index`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Index.html#pandas.Index) or [array-like](https://numpy.org/doc/stable/glossary.html#term-array_like)) – Index or an array-like object containing elements to form the union
    with the original Index.
  * **sort** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool) or [`None`](https://docs.python.org/3/builtins/constants.html#None), *default* [`None`](https://docs.python.org/3/builtins/constants.html#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.
    * True : Sort the result (which may raise TypeError).
* **Returns:**
  [`Index`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Index.html#pandas.Index) – Returns a new Index object with elements from both the original
  Index and the `other` Index.

  If either index contains duplicate entries, the result preserves
  duplicates up to the maximum number of occurrences in either index.

#### SEE ALSO
`Index.unique`
: Return unique values in the index.

`Index.intersection`
: Form the intersection of two Index objects.

`Index.difference`
: Return a new Index with elements of index not in other.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('096bdece-a62b-4a84-a443-57d532cb84b6','d1f48180-9b93-4956-8280-187bb2720b09','c8bd0420-fb64-4685-bb62-38242631f029','../lite/tree/../notebooks/index.html?path=0cabace5_feb9_4e34_8e21_67c4a9253fe2.ipynb','None')">Try it in your browser!</button></div>

Union matching dtypes

```pycon
>>> idx1 = pd.Index([1, 2, 3, 4])
>>> idx2 = pd.Index([3, 4, 5, 6])
>>> idx1.union(idx2)
Index([1, 2, 3, 4, 5, 6], dtype='int64')
```

Union mismatched dtypes

```pycon
>>> idx1 = pd.Index(["a", "b", "c", "d"])
>>> idx2 = pd.Index([1, 2, 3, 4])
>>> idx1.union(idx2)
Index(['a', 'b', 'c', 'd', 1, 2, 3, 4], dtype='object')
```

Union with duplicate values

```pycon
>>> idx1 = pd.Index([1, 2, 2, 3])
>>> idx2 = pd.Index([3, 3, 4])
>>> idx1.union(idx2)
Index([1, 2, 2, 3, 3, 4], dtype='int64')
```

MultiIndex case

```pycon
>>> idx1 = pd.MultiIndex.from_arrays(
...     [[1, 1, 2, 2], ["Red", "Blue", "Red", "Blue"]]
... )
>>> idx1
MultiIndex([(1,  'Red'),
    (1, 'Blue'),
    (2,  'Red'),
    (2, 'Blue')],
   )
>>> idx2 = pd.MultiIndex.from_arrays(
...     [[3, 3, 2, 2], ["Red", "Green", "Red", "Green"]]
... )
>>> idx2
MultiIndex([(3,   'Red'),
    (3, 'Green'),
    (2,   'Red'),
    (2, 'Green')],
   )
>>> idx1.union(idx2)
MultiIndex([(1,  'Blue'),
    (1,   'Red'),
    (2,  'Blue'),
    (2, 'Green'),
    (2,   'Red'),
    (3, 'Green'),
    (3,   'Red')],
   )
>>> idx1.union(idx2, sort=False)
MultiIndex([(1,   'Red'),
    (1,  'Blue'),
    (2,   'Red'),
    (2,  'Blue'),
    (3,   'Red'),
    (3, 'Green'),
    (2, 'Green')],
   )
```

<div id="c8bd0420-fb64-4685-bb62-38242631f029" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('096bdece-a62b-4a84-a443-57d532cb84b6','c8bd0420-fb64-4685-bb62-38242631f029')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('096bdece-a62b-4a84-a443-57d532cb84b6','c8bd0420-fb64-4685-bb62-38242631f029')">Open In Tab</button></div><div id="d1f48180-9b93-4956-8280-187bb2720b09" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
