Skip to content

Commit 2d6e0b2

Browse files
authored
Cln tests interval wrt inclusive (pandas-dev#47775)
Clean tests from closed usage
1 parent 833ef31 commit 2d6e0b2

File tree

7 files changed

+50
-53
lines changed

7 files changed

+50
-53
lines changed

pandas/tests/arrays/test_array.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def test_array_inference(data, expected):
298298
[
299299
# mix of frequencies
300300
[pd.Period("2000", "D"), pd.Period("2001", "A")],
301-
# mix of closed
301+
# mix of inclusive
302302
[pd.Interval(0, 1, "left"), pd.Interval(1, 2, "right")],
303303
# Mix of timezones
304304
[pd.Timestamp("2000", tz="CET"), pd.Timestamp("2000", tz="UTC")],

pandas/tests/dtypes/test_dtypes.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -593,13 +593,13 @@ def test_construction_string_regex(self, subtype):
593593
@pytest.mark.parametrize(
594594
"subtype", ["interval[int64]", "Interval[int64]", "int64", np.dtype("int64")]
595595
)
596-
def test_construction_allows_closed_none(self, subtype):
596+
def test_construction_allows_inclusive_none(self, subtype):
597597
# GH#38394
598598
dtype = IntervalDtype(subtype)
599599

600600
assert dtype.inclusive is None
601601

602-
def test_closed_mismatch(self):
602+
def test_inclusive_mismatch(self):
603603
msg = "'inclusive' keyword does not match value specified in dtype string"
604604
with pytest.raises(ValueError, match=msg):
605605
IntervalDtype("interval[int64, left]", "right")
@@ -638,15 +638,15 @@ def test_construction_errors(self, subtype):
638638
with pytest.raises(TypeError, match=msg):
639639
IntervalDtype(subtype)
640640

641-
def test_closed_must_match(self):
641+
def test_inclusive_must_match(self):
642642
# GH#37933
643643
dtype = IntervalDtype(np.float64, "left")
644644

645645
msg = "dtype.inclusive and 'inclusive' do not match"
646646
with pytest.raises(ValueError, match=msg):
647647
IntervalDtype(dtype, inclusive="both")
648648

649-
def test_closed_invalid(self):
649+
def test_inclusive_invalid(self):
650650
with pytest.raises(ValueError, match="inclusive must be one of"):
651651
IntervalDtype(np.float64, "foo")
652652

@@ -822,7 +822,7 @@ def test_not_string(self):
822822
# GH30568: though IntervalDtype has object kind, it cannot be string
823823
assert not is_string_dtype(IntervalDtype())
824824

825-
def test_unpickling_without_closed(self):
825+
def test_unpickling_without_inclusive(self):
826826
# GH#38394
827827
dtype = IntervalDtype("interval")
828828

pandas/tests/indexes/interval/test_constructors.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ def test_constructor_dtype(self, constructor, breaks, subtype):
104104
timedelta_range("1 day", periods=5),
105105
],
106106
)
107-
def test_constructor_pass_closed(self, constructor, breaks):
108-
# not passing closed to IntervalDtype, but to IntervalArray constructor
107+
def test_constructor_pass_inclusive(self, constructor, breaks):
108+
# not passing inclusive to IntervalDtype, but to IntervalArray constructor
109109
warn = None
110110
if isinstance(constructor, partial) and constructor.func is Index:
111111
# passing kwargs to Index is deprecated
@@ -193,7 +193,7 @@ def test_generic_errors(self, constructor):
193193
# filler input data to be used when supplying invalid kwargs
194194
filler = self.get_kwargs_from_breaks(range(10))
195195

196-
# invalid closed
196+
# invalid inclusive
197197
msg = "inclusive must be one of 'right', 'left', 'both', 'neither'"
198198
with pytest.raises(ValueError, match=msg):
199199
constructor(inclusive="invalid", **filler)
@@ -399,7 +399,7 @@ def test_constructor_string(self):
399399
pass
400400

401401
def test_constructor_errors(self, constructor):
402-
# mismatched closed within intervals with no constructor override
402+
# mismatched inclusive within intervals with no constructor override
403403
ivs = [Interval(0, 1, inclusive="right"), Interval(2, 3, inclusive="left")]
404404
msg = "intervals must all be inclusive on the same side"
405405
with pytest.raises(ValueError, match=msg):
@@ -420,7 +420,7 @@ def test_constructor_errors(self, constructor):
420420

421421
@pytest.mark.filterwarnings("ignore:Passing keywords other:FutureWarning")
422422
@pytest.mark.parametrize(
423-
"data, closed",
423+
"data, inclusive",
424424
[
425425
([], "both"),
426426
([np.nan, np.nan], "neither"),
@@ -438,14 +438,14 @@ def test_constructor_errors(self, constructor):
438438
(IntervalIndex.from_breaks(range(5), inclusive="both"), "right"),
439439
],
440440
)
441-
def test_override_inferred_closed(self, constructor, data, closed):
441+
def test_override_inferred_inclusive(self, constructor, data, inclusive):
442442
# GH 19370
443443
if isinstance(data, IntervalIndex):
444444
tuples = data.to_tuples()
445445
else:
446446
tuples = [(iv.left, iv.right) if notna(iv) else iv for iv in data]
447-
expected = IntervalIndex.from_tuples(tuples, inclusive=closed)
448-
result = constructor(data, inclusive=closed)
447+
expected = IntervalIndex.from_tuples(tuples, inclusive=inclusive)
448+
result = constructor(data, inclusive=inclusive)
449449
tm.assert_index_equal(result, expected)
450450

451451
@pytest.mark.parametrize(
@@ -460,7 +460,7 @@ def test_index_object_dtype(self, values_constructor):
460460
assert type(result) is Index
461461
tm.assert_numpy_array_equal(result.values, np.array(values))
462462

463-
def test_index_mixed_closed(self):
463+
def test_index_mixed_inclusive(self):
464464
# GH27172
465465
intervals = [
466466
Interval(0, 1, inclusive="left"),
@@ -473,8 +473,8 @@ def test_index_mixed_closed(self):
473473
tm.assert_index_equal(result, expected)
474474

475475

476-
def test_dtype_closed_mismatch():
477-
# GH#38394 closed specified in both dtype and IntervalIndex constructor
476+
def test_dtype_inclusive_mismatch():
477+
# GH#38394
478478

479479
dtype = IntervalDtype(np.int64, "left")
480480

pandas/tests/indexes/interval/test_indexing.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,20 @@ def test_get_loc_length_one_scalar(self, scalar, closed):
7676
with pytest.raises(KeyError, match=str(scalar)):
7777
index.get_loc(scalar)
7878

79-
@pytest.mark.parametrize("other_closed", ["left", "right", "both", "neither"])
79+
@pytest.mark.parametrize("other_inclusive", ["left", "right", "both", "neither"])
8080
@pytest.mark.parametrize("left, right", [(0, 5), (-1, 4), (-1, 6), (6, 7)])
81-
def test_get_loc_length_one_interval(self, left, right, closed, other_closed):
81+
def test_get_loc_length_one_interval(self, left, right, closed, other_inclusive):
8282
# GH 20921
8383
index = IntervalIndex.from_tuples([(0, 5)], inclusive=closed)
84-
interval = Interval(left, right, inclusive=other_closed)
84+
interval = Interval(left, right, inclusive=other_inclusive)
8585
if interval == index[0]:
8686
result = index.get_loc(interval)
8787
assert result == 0
8888
else:
8989
with pytest.raises(
9090
KeyError,
9191
match=re.escape(
92-
f"Interval({left}, {right}, inclusive='{other_closed}')"
92+
f"Interval({left}, {right}, inclusive='{other_inclusive}')"
9393
),
9494
):
9595
index.get_loc(interval)
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import pytest
2-
31
from pandas import IntervalIndex
42
import pandas._testing as tm
53

64

75
class TestPickle:
8-
@pytest.mark.parametrize("inclusive", ["left", "right", "both"])
9-
def test_pickle_round_trip_closed(self, inclusive):
6+
def test_pickle_round_trip_inclusive(self, closed):
107
# https://github.com/pandas-dev/pandas/issues/35658
11-
idx = IntervalIndex.from_tuples([(1, 2), (2, 3)], inclusive=inclusive)
8+
idx = IntervalIndex.from_tuples([(1, 2), (2, 3)], inclusive=closed)
129
result = tm.round_trip_pickle(idx)
1310
tm.assert_index_equal(result, idx)

pandas/tests/indexes/interval/test_setops.py

+25-25
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@
1010
import pandas._testing as tm
1111

1212

13-
def monotonic_index(start, end, dtype="int64", closed="right"):
13+
def monotonic_index(start, end, dtype="int64", inclusive="right"):
1414
return IntervalIndex.from_breaks(
15-
np.arange(start, end, dtype=dtype), inclusive=closed
15+
np.arange(start, end, dtype=dtype), inclusive=inclusive
1616
)
1717

1818

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)
2121

2222

2323
class TestIntervalIndex:
2424
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)
2727

28-
expected = monotonic_index(0, 13, closed=closed)
28+
expected = monotonic_index(0, 13, inclusive=closed)
2929
result = index[::-1].union(other, sort=sort)
3030
if sort is None:
3131
tm.assert_index_equal(result, expected)
@@ -41,31 +41,31 @@ def test_union(self, closed, sort):
4141

4242
def test_union_empty_result(self, closed, sort):
4343
# GH 19101: empty result, same dtype
44-
index = empty_index(dtype="int64", closed=closed)
44+
index = empty_index(dtype="int64", inclusive=closed)
4545
result = index.union(index, sort=sort)
4646
tm.assert_index_equal(result, index)
4747

4848
# 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)
5050
result = index.union(other, sort=sort)
5151
expected = other
5252
tm.assert_index_equal(result, expected)
5353

5454
other = index.union(index, sort=sort)
5555
tm.assert_index_equal(result, expected)
5656

57-
other = empty_index(dtype="uint64", closed=closed)
57+
other = empty_index(dtype="uint64", inclusive=closed)
5858
result = index.union(other, sort=sort)
5959
tm.assert_index_equal(result, expected)
6060

6161
result = other.union(index, sort=sort)
6262
tm.assert_index_equal(result, expected)
6363

6464
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)
6767

68-
expected = monotonic_index(5, 11, closed=closed)
68+
expected = monotonic_index(5, 11, inclusive=closed)
6969
result = index[::-1].intersection(other, sort=sort)
7070
if sort is None:
7171
tm.assert_index_equal(result, expected)
@@ -100,21 +100,21 @@ def test_intersection(self, closed, sort):
100100
tm.assert_index_equal(result, expected)
101101

102102
def test_intersection_empty_result(self, closed, sort):
103-
index = monotonic_index(0, 11, closed=closed)
103+
index = monotonic_index(0, 11, inclusive=closed)
104104

105105
# 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)
108108
result = index.intersection(other, sort=sort)
109109
tm.assert_index_equal(result, expected)
110110

111111
# 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)
113113
result = index.intersection(other, sort=sort)
114114
expected = other[:0]
115115
tm.assert_index_equal(result, expected)
116116

117-
other = monotonic_index(300, 314, dtype="uint64", closed=closed)
117+
other = monotonic_index(300, 314, dtype="uint64", inclusive=closed)
118118
result = index.intersection(other, sort=sort)
119119
tm.assert_index_equal(result, expected)
120120

@@ -136,7 +136,7 @@ def test_difference(self, closed, sort):
136136

137137
# GH 19101: empty result, same dtype
138138
result = index.difference(index, sort=sort)
139-
expected = empty_index(dtype="int64", closed=closed)
139+
expected = empty_index(dtype="int64", inclusive=closed)
140140
tm.assert_index_equal(result, expected)
141141

142142
# GH 19101: empty result, different dtypes
@@ -147,7 +147,7 @@ def test_difference(self, closed, sort):
147147
tm.assert_index_equal(result, expected)
148148

149149
def test_symmetric_difference(self, closed, sort):
150-
index = monotonic_index(0, 11, closed=closed)
150+
index = monotonic_index(0, 11, inclusive=closed)
151151
result = index[1:].symmetric_difference(index[:-1], sort=sort)
152152
expected = IntervalIndex([index[0], index[-1]])
153153
if sort is None:
@@ -156,7 +156,7 @@ def test_symmetric_difference(self, closed, sort):
156156

157157
# GH 19101: empty result, same dtype
158158
result = index.symmetric_difference(index, sort=sort)
159-
expected = empty_index(dtype="int64", closed=closed)
159+
expected = empty_index(dtype="int64", inclusive=closed)
160160
if sort is None:
161161
tm.assert_index_equal(result, expected)
162162
assert tm.equalContents(result, expected)
@@ -166,15 +166,15 @@ def test_symmetric_difference(self, closed, sort):
166166
index.left.astype("float64"), index.right, inclusive=closed
167167
)
168168
result = index.symmetric_difference(other, sort=sort)
169-
expected = empty_index(dtype="float64", closed=closed)
169+
expected = empty_index(dtype="float64", inclusive=closed)
170170
tm.assert_index_equal(result, expected)
171171

172172
@pytest.mark.filterwarnings("ignore:'<' not supported between:RuntimeWarning")
173173
@pytest.mark.parametrize(
174174
"op_name", ["union", "intersection", "difference", "symmetric_difference"]
175175
)
176176
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)
178178
set_op = getattr(index, op_name)
179179

180180
# 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):
187187
tm.assert_index_equal(result, expected)
188188

189189
# 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)
192192
expected = getattr(index.astype(object), op_name)(other, sort=sort)
193193
if op_name == "difference":
194194
expected = index

pandas/tests/series/test_constructors.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1200,8 +1200,8 @@ def test_constructor_infer_interval(self, data_constructor):
12001200
@pytest.mark.parametrize(
12011201
"data_constructor", [list, np.array], ids=["list", "ndarray[object]"]
12021202
)
1203-
def test_constructor_interval_mixed_closed(self, data_constructor):
1204-
# GH 23563: mixed closed results in object dtype (not interval dtype)
1203+
def test_constructor_interval_mixed_inclusive(self, data_constructor):
1204+
# GH 23563: mixed inclusive results in object dtype (not interval dtype)
12051205
data = [Interval(0, 1, inclusive="both"), Interval(0, 2, inclusive="neither")]
12061206
result = Series(data_constructor(data))
12071207
assert result.dtype == object

0 commit comments

Comments
 (0)