Skip to content

PERF improve performance of is_lexsorted #47459

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

Merged
merged 3 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ Performance improvements
- Performance improvement in :func:`factorize` (:issue:`46109`)
- Performance improvement in :class:`DataFrame` and :class:`Series` constructors for extension dtype scalars (:issue:`45854`)
- Performance improvement in :func:`read_excel` when ``nrows`` argument provided (:issue:`32727`)
- Performance improvement in :meth:`MultiIndex.is_monotonic_increasing` (:issue:`47458`)

.. ---------------------------------------------------------------------------
.. _whatsnew_150.bug_fixes:
Expand Down
2 changes: 2 additions & 0 deletions pandas/_libs/algos.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ def is_lexsorted(list_of_arrays: list) -> bint:
else:
result = False
break
if not result:
break
Comment on lines 181 to +184
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me. But probably even better instead of the double break, to simply return when we know it's False. And we don't even need the result variable, since the return at the end of the function should always be return True.

Suggested change
result = False
break
if not result:
break
free(vecs)
return False

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this isn't allowed

Error compiling Cython file:
------------------------------------------------------------
...
                else:
                    result = False
                    break
            if not result:
                free(vecs)
                return False
               ^
------------------------------------------------------------
pandas/_libs/algos.pyx:184:16: Returning Python object not allowed without gil

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know, I was wondering if there was a Cython limitation. Thanks for trying it.

free(vecs)
return result

Expand Down