Repository navigation
Bug in Chapter 3.01 #443
Description
Activity
- 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.…On Wed, Aug 5, 2026 at 6:12 AM karlhegci ***@***.***> wrote: *karlhegci* left a comment (jakevdp/PythonDataScienceHandbook#443) <#443 (comment)> 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 <#443?email_source=notifications&email_token=CKTITMGU2YRGKPLX3HXOV2L5IKXZXA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJYG42DIMZSGY42M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#issuecomment-5187443269>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/CKTITMH3O2NCDRRIFY5QQJD5IKXZXAVCNFSNUABEKJSXA33TNF2G64TZHM3DKMZYHA4TCNZ3JFZXG5LFHMZTONZRGMZTGMBYHCQXMAQ> . Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS <https://github.com/notifications/mobile/ios/CKTITMDUWI6JGSRAKHYEQCT5IKXZXA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJYG42DIMZSGY42M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSVGM33PORSXEX3JN5ZQ> and Android <https://github.com/notifications/mobile/android/CKTITMBFNC4QXS4Y6BCSUBL5IKXZXA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJYG42DIMZSGY42M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ>. Download it today! You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
- Skip to content <https://mail.google.com/mail/u/0/> Using Gmail with screen readers <https://mail.google.com/mail/u/0/> <https://accounts.google.com/SignOutOptions?hl=en&continue=https://mail.google.com/mail&service=mail&ec=GBRAFw> Enable desktop notifications for Gmail. OK No thanks 2 of 19 Re: [jakevdp/PythonDataScienceHandbook] Bug in Chapter 3.01 (Issue #443) Inbox Summarize this email wafir645fcqs49 ***@***.***> Wed, Aug 5, 10:26 AM (5 days ago) to jakevdp/PythonDataScienceHandbook, Subscribed *wafir645fcqs49* left a comment (jakevdp/PythonDataScienceHandbook#443) <#443 (comment)> 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.On Wed, Aug 5, 2026 at 6:12 AM karlhegci ***@***.***> wrote: *karlhegci* left a comment (jakevdp/PythonDataScienceHandbook#443) <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 noteaboutthis distinction would improve clarity. — Reply to this email directly, view it on GitHub <#443?email_source=notifications&email_token=CKTITMGU2YRGKPLX3HXOV2L5IKXZXA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJYG42DIMZSGY42M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#issuecomment-5187443269, or unsubscribe <. Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS <and Android <. Download it today! You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>— Reply to this email directly, view it on GitHub <#443?email_source=notifications&email_token=CI5ETW5R3JZEMX3Z74DBS735ILVRZA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJYHE2DAOBQHEYKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#issuecomment-5189408090>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/CI5ETWZOQJISIV644GVX4CT5ILVRZAVCNFSNUABEKJSXA33TNF2G64TZHM3DKMZYHA4TCNZ3JFZXG5LFHMZTONZRGMZTGMBYHCQXMAQ> . Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS <https://github.com/notifications/mobile/ios/CI5ETW4GCJY7RIFFGSMH7YT5ILVRZA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJYHE2DAOBQHEYKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSVGM33PORSXEX3JN5ZQ> and Android <https://github.com/notifications/mobile/android/CI5ETW3YTKH7ZIL7JJ7IOUT5ILVRZA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJYHE2DAOBQHEYKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ>. Download it today! You are receiving this because you are subscribed to this thread. On Wed, Aug 5, 2026 at 10:26 AM wafir645fcqs49 ***@***.***> wrote:…*wafir645fcqs49* left a comment (jakevdp/PythonDataScienceHandbook#443) <#443 (comment)> 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. On Wed, Aug 5, 2026 at 6:12 AM karlhegci ***@***.***> wrote: > *karlhegci* left a comment (jakevdp/PythonDataScienceHandbook#443) > < #443 (comment)> > > 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 > < #443?email_source=notifications&email_token=CKTITMGU2YRGKPLX3HXOV2L5IKXZXA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJYG42DIMZSGY42M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#issuecomment-5187443269>, > or unsubscribe > < https://github.com/notifications/unsubscribe-auth/CKTITMH3O2NCDRRIFY5QQJD5IKXZXAVCNFSNUABEKJSXA33TNF2G64TZHM3DKMZYHA4TCNZ3JFZXG5LFHMZTONZRGMZTGMBYHCQXMAQ> > . > Triage notifications, keep track of coding agent tasks and review pull > requests on the go with GitHub Mobile for iOS > < https://github.com/notifications/mobile/ios/CKTITMDUWI6JGSRAKHYEQCT5IKXZXA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJYG42DIMZSGY42M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSVGM33PORSXEX3JN5ZQ> > and Android > < https://github.com/notifications/mobile/android/CKTITMBFNC4QXS4Y6BCSUBL5IKXZXA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJYG42DIMZSGY42M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ>. > Download it today! > You are receiving this because you are subscribed to this thread.Message > ID: ***@***.***> > — Reply to this email directly, view it on GitHub <#443?email_source=notifications&email_token=CI5ETW5R3JZEMX3Z74DBS735ILVRZA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJYHE2DAOBQHEYKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#issuecomment-5189408090>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/CI5ETWZOQJISIV644GVX4CT5ILVRZAVCNFSNUABEKJSXA33TNF2G64TZHM3DKMZYHA4TCNZ3JFZXG5LFHMZTONZRGMZTGMBYHCQXMAQ> . Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS <https://github.com/notifications/mobile/ios/CI5ETW4GCJY7RIFFGSMH7YT5ILVRZA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJYHE2DAOBQHEYKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSVGM33PORSXEX3JN5ZQ> and Android <https://github.com/notifications/mobile/android/CI5ETW3YTKH7ZIL7JJ7IOUT5ILVRZA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJYHE2DAOBQHEYKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ>. Download it today! You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
- Thanks for pointing this out. Clarifying the difference between the logical AND operation and indA.intersection(indB) would make the example much clearer.…On Wed, Aug 5, 2026 at 6:12 AM karlhegci ***@***.***> wrote: *karlhegci* left a comment (jakevdp/PythonDataScienceHandbook#443) <#443 (comment)> 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 <#443?email_source=notifications&email_token=CI5ETW2N7H7U4ECM72KBJ735IKXZVA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJYG42DIMZSGY42M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#issuecomment-5187443269>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/CI5ETWZ3DYEMU6WBGDYUPQT5IKXZVAVCNFSNUABEKJSXA33TNF2G64TZHM3DKMZYHA4TCNZ3JFZXG5LFHMZTONZRGMZTGMBYHCQXMAQ> . Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS <https://github.com/notifications/mobile/ios/CI5ETW5Z3BLYSW67LMD77PL5IKXZVA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJYG42DIMZSGY42M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSVGM33PORSXEX3JN5ZQ> and Android <https://github.com/notifications/mobile/android/CI5ETW527VALY6TPOTW6W3L5IKXZVA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJYG42DIMZSGY42M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ>. Download it today! You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
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.
ShowingindA.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 prioritizeindA.intersection(indB)is the right move, but we should also explicitly warn readers that&behavior onpd.Indexobjects depends heavily on the underlying dtype.This behavior changed in pandas 1.0.0 where the
&operator on integer Index objects was deprecated forSince 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.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.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?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.
Error is located in "Index as ordered set" section
indA & indB # intersectionreturns
Index([0, 3, 5, 7, 9], dtype='int64')but for intersection result should be [3, 5, 7], instead pandas performs logical AND
indA.intersection(indB) # Index([3, 5, 7], dtype='int64')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