10
10
import pandas ._testing as tm
11
11
12
12
13
- def monotonic_index (start , end , dtype = "int64" , closed = "right" ):
13
+ def monotonic_index (start , end , dtype = "int64" , inclusive = "right" ):
14
14
return IntervalIndex .from_breaks (
15
- np .arange (start , end , dtype = dtype ), inclusive = closed
15
+ np .arange (start , end , dtype = dtype ), inclusive = inclusive
16
16
)
17
17
18
18
19
- def empty_index (dtype = "int64" , closed = "right" ):
20
- return IntervalIndex (np .array ([], dtype = dtype ), inclusive = closed )
19
+ def empty_index (dtype = "int64" , inclusive = "right" ):
20
+ return IntervalIndex (np .array ([], dtype = dtype ), inclusive = inclusive )
21
21
22
22
23
23
class TestIntervalIndex :
24
24
def test_union (self , closed , sort ):
25
- index = monotonic_index (0 , 11 , closed = closed )
26
- other = monotonic_index (5 , 13 , closed = closed )
25
+ index = monotonic_index (0 , 11 , inclusive = closed )
26
+ other = monotonic_index (5 , 13 , inclusive = closed )
27
27
28
- expected = monotonic_index (0 , 13 , closed = closed )
28
+ expected = monotonic_index (0 , 13 , inclusive = closed )
29
29
result = index [::- 1 ].union (other , sort = sort )
30
30
if sort is None :
31
31
tm .assert_index_equal (result , expected )
@@ -41,31 +41,31 @@ def test_union(self, closed, sort):
41
41
42
42
def test_union_empty_result (self , closed , sort ):
43
43
# GH 19101: empty result, same dtype
44
- index = empty_index (dtype = "int64" , closed = closed )
44
+ index = empty_index (dtype = "int64" , inclusive = closed )
45
45
result = index .union (index , sort = sort )
46
46
tm .assert_index_equal (result , index )
47
47
48
48
# GH 19101: empty result, different numeric dtypes -> common dtype is f8
49
- other = empty_index (dtype = "float64" , closed = closed )
49
+ other = empty_index (dtype = "float64" , inclusive = closed )
50
50
result = index .union (other , sort = sort )
51
51
expected = other
52
52
tm .assert_index_equal (result , expected )
53
53
54
54
other = index .union (index , sort = sort )
55
55
tm .assert_index_equal (result , expected )
56
56
57
- other = empty_index (dtype = "uint64" , closed = closed )
57
+ other = empty_index (dtype = "uint64" , inclusive = closed )
58
58
result = index .union (other , sort = sort )
59
59
tm .assert_index_equal (result , expected )
60
60
61
61
result = other .union (index , sort = sort )
62
62
tm .assert_index_equal (result , expected )
63
63
64
64
def test_intersection (self , closed , sort ):
65
- index = monotonic_index (0 , 11 , closed = closed )
66
- other = monotonic_index (5 , 13 , closed = closed )
65
+ index = monotonic_index (0 , 11 , inclusive = closed )
66
+ other = monotonic_index (5 , 13 , inclusive = closed )
67
67
68
- expected = monotonic_index (5 , 11 , closed = closed )
68
+ expected = monotonic_index (5 , 11 , inclusive = closed )
69
69
result = index [::- 1 ].intersection (other , sort = sort )
70
70
if sort is None :
71
71
tm .assert_index_equal (result , expected )
@@ -100,21 +100,21 @@ def test_intersection(self, closed, sort):
100
100
tm .assert_index_equal (result , expected )
101
101
102
102
def test_intersection_empty_result (self , closed , sort ):
103
- index = monotonic_index (0 , 11 , closed = closed )
103
+ index = monotonic_index (0 , 11 , inclusive = closed )
104
104
105
105
# GH 19101: empty result, same dtype
106
- other = monotonic_index (300 , 314 , closed = closed )
107
- expected = empty_index (dtype = "int64" , closed = closed )
106
+ other = monotonic_index (300 , 314 , inclusive = closed )
107
+ expected = empty_index (dtype = "int64" , inclusive = closed )
108
108
result = index .intersection (other , sort = sort )
109
109
tm .assert_index_equal (result , expected )
110
110
111
111
# GH 19101: empty result, different numeric dtypes -> common dtype is float64
112
- other = monotonic_index (300 , 314 , dtype = "float64" , closed = closed )
112
+ other = monotonic_index (300 , 314 , dtype = "float64" , inclusive = closed )
113
113
result = index .intersection (other , sort = sort )
114
114
expected = other [:0 ]
115
115
tm .assert_index_equal (result , expected )
116
116
117
- other = monotonic_index (300 , 314 , dtype = "uint64" , closed = closed )
117
+ other = monotonic_index (300 , 314 , dtype = "uint64" , inclusive = closed )
118
118
result = index .intersection (other , sort = sort )
119
119
tm .assert_index_equal (result , expected )
120
120
@@ -136,7 +136,7 @@ def test_difference(self, closed, sort):
136
136
137
137
# GH 19101: empty result, same dtype
138
138
result = index .difference (index , sort = sort )
139
- expected = empty_index (dtype = "int64" , closed = closed )
139
+ expected = empty_index (dtype = "int64" , inclusive = closed )
140
140
tm .assert_index_equal (result , expected )
141
141
142
142
# GH 19101: empty result, different dtypes
@@ -147,7 +147,7 @@ def test_difference(self, closed, sort):
147
147
tm .assert_index_equal (result , expected )
148
148
149
149
def test_symmetric_difference (self , closed , sort ):
150
- index = monotonic_index (0 , 11 , closed = closed )
150
+ index = monotonic_index (0 , 11 , inclusive = closed )
151
151
result = index [1 :].symmetric_difference (index [:- 1 ], sort = sort )
152
152
expected = IntervalIndex ([index [0 ], index [- 1 ]])
153
153
if sort is None :
@@ -156,7 +156,7 @@ def test_symmetric_difference(self, closed, sort):
156
156
157
157
# GH 19101: empty result, same dtype
158
158
result = index .symmetric_difference (index , sort = sort )
159
- expected = empty_index (dtype = "int64" , closed = closed )
159
+ expected = empty_index (dtype = "int64" , inclusive = closed )
160
160
if sort is None :
161
161
tm .assert_index_equal (result , expected )
162
162
assert tm .equalContents (result , expected )
@@ -166,15 +166,15 @@ def test_symmetric_difference(self, closed, sort):
166
166
index .left .astype ("float64" ), index .right , inclusive = closed
167
167
)
168
168
result = index .symmetric_difference (other , sort = sort )
169
- expected = empty_index (dtype = "float64" , closed = closed )
169
+ expected = empty_index (dtype = "float64" , inclusive = closed )
170
170
tm .assert_index_equal (result , expected )
171
171
172
172
@pytest .mark .filterwarnings ("ignore:'<' not supported between:RuntimeWarning" )
173
173
@pytest .mark .parametrize (
174
174
"op_name" , ["union" , "intersection" , "difference" , "symmetric_difference" ]
175
175
)
176
176
def test_set_incompatible_types (self , closed , op_name , sort ):
177
- index = monotonic_index (0 , 11 , closed = closed )
177
+ index = monotonic_index (0 , 11 , inclusive = closed )
178
178
set_op = getattr (index , op_name )
179
179
180
180
# TODO: standardize return type of non-union setops type(self vs other)
@@ -187,8 +187,8 @@ def test_set_incompatible_types(self, closed, op_name, sort):
187
187
tm .assert_index_equal (result , expected )
188
188
189
189
# mixed closed -> cast to object
190
- for other_closed in {"right" , "left" , "both" , "neither" } - {closed }:
191
- other = monotonic_index (0 , 11 , closed = other_closed )
190
+ for other_inclusive in {"right" , "left" , "both" , "neither" } - {closed }:
191
+ other = monotonic_index (0 , 11 , inclusive = other_inclusive )
192
192
expected = getattr (index .astype (object ), op_name )(other , sort = sort )
193
193
if op_name == "difference" :
194
194
expected = index
0 commit comments