@@ -50,6 +50,79 @@ def test_compare_invalid_scalar(self, box_with_array, scalar):
50
50
parr = tm .box_expected (pi , box_with_array )
51
51
assert_invalid_comparison (parr , scalar , box_with_array )
52
52
53
+ @pytest .mark .parametrize (
54
+ "other" ,
55
+ [
56
+ pd .date_range ("2000" , periods = 4 ).array ,
57
+ pd .timedelta_range ("1D" , periods = 4 ).array ,
58
+ np .arange (4 ),
59
+ np .arange (4 ).astype (np .float64 ),
60
+ list (range (4 )),
61
+ ],
62
+ )
63
+ def test_compare_invalid_listlike (self , box_with_array , other ):
64
+ pi = pd .period_range ("2000" , periods = 4 )
65
+ parr = tm .box_expected (pi , box_with_array )
66
+ assert_invalid_comparison (parr , other , box_with_array )
67
+
68
+ @pytest .mark .parametrize ("other_box" , [list , np .array , lambda x : x .astype (object )])
69
+ def test_compare_object_dtype (self , box_with_array , other_box ):
70
+ pi = pd .period_range ("2000" , periods = 5 )
71
+ parr = tm .box_expected (pi , box_with_array )
72
+
73
+ xbox = np .ndarray if box_with_array is pd .Index else box_with_array
74
+
75
+ other = other_box (pi )
76
+
77
+ expected = np .array ([True , True , True , True , True ])
78
+ expected = tm .box_expected (expected , xbox )
79
+
80
+ result = parr == other
81
+ tm .assert_equal (result , expected )
82
+ result = parr <= other
83
+ tm .assert_equal (result , expected )
84
+ result = parr >= other
85
+ tm .assert_equal (result , expected )
86
+
87
+ result = parr != other
88
+ tm .assert_equal (result , ~ expected )
89
+ result = parr < other
90
+ tm .assert_equal (result , ~ expected )
91
+ result = parr > other
92
+ tm .assert_equal (result , ~ expected )
93
+
94
+ other = other_box (pi [::- 1 ])
95
+
96
+ expected = np .array ([False , False , True , False , False ])
97
+ expected = tm .box_expected (expected , xbox )
98
+ result = parr == other
99
+ tm .assert_equal (result , expected )
100
+
101
+ expected = np .array ([True , True , True , False , False ])
102
+ expected = tm .box_expected (expected , xbox )
103
+ result = parr <= other
104
+ tm .assert_equal (result , expected )
105
+
106
+ expected = np .array ([False , False , True , True , True ])
107
+ expected = tm .box_expected (expected , xbox )
108
+ result = parr >= other
109
+ tm .assert_equal (result , expected )
110
+
111
+ expected = np .array ([True , True , False , True , True ])
112
+ expected = tm .box_expected (expected , xbox )
113
+ result = parr != other
114
+ tm .assert_equal (result , expected )
115
+
116
+ expected = np .array ([True , True , False , False , False ])
117
+ expected = tm .box_expected (expected , xbox )
118
+ result = parr < other
119
+ tm .assert_equal (result , expected )
120
+
121
+ expected = np .array ([False , False , False , True , True ])
122
+ expected = tm .box_expected (expected , xbox )
123
+ result = parr > other
124
+ tm .assert_equal (result , expected )
125
+
53
126
54
127
class TestPeriodIndexComparisons :
55
128
# TODO: parameterize over boxes
0 commit comments