# xarray.CFTimeIndex.union

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

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 all unique elements from both the original
  Index and the other 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('369e0dc1-c675-4c1b-8fee-fd1be3f05908','4946ada9-a61d-4994-83ca-5ef4b5de0791','829be7fd-6fdb-4de6-99c3-e2a29d41509d','../lite/tree/../notebooks/index.html?path=acc31b37_4a1c_4fcc_96ab_b48755cb383d.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')
```

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="829be7fd-6fdb-4de6-99c3-e2a29d41509d" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('369e0dc1-c675-4c1b-8fee-fd1be3f05908','829be7fd-6fdb-4de6-99c3-e2a29d41509d')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('369e0dc1-c675-4c1b-8fee-fd1be3f05908','829be7fd-6fdb-4de6-99c3-e2a29d41509d')">Open In Tab</button></div><div id="4946ada9-a61d-4994-83ca-5ef4b5de0791" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
