Return the union or intersection of indexes. Parameters ---------- indexes : list of Index or list objects When intersect=True, do not accept list of lists. intersect : bool, default False If True, calculate the intersection between indexes. Otherwise, c
(
indexes: list[Index],
intersect: bool = False,
sort: bool | lib.NoDefault = False,
)
| 107 | |
| 108 | |
| 109 | def _get_combined_index( |
| 110 | indexes: list[Index], |
| 111 | intersect: bool = False, |
| 112 | sort: bool | lib.NoDefault = False, |
| 113 | ) -> Index: |
| 114 | """ |
| 115 | Return the union or intersection of indexes. |
| 116 | |
| 117 | Parameters |
| 118 | ---------- |
| 119 | indexes : list of Index or list objects |
| 120 | When intersect=True, do not accept list of lists. |
| 121 | intersect : bool, default False |
| 122 | If True, calculate the intersection between indexes. Otherwise, |
| 123 | calculate the union. |
| 124 | sort : bool, default False |
| 125 | Whether the result index should come out sorted or not. NoDefault |
| 126 | used for deprecation of GH#57335 |
| 127 | |
| 128 | Returns |
| 129 | ------- |
| 130 | Index |
| 131 | """ |
| 132 | # TODO: handle index names! |
| 133 | indexes = _get_distinct_objs(indexes) |
| 134 | if len(indexes) == 0: |
| 135 | index: Index = default_index(0) |
| 136 | elif len(indexes) == 1: |
| 137 | index = indexes[0] |
| 138 | elif intersect: |
| 139 | index = indexes[0] |
| 140 | for other in indexes[1:]: |
| 141 | index = index.intersection(other) |
| 142 | else: |
| 143 | index = union_indexes(indexes, sort=sort if sort is lib.no_default else False) |
| 144 | index = ensure_index(index) |
| 145 | |
| 146 | if sort and sort is not lib.no_default: |
| 147 | index = safe_sort_index(index) |
| 148 | return index |
| 149 | |
| 150 | |
| 151 | def safe_sort_index(index: Index) -> Index: |