[3.0.x] BUG: fix segfault adding non-tick DateOffset to datetime data under threads#66031
Merged
jorisvandenbossche merged 1 commit intoJun 26, 2026
Conversation
…hreads The vectorized offset apply path (shift_months/shift_quarters -> _roll_qtrday/get_day_of_month) compared the Python ``str`` day_opt inside ``with nogil`` blocks, i.e. with the GIL released. Concurrent Python activity in another thread (e.g. pytest-xdist's execnet receiver) could race those comparisons and segfault. Convert day_opt to a C enum before releasing the GIL so the in-nogil comparisons are pure C. This backports the memory-safety core of the day_opt-enum refactor in pandas-devGH-64480 without the rest of that PR's changes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1c88351 to
e3542d2
Compare
Member
|
@jbrockmendel thanks! That seems to fix it indeed (still a bit strange that it only shows up on the wheel builds ..) |
jorisvandenbossche
approved these changes
Jun 26, 2026
15494e8
into
pandas-dev:3.0.x
118 of 119 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backports the memory-safety core of GH-64480 to the 3.0.x branch.
The vectorized offset apply path (
shift_months/shift_quarters→_roll_qtrday/get_day_of_month) compared the Pythonstrday_opt(day_opt == "start", etc.) insidewith nogil:blocks — i.e. with the GIL released. When another thread runs Python concurrently (for examplepytest-xdist's execnet receiver thread), that races the comparison on Python internals and can segfault. This is what crashes the cp311/cp312/cp313 3.0.x wheel builds in_add_offsetduring the test phase.The fix converts
day_optto a C enum before thewith nogil:blocks, so the in-nogilcomparisons are pure C and touch no Python objects. It is the minimal subset of GH-64480 (just theday_optenum) without the rest of that PR's perf changes; the publicshift_months/shift_quarters/roll_qtrdaysignatures are unchanged.mainalready has this via GH-64480, so no forward-port is needed. The bug has been latent since 2022, is platform/timing-dependent (manifests on Linux x86_64, not macOS arm64), and is numpy-independent.