Title: BUG: Fix Incorrect Logical Operation Between Pandas DataFrame and Series (#60204) #60278
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.
This PR fixes issue #60204, where logical operations (
&,|,^) between aDataFrameand aSerieswere not correctly broadcasting, leading to unexpected results. The issue was observed when attempting operations like(df >= 10) | (df['A'] >= 10), wheredfis aDataFrameanddf['A']is aSeries.Changes Made
logical_opfunction: Added logic to handle cases whereleftis aDataFrameandrightis aSeries. The function now convertsrightto a NumPy array to allow proper broadcasting.TypeErrorifrightis a list-like object (e.g., list, tuple) without a defined dtype, as these are unsupported in logical operations with DataFrames.fill_bool: Modifiedfill_boolto ensure proper casting to boolean, accommodating non-boolean types and handling missing values correctly.Code Adjustments
DataFrameandSeriestypes, appliedlib.item_from_zerodimfor handling zero-dimensionalrightobjects.righttoright.valueswhen it's a Series, enabling proper broadcasting across DataFrame columns in logical operations.Testing and Validation
pandas/tests/arithmetic/test_ops.pyto verify:DataFrameandSeriesto ensure correct broadcasting behavior.TypeErroris raised for unsupported list-like objects without dtype.Additional Notes
Checklist
Related Issue
Closes #60204
Thank you for reviewing this PR! Please let me know if further adjustments are needed.