diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index cde2a4279cf27..c95e7d20c1ab4 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -223,7 +223,7 @@ Categorical - Bug where :func:`merge` was unable to join on categorical and extension dtype columns (:issue:`28668`) - :meth:`Categorical.searchsorted` and :meth:`CategoricalIndex.searchsorted` now work on unordered categoricals also (:issue:`21667`) - Added test to assert roundtripping to parquet with :func:`DataFrame.to_parquet` or :func:`read_parquet` will preserve Categorical dtypes for string types (:issue:`27955`) -- +- Bug in merge on CategoricalIndex fails if ``left_index=True`` & ``right_index=True``, but not if ``on={index}`` (:issue:`28189`)- Datetimelike diff --git a/pandas/_libs/join.pyx b/pandas/_libs/join.pyx index 238bfd0be0aa7..12d6439ed5b17 100644 --- a/pandas/_libs/join.pyx +++ b/pandas/_libs/join.pyx @@ -242,6 +242,8 @@ ctypedef fused join_t: float64_t float32_t object + int8_t + int16_t int32_t int64_t uint64_t @@ -410,6 +412,11 @@ def left_join_indexer(ndarray[join_t] left, ndarray[join_t] right): left_join_indexer_float64 = left_join_indexer["float64_t"] left_join_indexer_float32 = left_join_indexer["float32_t"] left_join_indexer_object = left_join_indexer["object"] +left_join_indexer_int8 = left_join_indexer["int8_t"] +<<<<<<< HEAD +======= +left_join_indexer_int16 = left_join_indexer["int16_t"] +>>>>>>> 4e8bf1f62a82e6fec532c91297b0b5a908351c3d left_join_indexer_int32 = left_join_indexer["int32_t"] left_join_indexer_int64 = left_join_indexer["int64_t"] left_join_indexer_uint64 = left_join_indexer["uint64_t"] diff --git a/pandas/tests/test_join.py b/pandas/tests/test_join.py index e750193abb71a..3f87317d77f27 100644 --- a/pandas/tests/test_join.py +++ b/pandas/tests/test_join.py @@ -348,3 +348,21 @@ def test_merge_join_categorical_multiindex(): result = a.join(b, on=["Cat1", "Int1"]) expected = expected.drop(["Cat", "Int"], axis=1) assert_frame_equal(expected, result) + + +def test_left_index_and_right_index_true(): + # From issue 28189 + df = DataFrame( + range(4), columns=["value"], index=Index(Categorical(["1"] * 4), name="idx") + ) + df2 = DataFrame( + [[6]], columns=["value"], index=Index(Categorical(["1"]), name="idx") + ) + + result = merge(df, df2, how="left", left_index=True, right_index=True) + result = result.reset_index(drop=True) + expected = DataFrame( + np.array([[0, 6], [1, 6], [2, 6], [3, 6]]), columns=["value_x", "value_y"] + ) + + assert_frame_equal(expected, result)