Skip to content

MNT: Explicitly set cdef functions as noexcept #53144

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 2 commits into from
May 9, 2023

Conversation

matusvalo
Copy link
Contributor

@matusvalo matusvalo commented May 8, 2023

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

This PR marks functions returning void as noexcept to avoid checking an exception after every function call. inline functions are marked too to avoid unnecessary overhead. The improvement is only in Cython 3. In Cython 0.29.X noexcept keyword is ignored. See #53125 (comment) for details.

@matusvalo matusvalo force-pushed the cython3_noexcept branch from 9da685c to d14b6d3 Compare May 8, 2023 22:01
@mroeschke mroeschke added the Internals Related to non-user accessible pandas implementation label May 9, 2023
@mroeschke mroeschke added this to the 2.1 milestone May 9, 2023
@mroeschke mroeschke merged commit 2c164f0 into pandas-dev:main May 9, 2023
@mroeschke
Copy link
Member

Thanks @matusvalo

@matusvalo matusvalo deleted the cython3_noexcept branch May 9, 2023 17:25
@@ -595,7 +595,7 @@ cdef check_overflows(_TSObject obj, NPY_DATETIMEUNIT reso=NPY_FR_ns):
# ----------------------------------------------------------------------
# Localization

cdef void _localize_tso(_TSObject obj, tzinfo tz, NPY_DATETIMEUNIT reso):
cdef void _localize_tso(_TSObject obj, tzinfo tz, NPY_DATETIMEUNIT reso) noexcept:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this really noexcept? I think the Localizer constructor can raise

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In Cython 0.29.X the default exception handling is noexcept hence the exception was not propagated even before this PR. If an exception should be propagated, one should consider changing return type from void to int to avoid checking exception after every function call.

Rylie-W pushed a commit to Rylie-W/pandas that referenced this pull request May 19, 2023
* Explicitly set cdef functions as noexcept

* Make linter happy
Daquisu pushed a commit to Daquisu/pandas that referenced this pull request Jul 8, 2023
* Explicitly set cdef functions as noexcept

* Make linter happy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internals Related to non-user accessible pandas implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants