|
9 | 9 | import sys
|
10 | 10 | from typing import Hashable
|
11 | 11 |
|
12 |
| -import numpy as np |
13 |
| -import pytest |
14 | 12 | from hypothesis import given
|
15 | 13 | from hypothesis.strategies import integers
|
| 14 | +import numpy as np |
| 15 | +import pytest |
16 | 16 |
|
17 | 17 | from pandas.errors import OutOfBoundsTimedelta
|
18 | 18 |
|
@@ -1147,13 +1147,18 @@ def test_compare_unknown_type(self, val):
|
1147 | 1147 | with pytest.raises(TypeError, match=msg):
|
1148 | 1148 | t < val
|
1149 | 1149 |
|
| 1150 | + @pytest.mark.xfail( |
| 1151 | + reason="pd.Timedelta violates hash invariant (GH#44504).", |
| 1152 | + raises=AssertionError, |
| 1153 | + strict=True, |
| 1154 | + ) |
1150 | 1155 | @given(integers(min_value=-sys.maxsize - 1, max_value=sys.maxsize))
|
1151 |
| - def test_hash_invariant(value: int) -> None: |
| 1156 | + def test_hash_invariant(self, value: int) -> None: |
1152 | 1157 | """Reproducing GH#44504
|
1153 |
| - |
| 1158 | +
|
1154 | 1159 | See: https://github.com/pandas-dev/pandas/issues/44504
|
1155 | 1160 | """
|
1156 |
| - |
| 1161 | + |
1157 | 1162 | # See: UnitChoices in pandas/_libs/tslibs/timedeltas.pyi
|
1158 | 1163 | unit_choices = (
|
1159 | 1164 | "W",
|
@@ -1195,23 +1200,20 @@ def test_hash_invariant(value: int) -> None:
|
1195 | 1200 | "nanosecond",
|
1196 | 1201 | "n",
|
1197 | 1202 | )
|
1198 |
| - |
| 1203 | + |
1199 | 1204 | def _hash_invariance_upheld(v1: Hashable, v2: Hashable) -> bool:
|
1200 | 1205 | if v1 != v2:
|
1201 | 1206 | return True
|
1202 |
| - |
| 1207 | + |
1203 | 1208 | # See: https://docs.python.org/3/glossary.html#term-hashable
|
1204 | 1209 | # Hashable objects which compare equal must have the same hash value.
|
1205 | 1210 | return hash(v1) == hash(v2)
|
1206 |
| - |
| 1211 | + |
1207 | 1212 | for unit in unit_choices:
|
1208 | 1213 | pd_td = Timedelta(value, unit)
|
1209 | 1214 | np_td = np.timedelta64(value)
|
1210 |
| - |
1211 |
| - try: |
1212 |
| - assert _hash_invariance_upheld(pd_td, np_td) |
1213 |
| - except AssertionError: |
1214 |
| - pytest.xfail("pd.Timedelta violates hash invariant (GH#44504).") |
| 1215 | + |
| 1216 | + assert _hash_invariance_upheld(pd_td, np_td) |
1215 | 1217 |
|
1216 | 1218 |
|
1217 | 1219 | def test_ops_notimplemented():
|
|
0 commit comments