Message406485
https://docs.python.org/3/reference/expressions.html#membership-test-operations
> For container types such as list, tuple, set, frozenset, dict, or collections.deque, the expression `x in y` is equivalent to `any(x is e or x == e for e in y)`.
Yet:
```py
import pandas as pd
import numpy as np
pd_0_dt = pd.Timedelta(0)
np_0_dt = np.timedelta64(0)
cm = (pd_0_dt, np_0_dt)
d1 = {np_0_dt: pd_0_dt}
d2 = {pd_0_dt: np_0_dt}
def test_membership_doc_claim(candidate_members, dct):
for m in candidate_members:
if m in dct:
assert any(m is e or m == e for e in dct)
if any(m is e or m == e for e in dct):
assert m in dct
if __name__ == "__main__":
test_membership_doc_claim(cm, d1) # Fails
test_membership_doc_claim(cm, d2) # Fails
```
Not too surprised, given the td.__hash__() implementation differs between these classes, but they are considered equal none the less.
Unsure whether it is the dict implementation or the doc claim that needs to budge here. |
|
Date |
User |
Action |
Args |
2021-11-17 19:00:34 | harahu | set | recipients:
+ harahu, ezio.melotti, eric.araujo, docs@python, willingc, mdk |
2021-11-17 19:00:34 | harahu | set | messageid: <1637175634.4.0.451304822027.issue45832@roundup.psfhosted.org> |
2021-11-17 19:00:34 | harahu | link | issue45832 messages |
2021-11-17 19:00:34 | harahu | create | |
|