(
join_type,
sort,
on_index,
left_unique,
left_monotonic,
right_unique,
right_monotonic,
)
| 3012 | @pytest.mark.parametrize("right_unique", [True, False]) |
| 3013 | @pytest.mark.parametrize("right_monotonic", [True, False]) |
| 3014 | def test_merge_combinations( |
| 3015 | join_type, |
| 3016 | sort, |
| 3017 | on_index, |
| 3018 | left_unique, |
| 3019 | left_monotonic, |
| 3020 | right_unique, |
| 3021 | right_monotonic, |
| 3022 | ): |
| 3023 | how = join_type |
| 3024 | # GH 54611 |
| 3025 | left = [2, 3] |
| 3026 | if left_unique: |
| 3027 | left.append(4 if left_monotonic else 1) |
| 3028 | else: |
| 3029 | left.append(3 if left_monotonic else 2) |
| 3030 | |
| 3031 | right = [2, 3] |
| 3032 | if right_unique: |
| 3033 | right.append(4 if right_monotonic else 1) |
| 3034 | else: |
| 3035 | right.append(3 if right_monotonic else 2) |
| 3036 | |
| 3037 | left = DataFrame({"key": left}) |
| 3038 | right = DataFrame({"key": right}) |
| 3039 | |
| 3040 | if on_index: |
| 3041 | left = left.set_index("key") |
| 3042 | right = right.set_index("key") |
| 3043 | on_kwargs = {"left_index": True, "right_index": True} |
| 3044 | else: |
| 3045 | on_kwargs = {"on": "key"} |
| 3046 | |
| 3047 | result = merge(left, right, how=how, sort=sort, **on_kwargs) |
| 3048 | |
| 3049 | if on_index: |
| 3050 | left = left.reset_index() |
| 3051 | right = right.reset_index() |
| 3052 | |
| 3053 | if how in ["left", "right", "inner"]: |
| 3054 | if how in ["left", "inner"]: |
| 3055 | expected, other, other_unique = left, right, right_unique |
| 3056 | else: |
| 3057 | expected, other, other_unique = right, left, left_unique |
| 3058 | if how == "inner": |
| 3059 | keep_values = set(left["key"].values).intersection(right["key"].values) |
| 3060 | keep_mask = expected["key"].isin(keep_values) |
| 3061 | expected = expected[keep_mask] |
| 3062 | if sort: |
| 3063 | expected = expected.sort_values("key") |
| 3064 | if not other_unique: |
| 3065 | other_value_counts = other["key"].value_counts() |
| 3066 | repeats = other_value_counts.reindex(expected["key"].values, fill_value=1) |
| 3067 | repeats = repeats.astype(np.intp) |
| 3068 | expected = expected["key"].repeat(repeats.values) |
| 3069 | expected = expected.to_frame() |
| 3070 | elif how == "outer": |
| 3071 | left_counts = left["key"].value_counts() |
nothing calls this directly
no test coverage detected