@@ -50,7 +50,7 @@ def left_right_dtypes(request):
50
50
51
51
52
52
@pytest .fixture
53
- def array (left_right_dtypes ):
53
+ def interval_array (left_right_dtypes ):
54
54
"""
55
55
Fixture to generate an IntervalArray of various dtypes containing NA if possible
56
56
"""
@@ -98,42 +98,42 @@ def interval_constructor(self, request):
98
98
"""
99
99
return request .param
100
100
101
- def elementwise_comparison (self , op , array , other ):
101
+ def elementwise_comparison (self , op , interval_array , other ):
102
102
"""
103
103
Helper that performs elementwise comparisons between `array` and `other`
104
104
"""
105
- other = other if is_list_like (other ) else [other ] * len (array )
106
- expected = np .array ([op (x , y ) for x , y in zip (array , other )])
105
+ other = other if is_list_like (other ) else [other ] * len (interval_array )
106
+ expected = np .array ([op (x , y ) for x , y in zip (interval_array , other )])
107
107
if isinstance (other , Series ):
108
108
return Series (expected , index = other .index )
109
109
return expected
110
110
111
- def test_compare_scalar_interval (self , op , array ):
111
+ def test_compare_scalar_interval (self , op , interval_array ):
112
112
# matches first interval
113
- other = array [0 ]
114
- result = op (array , other )
115
- expected = self .elementwise_comparison (op , array , other )
113
+ other = interval_array [0 ]
114
+ result = op (interval_array , other )
115
+ expected = self .elementwise_comparison (op , interval_array , other )
116
116
tm .assert_numpy_array_equal (result , expected )
117
117
118
118
# matches on a single endpoint but not both
119
- other = Interval (array .left [0 ], array .right [1 ])
120
- result = op (array , other )
121
- expected = self .elementwise_comparison (op , array , other )
119
+ other = Interval (interval_array .left [0 ], interval_array .right [1 ])
120
+ result = op (interval_array , other )
121
+ expected = self .elementwise_comparison (op , interval_array , other )
122
122
tm .assert_numpy_array_equal (result , expected )
123
123
124
124
def test_compare_scalar_interval_mixed_closed (self , op , closed , other_closed ):
125
- array = IntervalArray .from_arrays (range (2 ), range (1 , 3 ), closed = closed )
125
+ interval_array = IntervalArray .from_arrays (range (2 ), range (1 , 3 ), closed = closed )
126
126
other = Interval (0 , 1 , closed = other_closed )
127
127
128
- result = op (array , other )
129
- expected = self .elementwise_comparison (op , array , other )
128
+ result = op (interval_array , other )
129
+ expected = self .elementwise_comparison (op , interval_array , other )
130
130
tm .assert_numpy_array_equal (result , expected )
131
131
132
- def test_compare_scalar_na (self , op , array , nulls_fixture , request ):
133
- result = op (array , nulls_fixture )
134
- expected = self .elementwise_comparison (op , array , nulls_fixture )
132
+ def test_compare_scalar_na (self , op , interval_array , nulls_fixture , request ):
133
+ result = op (interval_array , nulls_fixture )
134
+ expected = self .elementwise_comparison (op , interval_array , nulls_fixture )
135
135
136
- if nulls_fixture is pd .NA and array .dtype .subtype != "int64" :
136
+ if nulls_fixture is pd .NA and interval_array .dtype .subtype != "int64" :
137
137
mark = pytest .mark .xfail (
138
138
reason = "broken for non-integer IntervalArray; see GH 31882"
139
139
)
@@ -154,38 +154,40 @@ def test_compare_scalar_na(self, op, array, nulls_fixture, request):
154
154
Period ("2017-01-01" , "D" ),
155
155
],
156
156
)
157
- def test_compare_scalar_other (self , op , array , other ):
158
- result = op (array , other )
159
- expected = self .elementwise_comparison (op , array , other )
157
+ def test_compare_scalar_other (self , op , interval_array , other ):
158
+ result = op (interval_array , other )
159
+ expected = self .elementwise_comparison (op , interval_array , other )
160
160
tm .assert_numpy_array_equal (result , expected )
161
161
162
- def test_compare_list_like_interval (self , op , array , interval_constructor ):
162
+ def test_compare_list_like_interval (self , op , interval_array , interval_constructor ):
163
163
# same endpoints
164
- other = interval_constructor (array .left , array .right )
165
- result = op (array , other )
166
- expected = self .elementwise_comparison (op , array , other )
164
+ other = interval_constructor (interval_array .left , interval_array .right )
165
+ result = op (interval_array , other )
166
+ expected = self .elementwise_comparison (op , interval_array , other )
167
167
tm .assert_equal (result , expected )
168
168
169
169
# different endpoints
170
- other = interval_constructor (array .left [::- 1 ], array .right [::- 1 ])
171
- result = op (array , other )
172
- expected = self .elementwise_comparison (op , array , other )
170
+ other = interval_constructor (
171
+ interval_array .left [::- 1 ], interval_array .right [::- 1 ]
172
+ )
173
+ result = op (interval_array , other )
174
+ expected = self .elementwise_comparison (op , interval_array , other )
173
175
tm .assert_equal (result , expected )
174
176
175
177
# all nan endpoints
176
178
other = interval_constructor ([np .nan ] * 4 , [np .nan ] * 4 )
177
- result = op (array , other )
178
- expected = self .elementwise_comparison (op , array , other )
179
+ result = op (interval_array , other )
180
+ expected = self .elementwise_comparison (op , interval_array , other )
179
181
tm .assert_equal (result , expected )
180
182
181
183
def test_compare_list_like_interval_mixed_closed (
182
184
self , op , interval_constructor , closed , other_closed
183
185
):
184
- array = IntervalArray .from_arrays (range (2 ), range (1 , 3 ), closed = closed )
186
+ interval_array = IntervalArray .from_arrays (range (2 ), range (1 , 3 ), closed = closed )
185
187
other = interval_constructor (range (2 ), range (1 , 3 ), closed = other_closed )
186
188
187
- result = op (array , other )
188
- expected = self .elementwise_comparison (op , array , other )
189
+ result = op (interval_array , other )
190
+ expected = self .elementwise_comparison (op , interval_array , other )
189
191
tm .assert_equal (result , expected )
190
192
191
193
@pytest .mark .parametrize (
@@ -206,17 +208,17 @@ def test_compare_list_like_interval_mixed_closed(
206
208
),
207
209
],
208
210
)
209
- def test_compare_list_like_object (self , op , array , other ):
210
- result = op (array , other )
211
- expected = self .elementwise_comparison (op , array , other )
211
+ def test_compare_list_like_object (self , op , interval_array , other ):
212
+ result = op (interval_array , other )
213
+ expected = self .elementwise_comparison (op , interval_array , other )
212
214
tm .assert_numpy_array_equal (result , expected )
213
215
214
- def test_compare_list_like_nan (self , op , array , nulls_fixture , request ):
216
+ def test_compare_list_like_nan (self , op , interval_array , nulls_fixture , request ):
215
217
other = [nulls_fixture ] * 4
216
- result = op (array , other )
217
- expected = self .elementwise_comparison (op , array , other )
218
+ result = op (interval_array , other )
219
+ expected = self .elementwise_comparison (op , interval_array , other )
218
220
219
- if nulls_fixture is pd .NA and array .dtype .subtype != "i8" :
221
+ if nulls_fixture is pd .NA and interval_array .dtype .subtype != "i8" :
220
222
reason = "broken for non-integer IntervalArray; see GH 31882"
221
223
mark = pytest .mark .xfail (reason = reason )
222
224
request .node .add_marker (mark )
@@ -239,18 +241,18 @@ def test_compare_list_like_nan(self, op, array, nulls_fixture, request):
239
241
],
240
242
ids = lambda x : str (x .dtype ),
241
243
)
242
- def test_compare_list_like_other (self , op , array , other ):
243
- result = op (array , other )
244
- expected = self .elementwise_comparison (op , array , other )
244
+ def test_compare_list_like_other (self , op , interval_array , other ):
245
+ result = op (interval_array , other )
246
+ expected = self .elementwise_comparison (op , interval_array , other )
245
247
tm .assert_numpy_array_equal (result , expected )
246
248
247
249
@pytest .mark .parametrize ("length" , [1 , 3 , 5 ])
248
250
@pytest .mark .parametrize ("other_constructor" , [IntervalArray , list ])
249
251
def test_compare_length_mismatch_errors (self , op , other_constructor , length ):
250
- array = IntervalArray .from_arrays (range (4 ), range (1 , 5 ))
252
+ interval_array = IntervalArray .from_arrays (range (4 ), range (1 , 5 ))
251
253
other = other_constructor ([Interval (0 , 1 )] * length )
252
254
with pytest .raises (ValueError , match = "Lengths must match to compare" ):
253
- op (array , other )
255
+ op (interval_array , other )
254
256
255
257
@pytest .mark .parametrize (
256
258
"constructor, expected_type, assert_func" ,
0 commit comments