-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
PERF: improve find_common_type perf for special case of all-equal dtypes #44594
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
PERF: improve find_common_type perf for special case of all-equal dtypes #44594
Conversation
pandas/_libs/lib.pyx
Outdated
@@ -3038,3 +3038,23 @@ def is_bool_list(obj: list) -> bool: | |||
|
|||
# Note: we return True for empty list | |||
return True | |||
|
|||
|
|||
def dtypes_all_equal(list types): |
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.
can use python-style annotation with bool return
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.
It seems you can't combine that with a not None
, so left as is, but I added it to the pyi file alongside all others functions in lib.pyx
nice speedup! |
pandas/_libs/lib.pyx
Outdated
@@ -3038,3 +3038,25 @@ def is_bool_list(obj: list) -> bool: | |||
|
|||
# Note: we return True for empty list | |||
return True | |||
|
|||
|
|||
def dtypes_all_equal(list types not None): |
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.
is this a type?
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.
add a return type
In several benchmarks, the
find_common_type
spends quite some time on checking if all dtypes are equal, which can be improved a bit by 1) assuming all dtypes are actual dtypes (is_dtype_equal
is generic and will first convert the input to a dtype, giving overhead) and 2) writing the for loop generator in small cython helper:(based on some testing, both aspects above contribute significantly to the improvement)