Asthenia0412 opened a new pull request, #53775: URL: https://github.com/apache/arrow/pull/53775
## Background Issue #39149 reports that `pc.replace_substring_regex()` hangs indefinitely when passed a negative `max_replacements` value (other than -1 which means unlimited). The root cause is that the C++ kernel decrements `max_replacements` until it reaches 0, but a value like -3 becomes -4, -5, ... forever. ## Problem The Python layer's `ReplaceSubstringOptions.__init__` does not validate that `max_replacements >= -1`, allowing negative values to reach the C++ kernel and cause hangs. ## Solution Add input validation on the Python side to reject `max_replacements < -1` with a clear `ValueError`. This is a defensive fix that fails fast before the C++ kernel is invoked. ## Testing Added `test_replace_substring_negative_max_replacements` covering: - `max_replacements=-2`, `-3` -> raises ValueError (original bug scenario) - `max_replacements=-1`, `None` -> accepted, treated as unlimited - `max_replacements=0`, `5` -> accepted non-negative values -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
