Skip to content

Commit a7a4c7d

Browse files
topper-123jreback
authored andcommitted
CLN: collect ordered fixtures in pandas.conftest (#26082)
1 parent aad7739 commit a7a4c7d

File tree

5 files changed

+33
-37
lines changed

5 files changed

+33
-37
lines changed

pandas/conftest.py

+6
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ def observed(request):
126126
return request.param
127127

128128

129+
@pytest.fixture(params=[True, False, None])
130+
def ordered_fixture(request):
131+
"""Boolean 'ordered' parameter for Categorical."""
132+
return request.param
133+
134+
129135
_all_arithmetic_operators = ['__add__', '__radd__',
130136
'__sub__', '__rsub__',
131137
'__mul__', '__rmul__',

pandas/tests/arrays/categorical/conftest.py

-6
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,3 @@
55
def allow_fill(request):
66
"""Boolean 'allow_fill' parameter for Categorical.take"""
77
return request.param
8-
9-
10-
@pytest.fixture(params=[True, False])
11-
def ordered(request):
12-
"""Boolean 'ordered' parameter for Categorical."""
13-
return request.param

pandas/tests/arrays/categorical/test_algos.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,20 @@ def test_take_empty(self, allow_fill):
9696
with pytest.raises(IndexError):
9797
cat.take([0], allow_fill=allow_fill)
9898

99-
def test_positional_take(self, ordered):
99+
def test_positional_take(self, ordered_fixture):
100100
cat = pd.Categorical(['a', 'a', 'b', 'b'], categories=['b', 'a'],
101-
ordered=ordered)
101+
ordered=ordered_fixture)
102102
result = cat.take([0, 1, 2], allow_fill=False)
103103
expected = pd.Categorical(['a', 'a', 'b'], categories=cat.categories,
104-
ordered=ordered)
104+
ordered=ordered_fixture)
105105
tm.assert_categorical_equal(result, expected)
106106

107-
def test_positional_take_unobserved(self, ordered):
107+
def test_positional_take_unobserved(self, ordered_fixture):
108108
cat = pd.Categorical(['a', 'b'], categories=['a', 'b', 'c'],
109-
ordered=ordered)
109+
ordered=ordered_fixture)
110110
result = cat.take([1, 0], allow_fill=False)
111111
expected = pd.Categorical(['b', 'a'], categories=cat.categories,
112-
ordered=ordered)
112+
ordered=ordered_fixture)
113113
tm.assert_categorical_equal(result, expected)
114114

115115
def test_take_allow_fill(self):

pandas/tests/dtypes/test_dtypes.py

+14-18
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
import pandas.util.testing as tm
2121

2222

23-
@pytest.fixture(params=[True, False, None])
24-
def ordered(request):
25-
return request.param
26-
27-
2823
class Base(object):
2924

3025
def setup_method(self, method):
@@ -659,10 +654,10 @@ class TestCategoricalDtypeParametrized(object):
659654
['a', 'b', 10, 2, 1.3, True],
660655
[True, False],
661656
pd.date_range('2017', periods=4)])
662-
def test_basic(self, categories, ordered):
663-
c1 = CategoricalDtype(categories, ordered=ordered)
657+
def test_basic(self, categories, ordered_fixture):
658+
c1 = CategoricalDtype(categories, ordered=ordered_fixture)
664659
tm.assert_index_equal(c1.categories, pd.Index(categories))
665-
assert c1.ordered is ordered
660+
assert c1.ordered is ordered_fixture
666661

667662
def test_order_matters(self):
668663
categories = ['a', 'b']
@@ -683,7 +678,7 @@ def test_categories(self):
683678
tm.assert_index_equal(result.categories, pd.Index(['a', 'b', 'c']))
684679
assert result.ordered is None
685680

686-
def test_equal_but_different(self, ordered):
681+
def test_equal_but_different(self, ordered_fixture):
687682
c1 = CategoricalDtype([1, 2, 3])
688683
c2 = CategoricalDtype([1., 2., 3.])
689684
assert c1 is not c2
@@ -748,8 +743,9 @@ def test_categorical_equality(self, ordered1, ordered2):
748743

749744
@pytest.mark.parametrize('categories', [list('abc'), None])
750745
@pytest.mark.parametrize('other', ['category', 'not a category'])
751-
def test_categorical_equality_strings(self, categories, ordered, other):
752-
c1 = CategoricalDtype(categories, ordered)
746+
def test_categorical_equality_strings(self, categories, ordered_fixture,
747+
other):
748+
c1 = CategoricalDtype(categories, ordered_fixture)
753749
result = c1 == other
754750
expected = other == 'category'
755751
assert result is expected
@@ -793,12 +789,12 @@ def test_from_categorical_dtype_both(self):
793789
c1, categories=[1, 2], ordered=False)
794790
assert result == CategoricalDtype([1, 2], ordered=False)
795791

796-
def test_str_vs_repr(self, ordered):
797-
c1 = CategoricalDtype(['a', 'b'], ordered=ordered)
792+
def test_str_vs_repr(self, ordered_fixture):
793+
c1 = CategoricalDtype(['a', 'b'], ordered=ordered_fixture)
798794
assert str(c1) == 'category'
799795
# Py2 will have unicode prefixes
800796
pat = r"CategoricalDtype\(categories=\[.*\], ordered={ordered}\)"
801-
assert re.match(pat.format(ordered=ordered), repr(c1))
797+
assert re.match(pat.format(ordered=ordered_fixture), repr(c1))
802798

803799
def test_categorical_categories(self):
804800
# GH17884
@@ -810,8 +806,8 @@ def test_categorical_categories(self):
810806
@pytest.mark.parametrize('new_categories', [
811807
list('abc'), list('cba'), list('wxyz'), None])
812808
@pytest.mark.parametrize('new_ordered', [True, False, None])
813-
def test_update_dtype(self, ordered, new_categories, new_ordered):
814-
dtype = CategoricalDtype(list('abc'), ordered)
809+
def test_update_dtype(self, ordered_fixture, new_categories, new_ordered):
810+
dtype = CategoricalDtype(list('abc'), ordered_fixture)
815811
new_dtype = CategoricalDtype(new_categories, new_ordered)
816812

817813
expected_categories = new_dtype.categories
@@ -826,8 +822,8 @@ def test_update_dtype(self, ordered, new_categories, new_ordered):
826822
tm.assert_index_equal(result.categories, expected_categories)
827823
assert result.ordered is expected_ordered
828824

829-
def test_update_dtype_string(self, ordered):
830-
dtype = CategoricalDtype(list('abc'), ordered)
825+
def test_update_dtype_string(self, ordered_fixture):
826+
dtype = CategoricalDtype(list('abc'), ordered_fixture)
831827
expected_categories = dtype.categories
832828
expected_ordered = dtype.ordered
833829
result = dtype.update_dtype('category')

pandas/tests/series/test_analytics.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1406,14 +1406,14 @@ def test_value_counts_with_nan(self):
14061406
pytest.param("datetime64[D]",
14071407
marks=pytest.mark.xfail(reason="GH#7996"))]
14081408
)
1409-
@pytest.mark.parametrize("is_ordered", [True, False])
1410-
def test_drop_duplicates_categorical_non_bool(self, dtype, is_ordered):
1409+
def test_drop_duplicates_categorical_non_bool(self, dtype,
1410+
ordered_fixture):
14111411
cat_array = np.array([1, 2, 3, 4, 5], dtype=np.dtype(dtype))
14121412

14131413
# Test case 1
14141414
input1 = np.array([1, 2, 3, 3], dtype=np.dtype(dtype))
14151415
tc1 = Series(Categorical(input1, categories=cat_array,
1416-
ordered=is_ordered))
1416+
ordered=ordered_fixture))
14171417

14181418
expected = Series([False, False, False, True])
14191419
tm.assert_series_equal(tc1.duplicated(), expected)
@@ -1440,7 +1440,7 @@ def test_drop_duplicates_categorical_non_bool(self, dtype, is_ordered):
14401440
# Test case 2
14411441
input2 = np.array([1, 2, 3, 5, 3, 2, 4], dtype=np.dtype(dtype))
14421442
tc2 = Series(Categorical(
1443-
input2, categories=cat_array, ordered=is_ordered)
1443+
input2, categories=cat_array, ordered=ordered_fixture)
14441444
)
14451445

14461446
expected = Series([False, False, False, False, True, True, False])
@@ -1465,10 +1465,10 @@ def test_drop_duplicates_categorical_non_bool(self, dtype, is_ordered):
14651465
sc.drop_duplicates(keep=False, inplace=True)
14661466
tm.assert_series_equal(sc, tc2[~expected])
14671467

1468-
@pytest.mark.parametrize("is_ordered", [True, False])
1469-
def test_drop_duplicates_categorical_bool(self, is_ordered):
1468+
def test_drop_duplicates_categorical_bool(self, ordered_fixture):
14701469
tc = Series(Categorical([True, False, True, False],
1471-
categories=[True, False], ordered=is_ordered))
1470+
categories=[True, False],
1471+
ordered=ordered_fixture))
14721472

14731473
expected = Series([False, False, True, True])
14741474
tm.assert_series_equal(tc.duplicated(), expected)

0 commit comments

Comments
 (0)