@@ -938,7 +938,7 @@ class _MergeOperation:
938
938
"""
939
939
940
940
_merge_type = "merge"
941
- how : JoinHow | Literal ["left_anti" , "right_anti" , " asof" ]
941
+ how : JoinHow | Literal ["asof" ]
942
942
on : IndexLabel | None
943
943
# left_on/right_on may be None when passed, but in validate_specification
944
944
# get replaced with non-None.
@@ -973,8 +973,7 @@ def __init__(
973
973
_right = _validate_operand (right )
974
974
self .left = self .orig_left = _left
975
975
self .right = self .orig_right = _right
976
- self .how = how
977
- self .anti_join = False
976
+ self .how , self .anti_join = self ._validate_how (how )
978
977
979
978
self .on = com .maybe_make_list (on )
980
979
@@ -1004,26 +1003,6 @@ def __init__(
1004
1003
)
1005
1004
raise MergeError (msg )
1006
1005
1007
- # GH 59435: raise when "how" is not a valid Merge type
1008
- merge_type = {
1009
- "left" ,
1010
- "right" ,
1011
- "inner" ,
1012
- "outer" ,
1013
- "left_anti" ,
1014
- "right_anti" ,
1015
- "cross" ,
1016
- "asof" ,
1017
- }
1018
- if how not in merge_type :
1019
- raise ValueError (
1020
- f"'{ how } ' is not a valid Merge type: "
1021
- f"left, right, inner, outer, cross, asof"
1022
- )
1023
- if self .how in {"left_anti" , "right_anti" }:
1024
- self .how = self .how .split ("_" )[0 ] # type: ignore[assignment]
1025
- self .anti_join = True
1026
-
1027
1006
self .left_on , self .right_on = self ._validate_left_right_on (left_on , right_on )
1028
1007
1029
1008
(
@@ -1053,6 +1032,35 @@ def __init__(
1053
1032
if validate is not None :
1054
1033
self ._validate_validate_kwd (validate )
1055
1034
1035
+ def _validate_how (
1036
+ self , how : JoinHow | Literal ["left_anti" , "right_anti" , "asof" ]
1037
+ ) -> tuple [JoinHow , bool ]:
1038
+ """
1039
+ Validate the 'how' parameter and return the actual join type and whether
1040
+ this is an anti join.
1041
+ """
1042
+ # GH 59435: raise when "how" is not a valid Merge type
1043
+ merge_type = {
1044
+ "left" ,
1045
+ "right" ,
1046
+ "inner" ,
1047
+ "outer" ,
1048
+ "left_anti" ,
1049
+ "right_anti" ,
1050
+ "cross" ,
1051
+ "asof" ,
1052
+ }
1053
+ if how not in merge_type :
1054
+ raise ValueError (
1055
+ f"'{ how } ' is not a valid Merge type: "
1056
+ f"left, right, inner, outer, left_anti, right_anti, cross, asof"
1057
+ )
1058
+ anti_join = False
1059
+ if how in {"left_anti" , "right_anti" }:
1060
+ how = how .split ("_" )[0 ] # type: ignore[assignment]
1061
+ anti_join = True
1062
+ return how , anti_join
1063
+
1056
1064
def _maybe_require_matching_dtypes (
1057
1065
self , left_join_keys : list [ArrayLike ], right_join_keys : list [ArrayLike ]
1058
1066
) -> None :
0 commit comments