29
29
"&" : op .__and__ ,
30
30
"^" : op .__xor__ ,
31
31
"|" : op .__or__ ,
32
+ "<" : op .__lt__ ,
33
+ "<=" : op .__le__ ,
34
+ ">=" : op .__ge__ ,
35
+ ">" : op .__gt__ ,
36
+ # TODO(jorenham): these currently all return `Any`; fix this
37
+ # "==": op.__eq__,
32
38
}
33
39
NAMES = {
34
40
# builtins (key length > 1)
70
76
BITWISE_CHARS = "?bhilqBHILQ"
71
77
72
78
73
- def _scalar (key : str , / ) -> np .generic | complex :
79
+ def _scalar (key : str , / ) -> np .number | np . bool | np . timedelta64 | np . datetime64 | bool :
74
80
if len (key ) > 1 :
75
81
# must be one of the builtin scalars
76
- pytype : type [complex ] = getattr (__builtins__ , key )
82
+ pytype : type [bool ] = getattr (__builtins__ , key )
77
83
return pytype (1 )
78
84
79
85
dtype = np .dtype (key )
@@ -105,7 +111,7 @@ def _assert_stmt(op: str, lhs: str, rhs: str, /) -> str | None:
105
111
expr_eval = f"{ NAMES [lhs ]} { pad } { op } { pad } { NAMES [rhs ]} "
106
112
107
113
try :
108
- val_out : np . generic = OPS [op ](_scalar (lhs ), _scalar (rhs ))
114
+ val_out = OPS [op ](_scalar (lhs ), _scalar (rhs ))
109
115
except TypeError :
110
116
# generate rejection test, while avoiding trivial cases
111
117
if op not in DATETIME_OPS and (lhs == "M" or rhs == "M" ):
@@ -125,9 +131,9 @@ def _assert_stmt(op: str, lhs: str, rhs: str, /) -> str | None:
125
131
"# type: ignore[operator]" ,
126
132
"# pyright: ignore[reportOperatorIssue]" ,
127
133
))
128
- else :
129
- expr_type = _sctype_expr (val_out .dtype )
130
- return f"assert_type({ expr_eval } , { expr_type } )"
134
+
135
+ expr_type = _sctype_expr (val_out .dtype )
136
+ return f"assert_type({ expr_eval } , { expr_type } )"
131
137
132
138
133
139
def _gen_imports () -> Generator [str ]:
0 commit comments