File tree 1 file changed +25
-0
lines changed
pandas/tests/scalar/timedelta
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 1
1
""" test the scalar Timedelta """
2
2
from datetime import timedelta
3
+ import sys
3
4
4
5
from hypothesis import (
5
6
given ,
@@ -918,6 +919,30 @@ def test_timedelta_hash_equality(self):
918
919
ns_td = Timedelta (1 , "ns" )
919
920
assert hash (ns_td ) != hash (ns_td .to_pytimedelta ())
920
921
922
+ @pytest .mark .xfail (
923
+ reason = "pd.Timedelta violates the Python hash invariant (GH#44504)." ,
924
+ raises = AssertionError ,
925
+ )
926
+ @given (
927
+ st .integers (
928
+ min_value = (- sys .maxsize - 1 ) // 500 ,
929
+ max_value = sys .maxsize // 500 ,
930
+ )
931
+ )
932
+ def test_hash_equality_invariance (self , half_microseconds : int ) -> None :
933
+ # GH#44504
934
+
935
+ nanoseconds = half_microseconds * 500
936
+
937
+ pandas_timedelta = Timedelta (nanoseconds )
938
+ numpy_timedelta = np .timedelta64 (nanoseconds )
939
+
940
+ # See: https://docs.python.org/3/glossary.html#term-hashable
941
+ # Hashable objects which compare equal must have the same hash value.
942
+ assert pandas_timedelta != numpy_timedelta or hash (pandas_timedelta ) == hash (
943
+ numpy_timedelta
944
+ )
945
+
921
946
def test_implementation_limits (self ):
922
947
min_td = Timedelta (Timedelta .min )
923
948
max_td = Timedelta (Timedelta .max )
You can’t perform that action at this time.
0 commit comments