Skip to content

Commit e4c17f7

Browse files
authored
CLN: Rename ordered_fixture --> ordered (#33192)
1 parent f5b3d7c commit e4c17f7

File tree

10 files changed

+41
-51
lines changed

10 files changed

+41
-51
lines changed

pandas/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def observed(request):
182182

183183

184184
@pytest.fixture(params=[True, False, None])
185-
def ordered_fixture(request):
185+
def ordered(request):
186186
"""
187187
Boolean 'ordered' parameter for Categorical.
188188
"""

pandas/tests/arrays/categorical/test_algos.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -140,23 +140,21 @@ def test_take_empty(self, allow_fill):
140140
with pytest.raises(IndexError, match=msg):
141141
cat.take([0], allow_fill=allow_fill)
142142

143-
def test_positional_take(self, ordered_fixture):
143+
def test_positional_take(self, ordered):
144144
cat = pd.Categorical(
145-
["a", "a", "b", "b"], categories=["b", "a"], ordered=ordered_fixture
145+
["a", "a", "b", "b"], categories=["b", "a"], ordered=ordered
146146
)
147147
result = cat.take([0, 1, 2], allow_fill=False)
148148
expected = pd.Categorical(
149-
["a", "a", "b"], categories=cat.categories, ordered=ordered_fixture
149+
["a", "a", "b"], categories=cat.categories, ordered=ordered
150150
)
151151
tm.assert_categorical_equal(result, expected)
152152

153-
def test_positional_take_unobserved(self, ordered_fixture):
154-
cat = pd.Categorical(
155-
["a", "b"], categories=["a", "b", "c"], ordered=ordered_fixture
156-
)
153+
def test_positional_take_unobserved(self, ordered):
154+
cat = pd.Categorical(["a", "b"], categories=["a", "b", "c"], ordered=ordered)
157155
result = cat.take([1, 0], allow_fill=False)
158156
expected = pd.Categorical(
159-
["b", "a"], categories=cat.categories, ordered=ordered_fixture
157+
["b", "a"], categories=cat.categories, ordered=ordered
160158
)
161159
tm.assert_categorical_equal(result, expected)
162160

pandas/tests/arrays/categorical/test_analytics.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ def test_mode(self, values, categories, exp_mode):
114114
exp = Categorical(exp_mode, categories=categories, ordered=True)
115115
tm.assert_categorical_equal(res, exp)
116116

117-
def test_searchsorted(self, ordered_fixture):
117+
def test_searchsorted(self, ordered):
118118
# https://github.com/pandas-dev/pandas/issues/8420
119119
# https://github.com/pandas-dev/pandas/issues/14522
120120

121121
cat = Categorical(
122122
["cheese", "milk", "apple", "bread", "bread"],
123123
categories=["cheese", "milk", "apple", "bread"],
124-
ordered=ordered_fixture,
124+
ordered=ordered,
125125
)
126126
ser = Series(cat)
127127

pandas/tests/dtypes/test_dtypes.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -730,10 +730,10 @@ class TestCategoricalDtypeParametrized:
730730
pd.date_range("2017", periods=4),
731731
],
732732
)
733-
def test_basic(self, categories, ordered_fixture):
734-
c1 = CategoricalDtype(categories, ordered=ordered_fixture)
733+
def test_basic(self, categories, ordered):
734+
c1 = CategoricalDtype(categories, ordered=ordered)
735735
tm.assert_index_equal(c1.categories, pd.Index(categories))
736-
assert c1.ordered is ordered_fixture
736+
assert c1.ordered is ordered
737737

738738
def test_order_matters(self):
739739
categories = ["a", "b"]
@@ -754,7 +754,7 @@ def test_categories(self):
754754
tm.assert_index_equal(result.categories, pd.Index(["a", "b", "c"]))
755755
assert result.ordered is False
756756

757-
def test_equal_but_different(self, ordered_fixture):
757+
def test_equal_but_different(self, ordered):
758758
c1 = CategoricalDtype([1, 2, 3])
759759
c2 = CategoricalDtype([1.0, 2.0, 3.0])
760760
assert c1 is not c2
@@ -818,8 +818,8 @@ def test_categorical_equality(self, ordered1, ordered2):
818818

819819
@pytest.mark.parametrize("categories", [list("abc"), None])
820820
@pytest.mark.parametrize("other", ["category", "not a category"])
821-
def test_categorical_equality_strings(self, categories, ordered_fixture, other):
822-
c1 = CategoricalDtype(categories, ordered_fixture)
821+
def test_categorical_equality_strings(self, categories, ordered, other):
822+
c1 = CategoricalDtype(categories, ordered)
823823
result = c1 == other
824824
expected = other == "category"
825825
assert result is expected
@@ -862,12 +862,12 @@ def test_from_categorical_dtype_both(self):
862862
)
863863
assert result == CategoricalDtype([1, 2], ordered=False)
864864

865-
def test_str_vs_repr(self, ordered_fixture):
866-
c1 = CategoricalDtype(["a", "b"], ordered=ordered_fixture)
865+
def test_str_vs_repr(self, ordered):
866+
c1 = CategoricalDtype(["a", "b"], ordered=ordered)
867867
assert str(c1) == "category"
868868
# Py2 will have unicode prefixes
869869
pat = r"CategoricalDtype\(categories=\[.*\], ordered={ordered}\)"
870-
assert re.match(pat.format(ordered=ordered_fixture), repr(c1))
870+
assert re.match(pat.format(ordered=ordered), repr(c1))
871871

872872
def test_categorical_categories(self):
873873
# GH17884
@@ -880,9 +880,9 @@ def test_categorical_categories(self):
880880
"new_categories", [list("abc"), list("cba"), list("wxyz"), None]
881881
)
882882
@pytest.mark.parametrize("new_ordered", [True, False, None])
883-
def test_update_dtype(self, ordered_fixture, new_categories, new_ordered):
883+
def test_update_dtype(self, ordered, new_categories, new_ordered):
884884
original_categories = list("abc")
885-
dtype = CategoricalDtype(original_categories, ordered_fixture)
885+
dtype = CategoricalDtype(original_categories, ordered)
886886
new_dtype = CategoricalDtype(new_categories, new_ordered)
887887

888888
result = dtype.update_dtype(new_dtype)
@@ -892,8 +892,8 @@ def test_update_dtype(self, ordered_fixture, new_categories, new_ordered):
892892
tm.assert_index_equal(result.categories, expected_categories)
893893
assert result.ordered is expected_ordered
894894

895-
def test_update_dtype_string(self, ordered_fixture):
896-
dtype = CategoricalDtype(list("abc"), ordered_fixture)
895+
def test_update_dtype_string(self, ordered):
896+
dtype = CategoricalDtype(list("abc"), ordered)
897897
expected_categories = dtype.categories
898898
expected_ordered = dtype.ordered
899899
result = dtype.update_dtype("category")

pandas/tests/groupby/test_categorical.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1226,10 +1226,10 @@ def test_groupby_categorical_axis_1(code):
12261226
tm.assert_frame_equal(result, expected)
12271227

12281228

1229-
def test_groupby_cat_preserves_structure(observed, ordered_fixture):
1229+
def test_groupby_cat_preserves_structure(observed, ordered):
12301230
# GH 28787
12311231
df = DataFrame(
1232-
{"Name": Categorical(["Bob", "Greg"], ordered=ordered_fixture), "Item": [1, 2]},
1232+
{"Name": Categorical(["Bob", "Greg"], ordered=ordered), "Item": [1, 2]},
12331233
columns=["Name", "Item"],
12341234
)
12351235
expected = df.copy()

pandas/tests/indexes/categorical/test_map.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ class TestMap:
1515
],
1616
ids=["string", "interval"],
1717
)
18-
def test_map_str(self, data, categories, ordered_fixture):
18+
def test_map_str(self, data, categories, ordered):
1919
# GH 31202 - override base class since we want to maintain categorical/ordered
20-
index = CategoricalIndex(data, categories=categories, ordered=ordered_fixture)
20+
index = CategoricalIndex(data, categories=categories, ordered=ordered)
2121
result = index.map(str)
2222
expected = CategoricalIndex(
23-
map(str, data), categories=map(str, categories), ordered=ordered_fixture
23+
map(str, data), categories=map(str, categories), ordered=ordered
2424
)
2525
tm.assert_index_equal(result, expected)
2626

pandas/tests/indexes/interval/test_indexing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@ def test_get_indexer_length_one_interval(self, size, closed):
240240
["foo", "foo", "bar", "baz"],
241241
],
242242
)
243-
def test_get_indexer_categorical(self, target, ordered_fixture):
243+
def test_get_indexer_categorical(self, target, ordered):
244244
# GH 30063: categorical and non-categorical results should be consistent
245245
index = IntervalIndex.from_tuples([(0, 1), (1, 2), (3, 4)])
246-
categorical_target = CategoricalIndex(target, ordered=ordered_fixture)
246+
categorical_target = CategoricalIndex(target, ordered=ordered)
247247

248248
result = index.get_indexer(categorical_target)
249249
expected = index.get_indexer(target)

pandas/tests/indexing/test_categorical.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -778,9 +778,9 @@ def test_map_with_dict_or_series(self):
778778
pd.timedelta_range(start="1d", periods=3).array,
779779
],
780780
)
781-
def test_loc_with_non_string_categories(self, idx_values, ordered_fixture):
781+
def test_loc_with_non_string_categories(self, idx_values, ordered):
782782
# GH-17569
783-
cat_idx = CategoricalIndex(idx_values, ordered=ordered_fixture)
783+
cat_idx = CategoricalIndex(idx_values, ordered=ordered)
784784
df = DataFrame({"A": ["foo", "bar", "baz"]}, index=cat_idx)
785785
sl = slice(idx_values[0], idx_values[1])
786786

pandas/tests/reshape/test_pivot.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -1756,18 +1756,14 @@ def test_margins_casted_to_float(self, observed):
17561756
)
17571757
tm.assert_frame_equal(result, expected)
17581758

1759-
def test_pivot_with_categorical(self, observed, ordered_fixture):
1759+
def test_pivot_with_categorical(self, observed, ordered):
17601760
# gh-21370
17611761
idx = [np.nan, "low", "high", "low", np.nan]
17621762
col = [np.nan, "A", "B", np.nan, "A"]
17631763
df = pd.DataFrame(
17641764
{
1765-
"In": pd.Categorical(
1766-
idx, categories=["low", "high"], ordered=ordered_fixture
1767-
),
1768-
"Col": pd.Categorical(
1769-
col, categories=["A", "B"], ordered=ordered_fixture
1770-
),
1765+
"In": pd.Categorical(idx, categories=["low", "high"], ordered=ordered),
1766+
"Col": pd.Categorical(col, categories=["A", "B"], ordered=ordered),
17711767
"Val": range(1, 6),
17721768
}
17731769
)
@@ -1776,16 +1772,14 @@ def test_pivot_with_categorical(self, observed, ordered_fixture):
17761772
index="In", columns="Col", values="Val", observed=observed
17771773
)
17781774

1779-
expected_cols = pd.CategoricalIndex(
1780-
["A", "B"], ordered=ordered_fixture, name="Col"
1781-
)
1775+
expected_cols = pd.CategoricalIndex(["A", "B"], ordered=ordered, name="Col")
17821776

17831777
expected = pd.DataFrame(
17841778
data=[[2.0, np.nan], [np.nan, 3.0]], columns=expected_cols
17851779
)
17861780
expected.index = Index(
17871781
pd.Categorical(
1788-
["low", "high"], categories=["low", "high"], ordered=ordered_fixture
1782+
["low", "high"], categories=["low", "high"], ordered=ordered
17891783
),
17901784
name="In",
17911785
)

pandas/tests/series/methods/test_drop_duplicates.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ class TestSeriesDropDuplicates:
6969
"dtype",
7070
["int_", "uint", "float_", "unicode_", "timedelta64[h]", "datetime64[D]"],
7171
)
72-
def test_drop_duplicates_categorical_non_bool(self, dtype, ordered_fixture):
72+
def test_drop_duplicates_categorical_non_bool(self, dtype, ordered):
7373
cat_array = np.array([1, 2, 3, 4, 5], dtype=np.dtype(dtype))
7474

7575
# Test case 1
7676
input1 = np.array([1, 2, 3, 3], dtype=np.dtype(dtype))
77-
tc1 = Series(Categorical(input1, categories=cat_array, ordered=ordered_fixture))
77+
tc1 = Series(Categorical(input1, categories=cat_array, ordered=ordered))
7878
if dtype == "datetime64[D]":
7979
# pre-empty flaky xfail, tc1 values are seemingly-random
8080
if not (np.array(tc1) == input1).all():
@@ -103,7 +103,7 @@ def test_drop_duplicates_categorical_non_bool(self, dtype, ordered_fixture):
103103

104104
# Test case 2
105105
input2 = np.array([1, 2, 3, 5, 3, 2, 4], dtype=np.dtype(dtype))
106-
tc2 = Series(Categorical(input2, categories=cat_array, ordered=ordered_fixture))
106+
tc2 = Series(Categorical(input2, categories=cat_array, ordered=ordered))
107107
if dtype == "datetime64[D]":
108108
# pre-empty flaky xfail, tc2 values are seemingly-random
109109
if not (np.array(tc2) == input2).all():
@@ -130,12 +130,10 @@ def test_drop_duplicates_categorical_non_bool(self, dtype, ordered_fixture):
130130
sc.drop_duplicates(keep=False, inplace=True)
131131
tm.assert_series_equal(sc, tc2[~expected])
132132

133-
def test_drop_duplicates_categorical_bool(self, ordered_fixture):
133+
def test_drop_duplicates_categorical_bool(self, ordered):
134134
tc = Series(
135135
Categorical(
136-
[True, False, True, False],
137-
categories=[True, False],
138-
ordered=ordered_fixture,
136+
[True, False, True, False], categories=[True, False], ordered=ordered,
139137
)
140138
)
141139

0 commit comments

Comments
 (0)