-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Distinguish between np type hints from Py ones #4953
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -392,6 +392,41 @@ def f31(p1: Optional[np.bool_], p2=None) -> bool: | |
t2 = t.update(["X1 = f31(null, Y)"]) | ||
self.assertEqual(10, t2.to_string("X1").count("true")) | ||
|
||
def test_non_np_typehints(self): | ||
py_types = {"int", "float"} | ||
|
||
for p_type in py_types: | ||
with self.subTest(p_type): | ||
func_str = f""" | ||
def f(x: {p_type}) -> bool: # note typing | ||
return type(x) == {p_type} | ||
""" | ||
exec(func_str, globals()) | ||
t = empty_table(1).update(["X = i", f"Y = f(({p_type})X)"]) | ||
self.assertEqual(1, t.to_string(cols="Y").count("true")) | ||
|
||
|
||
np_int_types = {"np.int8", "np.int16", "np.int32", "np.int64"} | ||
for p_type in np_int_types: | ||
with self.subTest(p_type): | ||
func_str = f""" | ||
def f(x: {p_type}) -> bool: # note typing | ||
return type(x) == {p_type} | ||
""" | ||
exec(func_str, globals()) | ||
t = empty_table(1).update(["X = i", f"Y = f(X)"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it is only testing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see the comment above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the behavior here is correct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't yet statically check if the parameter types and argument types match. That's something for the improvement of the QLP. Runtime exception however will be thrown if the arg value is outside the range of a numpy integer type. |
||
self.assertEqual(1, t.to_string(cols="Y").count("true")) | ||
|
||
np_floating_types = {"np.float32", "np.float64"} | ||
for p_type in np_floating_types: | ||
with self.subTest(p_type): | ||
func_str = f""" | ||
def f(x: {p_type}) -> bool: # note typing | ||
return type(x) == {p_type} | ||
""" | ||
exec(func_str, globals()) | ||
t = empty_table(1).update(["X = i", f"Y = f((float)X)"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it is only testing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests are just to make sure that the converted args' types are what we expected, the exact types of the values are not a concern here and they are tested in other test cases in the same test class. |
||
self.assertEqual(1, t.to_string(cols="Y").count("true")) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this should also be testing with
long
anddouble
since the python types are wide.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see the comment above.