|
123 | 123 | SparseDtype,
|
124 | 124 | )
|
125 | 125 | from pandas.core.dtypes.generic import (
|
| 126 | + ABCCategoricalIndex, |
126 | 127 | ABCDataFrame,
|
127 | 128 | ABCDatetimeIndex,
|
128 | 129 | ABCIntervalIndex,
|
@@ -4614,19 +4615,24 @@ def join(
|
4614 | 4615 | this = self.astype(dtype, copy=False)
|
4615 | 4616 | other = other.astype(dtype, copy=False)
|
4616 | 4617 | return this.join(other, how=how, return_indexers=True)
|
| 4618 | + elif ( |
| 4619 | + isinstance(self, ABCCategoricalIndex) |
| 4620 | + and isinstance(other, ABCCategoricalIndex) |
| 4621 | + and not self.ordered |
| 4622 | + and not self.categories.equals(other.categories) |
| 4623 | + ): |
| 4624 | + # dtypes are "equal" but categories are in different order |
| 4625 | + other = Index(other._values.reorder_categories(self.categories)) |
4617 | 4626 |
|
4618 | 4627 | _validate_join_method(how)
|
4619 | 4628 |
|
4620 | 4629 | if (
|
4621 |
| - not isinstance(self.dtype, CategoricalDtype) |
4622 |
| - and self.is_monotonic_increasing |
| 4630 | + self.is_monotonic_increasing |
4623 | 4631 | and other.is_monotonic_increasing
|
4624 | 4632 | and self._can_use_libjoin
|
4625 | 4633 | and other._can_use_libjoin
|
4626 | 4634 | and (self.is_unique or other.is_unique)
|
4627 | 4635 | ):
|
4628 |
| - # Categorical is monotonic if data are ordered as categories, but join can |
4629 |
| - # not handle this in case of not lexicographically monotonic GH#38502 |
4630 | 4636 | try:
|
4631 | 4637 | return self._join_monotonic(other, how=how)
|
4632 | 4638 | except TypeError:
|
|
0 commit comments