Preserve MicroSeries weights in NumPy operations and reverse divmod - #323
Merged
Merged
Conversation
juaristi22
marked this pull request as ready for review
September 17, 2026 08:52
juaristi22
force-pushed
the
fix/ufunc-divmod-weights
branch
from
September 17, 2026 10:48
b9694bc to
1ea0557
Compare
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.
Binary NumPy operations with a pandas Series now preserve aligned, independent
MicroSeriesweights, and both results ofdivmod(Series, MicroSeries)retain their weights. For the examples in #322, weighted sums are 204 for maximum, 22 for the quotient and 15 for the remainder.The handler preserves pandas values, names, index order, attributes and errors, and rejects rows whose weights cannot be identified. Calls with higher-priority Series subclasses that inherit pandas' handler complete in both operand orders, including explicit output buffers. Reordered inputs preserve pandas' output order so positional masks write to the same rows. Distinct custom ufunc handlers continue to receive delegated calls.
Operations that would introduce unknown or ambiguous row weights now reject the result before writing explicit output buffers. This preserves the caller's values and any separate output buffer when validation fails, including when the output aliases the weighted input. Valid reordered and masked outputs retain pandas' behavior.
Validation after rebasing onto main with merged #320 and #321: 835 full-suite tests and 621 affected tests pass on each of pandas 2.3.1 and 3.0.5. Eighteen additional regression cases cover rejection before writes, valid aliased outputs and custom-handler delegation. Independent verification passes 38 rejection/output checks and 58 dispatch checks per environment.
The final commit also passes 58 callback/output acceptance cases, 35 prior repair cases and 180 exact-arithmetic interaction cases per environment. These include replicate callbacks that catch a rejected NumPy call and continue calculating, preserving the expected variance of 121 and standard error of 11.
Closes #322.