You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
P.S. I can open PR, but then section would look more organically if for examples object methods would be presented, with comment that boolean ops are also supported
Thanks for pointing this out. Adding a brief explanation of why indA & indB
behaves differently from indA.intersection(indB) would definitely make the
example clearer and help avoid confusion for readers.
The example should clarify that indA & indB returns an incorrect result
because it performs a logical AND operation, while indA.intersection(indB)
gives the expected intersection output of [3, 5, 7]; including a note
about
this distinction would improve clarity.
—
Reply to this email directly, view it on GitHub
<
Thanks for pointing this out. Clarifying the difference between the logical
AND operation and indA.intersection(indB) would make the example much
clearer.
The core problem in the "Index as ordered set" section is that indA & indB ends up returning Index([0, 3, 5, 7, 9], dtype='int64') for the listed values instead of performing the intersection.
Showing indA.intersection(indB) as the primary way to get [3, 5, 7] would resolve this directly.
The & operator is currently performing a bitwise AND on the integer values rather than a set intersection because pandas treats these indices as numeric arrays rather than sets. Updating the text to prioritize indA.intersection(indB) is the right move, but we should also explicitly warn readers that & behavior on pd.Index objects depends heavily on the underlying dtype.
Since the & operator behavior on pandas indices depends on the underlying dtype and often defaults to bitwise operations, we should explicitly document that intersection is the only reliable method for set operations to avoid these silent numeric misinterpretations.
Since pd.Index behavior for & defaults to bitwise operations on underlying numeric data, we should add a note explaining that intersection is the only safe method for set-like logic to avoid these silent, incorrect results.
Since the & operator behaves as a bitwise AND on underlying integer data, we should update the text to explicitly demonstrate indA.intersection(indB) for set operations. Would it be helpful to add a note explaining that & only acts as a set intersection when the index contains non-numeric data types like strings?
Updating the text to emphasize indA.intersection(indB) is correct, but we should also explicitly note that & on numeric indices triggers element-wise bitwise operations rather than set logic to prevent users from assuming consistent set behavior across different dtype indices.
To prevent further confusion, we should also add a note explaining that the & operator behaves as a bitwise operation on Index objects, which causes the unexpected output when values are interpreted as integers.
Since bitwise & on Index objects behaves as an element-wise operation rather than set intersection, we should replace the current example with indA.intersection(indB) and add a note that the & operator is reserved for bitwise logic in pandas.
To clarify the behavior for readers, we should note that indA & indB is executing a bitwise operation on the underlying int64 data, which is why the output reflects index-wise matching rather than set intersection. I suggest adding a sidebar or note explaining that while the bitwise operators are supported, they do not behave as set operators on numeric Index objects. We could also include a snippet demonstrating indA.intersection(indB) alongside the current example to explicitly show the expected set output of Index([3, 5, 7]).
Activity
wafir645fcqs49 commentedon Aug 5, 2026
bsoua8745s12 commentedon Aug 10, 2026
bsoua8745s12 commentedon Aug 16, 2026
gustavocastillo5 commentedon Sep 2, 2026
The core problem in the "Index as ordered set" section is that
indA & indBends up returningIndex([0, 3, 5, 7, 9], dtype='int64')for the listed values instead of performing the intersection.Showing
indA.intersection(indB)as the primary way to get [3, 5, 7] would resolve this directly.UfBt12qJNZKcw commentedon Sep 11, 2026
The
&operator is currently performing a bitwise AND on the integer values rather than a set intersection because pandas treats these indices as numeric arrays rather than sets. Updating the text to prioritizeindA.intersection(indB)is the right move, but we should also explicitly warn readers that&behavior onpd.Indexobjects depends heavily on the underlying dtype.jadayaanaliah26 commentedon Sep 14, 2026
This behavior changed in pandas 1.0.0 where the
&operator on integer Index objects was deprecated forheenll68 commentedon Sep 27, 2026
Since the
&operator behavior on pandas indices depends on the underlying dtype and often defaults to bitwise operations, we should explicitly document thatintersectionis the only reliable method for set operations to avoid these silent numeric misinterpretations.edinakama commentedon Oct 4, 2026
Since
pd.Indexbehavior for&defaults to bitwise operations on underlying numeric data, we should add a note explaining thatintersectionis the only safe method for set-like logic to avoid these silent, incorrect results.melina-karleen commentedon Oct 5, 2026
Since the
&operator behaves as a bitwise AND on underlying integer data, we should update the text to explicitly demonstrateindA.intersection(indB)for set operations. Would it be helpful to add a note explaining that&only acts as a set intersection when the index contains non-numeric data types like strings?zeniatison commentedon Oct 7, 2026
Updating the text to emphasize
indA.intersection(indB)is correct, but we should also explicitly note that&on numeric indices triggers element-wise bitwise operations rather than set logic to prevent users from assuming consistent set behavior across different dtype indices.sayradekayla26 commentedon Oct 11, 2026
To prevent further confusion, we should also add a note explaining that the
&operator behaves as a bitwise operation on Index objects, which causes the unexpected output when values are interpreted as integers.dredonjaquana26 commentedon Oct 15, 2026
Since bitwise
&on Index objects behaves as an element-wise operation rather than set intersection, we should replace the current example withindA.intersection(indB)and add a note that the&operator is reserved for bitwise logic in pandas.cherryrodney26 commentedon Oct 19, 2026
To clarify the behavior for readers, we should note that
indA & indBis executing a bitwise operation on the underlyingint64data, which is why the output reflects index-wise matching rather than set intersection. I suggest adding a sidebar or note explaining that while the bitwise operators are supported, they do not behave as set operators on numeric Index objects. We could also include a snippet demonstratingindA.intersection(indB)alongside the current example to explicitly show the expected set output ofIndex([3, 5, 7]).