From d87d5cfe2b7b7e76a2add3d47b3e592b26672c73 Mon Sep 17 00:00:00 2001 From: jschendel Date: Tue, 31 Mar 2020 11:47:27 -0600 Subject: [PATCH] CLN: Rename ordered_fixture --> ordered --- pandas/conftest.py | 2 +- pandas/tests/arrays/categorical/test_algos.py | 14 +++++----- .../arrays/categorical/test_analytics.py | 4 +-- pandas/tests/dtypes/test_dtypes.py | 26 +++++++++---------- pandas/tests/groupby/test_categorical.py | 4 +-- pandas/tests/indexes/categorical/test_map.py | 6 ++--- .../tests/indexes/interval/test_indexing.py | 4 +-- pandas/tests/indexing/test_categorical.py | 4 +-- pandas/tests/reshape/test_pivot.py | 16 ++++-------- .../series/methods/test_drop_duplicates.py | 12 ++++----- 10 files changed, 41 insertions(+), 51 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 0b14c12f2356f..e1088dae3925a 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -182,7 +182,7 @@ def observed(request): @pytest.fixture(params=[True, False, None]) -def ordered_fixture(request): +def ordered(request): """ Boolean 'ordered' parameter for Categorical. """ diff --git a/pandas/tests/arrays/categorical/test_algos.py b/pandas/tests/arrays/categorical/test_algos.py index 835aa87a7c21b..10c454f7c479a 100644 --- a/pandas/tests/arrays/categorical/test_algos.py +++ b/pandas/tests/arrays/categorical/test_algos.py @@ -140,23 +140,21 @@ def test_take_empty(self, allow_fill): with pytest.raises(IndexError, match=msg): cat.take([0], allow_fill=allow_fill) - def test_positional_take(self, ordered_fixture): + def test_positional_take(self, ordered): cat = pd.Categorical( - ["a", "a", "b", "b"], categories=["b", "a"], ordered=ordered_fixture + ["a", "a", "b", "b"], categories=["b", "a"], ordered=ordered ) result = cat.take([0, 1, 2], allow_fill=False) expected = pd.Categorical( - ["a", "a", "b"], categories=cat.categories, ordered=ordered_fixture + ["a", "a", "b"], categories=cat.categories, ordered=ordered ) tm.assert_categorical_equal(result, expected) - def test_positional_take_unobserved(self, ordered_fixture): - cat = pd.Categorical( - ["a", "b"], categories=["a", "b", "c"], ordered=ordered_fixture - ) + def test_positional_take_unobserved(self, ordered): + cat = pd.Categorical(["a", "b"], categories=["a", "b", "c"], ordered=ordered) result = cat.take([1, 0], allow_fill=False) expected = pd.Categorical( - ["b", "a"], categories=cat.categories, ordered=ordered_fixture + ["b", "a"], categories=cat.categories, ordered=ordered ) tm.assert_categorical_equal(result, expected) diff --git a/pandas/tests/arrays/categorical/test_analytics.py b/pandas/tests/arrays/categorical/test_analytics.py index 0ff7d3e59abb3..c470f677b5386 100644 --- a/pandas/tests/arrays/categorical/test_analytics.py +++ b/pandas/tests/arrays/categorical/test_analytics.py @@ -114,14 +114,14 @@ def test_mode(self, values, categories, exp_mode): exp = Categorical(exp_mode, categories=categories, ordered=True) tm.assert_categorical_equal(res, exp) - def test_searchsorted(self, ordered_fixture): + def test_searchsorted(self, ordered): # https://github.com/pandas-dev/pandas/issues/8420 # https://github.com/pandas-dev/pandas/issues/14522 cat = Categorical( ["cheese", "milk", "apple", "bread", "bread"], categories=["cheese", "milk", "apple", "bread"], - ordered=ordered_fixture, + ordered=ordered, ) ser = Series(cat) diff --git a/pandas/tests/dtypes/test_dtypes.py b/pandas/tests/dtypes/test_dtypes.py index 658d27160e3e1..d0831ea514a64 100644 --- a/pandas/tests/dtypes/test_dtypes.py +++ b/pandas/tests/dtypes/test_dtypes.py @@ -730,10 +730,10 @@ class TestCategoricalDtypeParametrized: pd.date_range("2017", periods=4), ], ) - def test_basic(self, categories, ordered_fixture): - c1 = CategoricalDtype(categories, ordered=ordered_fixture) + def test_basic(self, categories, ordered): + c1 = CategoricalDtype(categories, ordered=ordered) tm.assert_index_equal(c1.categories, pd.Index(categories)) - assert c1.ordered is ordered_fixture + assert c1.ordered is ordered def test_order_matters(self): categories = ["a", "b"] @@ -754,7 +754,7 @@ def test_categories(self): tm.assert_index_equal(result.categories, pd.Index(["a", "b", "c"])) assert result.ordered is False - def test_equal_but_different(self, ordered_fixture): + def test_equal_but_different(self, ordered): c1 = CategoricalDtype([1, 2, 3]) c2 = CategoricalDtype([1.0, 2.0, 3.0]) assert c1 is not c2 @@ -818,8 +818,8 @@ def test_categorical_equality(self, ordered1, ordered2): @pytest.mark.parametrize("categories", [list("abc"), None]) @pytest.mark.parametrize("other", ["category", "not a category"]) - def test_categorical_equality_strings(self, categories, ordered_fixture, other): - c1 = CategoricalDtype(categories, ordered_fixture) + def test_categorical_equality_strings(self, categories, ordered, other): + c1 = CategoricalDtype(categories, ordered) result = c1 == other expected = other == "category" assert result is expected @@ -862,12 +862,12 @@ def test_from_categorical_dtype_both(self): ) assert result == CategoricalDtype([1, 2], ordered=False) - def test_str_vs_repr(self, ordered_fixture): - c1 = CategoricalDtype(["a", "b"], ordered=ordered_fixture) + def test_str_vs_repr(self, ordered): + c1 = CategoricalDtype(["a", "b"], ordered=ordered) assert str(c1) == "category" # Py2 will have unicode prefixes pat = r"CategoricalDtype\(categories=\[.*\], ordered={ordered}\)" - assert re.match(pat.format(ordered=ordered_fixture), repr(c1)) + assert re.match(pat.format(ordered=ordered), repr(c1)) def test_categorical_categories(self): # GH17884 @@ -880,9 +880,9 @@ def test_categorical_categories(self): "new_categories", [list("abc"), list("cba"), list("wxyz"), None] ) @pytest.mark.parametrize("new_ordered", [True, False, None]) - def test_update_dtype(self, ordered_fixture, new_categories, new_ordered): + def test_update_dtype(self, ordered, new_categories, new_ordered): original_categories = list("abc") - dtype = CategoricalDtype(original_categories, ordered_fixture) + dtype = CategoricalDtype(original_categories, ordered) new_dtype = CategoricalDtype(new_categories, new_ordered) result = dtype.update_dtype(new_dtype) @@ -892,8 +892,8 @@ def test_update_dtype(self, ordered_fixture, new_categories, new_ordered): tm.assert_index_equal(result.categories, expected_categories) assert result.ordered is expected_ordered - def test_update_dtype_string(self, ordered_fixture): - dtype = CategoricalDtype(list("abc"), ordered_fixture) + def test_update_dtype_string(self, ordered): + dtype = CategoricalDtype(list("abc"), ordered) expected_categories = dtype.categories expected_ordered = dtype.ordered result = dtype.update_dtype("category") diff --git a/pandas/tests/groupby/test_categorical.py b/pandas/tests/groupby/test_categorical.py index 9ea5252b91e13..e570ea201cc3a 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -1226,10 +1226,10 @@ def test_groupby_categorical_axis_1(code): tm.assert_frame_equal(result, expected) -def test_groupby_cat_preserves_structure(observed, ordered_fixture): +def test_groupby_cat_preserves_structure(observed, ordered): # GH 28787 df = DataFrame( - {"Name": Categorical(["Bob", "Greg"], ordered=ordered_fixture), "Item": [1, 2]}, + {"Name": Categorical(["Bob", "Greg"], ordered=ordered), "Item": [1, 2]}, columns=["Name", "Item"], ) expected = df.copy() diff --git a/pandas/tests/indexes/categorical/test_map.py b/pandas/tests/indexes/categorical/test_map.py index 943359a72e971..6cef555275444 100644 --- a/pandas/tests/indexes/categorical/test_map.py +++ b/pandas/tests/indexes/categorical/test_map.py @@ -15,12 +15,12 @@ class TestMap: ], ids=["string", "interval"], ) - def test_map_str(self, data, categories, ordered_fixture): + def test_map_str(self, data, categories, ordered): # GH 31202 - override base class since we want to maintain categorical/ordered - index = CategoricalIndex(data, categories=categories, ordered=ordered_fixture) + index = CategoricalIndex(data, categories=categories, ordered=ordered) result = index.map(str) expected = CategoricalIndex( - map(str, data), categories=map(str, categories), ordered=ordered_fixture + map(str, data), categories=map(str, categories), ordered=ordered ) tm.assert_index_equal(result, expected) diff --git a/pandas/tests/indexes/interval/test_indexing.py b/pandas/tests/indexes/interval/test_indexing.py index 0e5721bfd83fd..0e08a3f41b666 100644 --- a/pandas/tests/indexes/interval/test_indexing.py +++ b/pandas/tests/indexes/interval/test_indexing.py @@ -240,10 +240,10 @@ def test_get_indexer_length_one_interval(self, size, closed): ["foo", "foo", "bar", "baz"], ], ) - def test_get_indexer_categorical(self, target, ordered_fixture): + def test_get_indexer_categorical(self, target, ordered): # GH 30063: categorical and non-categorical results should be consistent index = IntervalIndex.from_tuples([(0, 1), (1, 2), (3, 4)]) - categorical_target = CategoricalIndex(target, ordered=ordered_fixture) + categorical_target = CategoricalIndex(target, ordered=ordered) result = index.get_indexer(categorical_target) expected = index.get_indexer(target) diff --git a/pandas/tests/indexing/test_categorical.py b/pandas/tests/indexing/test_categorical.py index 8a8ac584c16c2..dcd2de3845cbc 100644 --- a/pandas/tests/indexing/test_categorical.py +++ b/pandas/tests/indexing/test_categorical.py @@ -778,9 +778,9 @@ def test_map_with_dict_or_series(self): pd.timedelta_range(start="1d", periods=3).array, ], ) - def test_loc_with_non_string_categories(self, idx_values, ordered_fixture): + def test_loc_with_non_string_categories(self, idx_values, ordered): # GH-17569 - cat_idx = CategoricalIndex(idx_values, ordered=ordered_fixture) + cat_idx = CategoricalIndex(idx_values, ordered=ordered) df = DataFrame({"A": ["foo", "bar", "baz"]}, index=cat_idx) sl = slice(idx_values[0], idx_values[1]) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index cdb1a73abc431..e49b80e476003 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -1756,18 +1756,14 @@ def test_margins_casted_to_float(self, observed): ) tm.assert_frame_equal(result, expected) - def test_pivot_with_categorical(self, observed, ordered_fixture): + def test_pivot_with_categorical(self, observed, ordered): # gh-21370 idx = [np.nan, "low", "high", "low", np.nan] col = [np.nan, "A", "B", np.nan, "A"] df = pd.DataFrame( { - "In": pd.Categorical( - idx, categories=["low", "high"], ordered=ordered_fixture - ), - "Col": pd.Categorical( - col, categories=["A", "B"], ordered=ordered_fixture - ), + "In": pd.Categorical(idx, categories=["low", "high"], ordered=ordered), + "Col": pd.Categorical(col, categories=["A", "B"], ordered=ordered), "Val": range(1, 6), } ) @@ -1776,16 +1772,14 @@ def test_pivot_with_categorical(self, observed, ordered_fixture): index="In", columns="Col", values="Val", observed=observed ) - expected_cols = pd.CategoricalIndex( - ["A", "B"], ordered=ordered_fixture, name="Col" - ) + expected_cols = pd.CategoricalIndex(["A", "B"], ordered=ordered, name="Col") expected = pd.DataFrame( data=[[2.0, np.nan], [np.nan, 3.0]], columns=expected_cols ) expected.index = Index( pd.Categorical( - ["low", "high"], categories=["low", "high"], ordered=ordered_fixture + ["low", "high"], categories=["low", "high"], ordered=ordered ), name="In", ) diff --git a/pandas/tests/series/methods/test_drop_duplicates.py b/pandas/tests/series/methods/test_drop_duplicates.py index 54f32f979232d..a4532ebb3d8c5 100644 --- a/pandas/tests/series/methods/test_drop_duplicates.py +++ b/pandas/tests/series/methods/test_drop_duplicates.py @@ -69,12 +69,12 @@ class TestSeriesDropDuplicates: "dtype", ["int_", "uint", "float_", "unicode_", "timedelta64[h]", "datetime64[D]"], ) - def test_drop_duplicates_categorical_non_bool(self, dtype, ordered_fixture): + def test_drop_duplicates_categorical_non_bool(self, dtype, ordered): cat_array = np.array([1, 2, 3, 4, 5], dtype=np.dtype(dtype)) # Test case 1 input1 = np.array([1, 2, 3, 3], dtype=np.dtype(dtype)) - tc1 = Series(Categorical(input1, categories=cat_array, ordered=ordered_fixture)) + tc1 = Series(Categorical(input1, categories=cat_array, ordered=ordered)) if dtype == "datetime64[D]": # pre-empty flaky xfail, tc1 values are seemingly-random if not (np.array(tc1) == input1).all(): @@ -103,7 +103,7 @@ def test_drop_duplicates_categorical_non_bool(self, dtype, ordered_fixture): # Test case 2 input2 = np.array([1, 2, 3, 5, 3, 2, 4], dtype=np.dtype(dtype)) - tc2 = Series(Categorical(input2, categories=cat_array, ordered=ordered_fixture)) + tc2 = Series(Categorical(input2, categories=cat_array, ordered=ordered)) if dtype == "datetime64[D]": # pre-empty flaky xfail, tc2 values are seemingly-random if not (np.array(tc2) == input2).all(): @@ -130,12 +130,10 @@ def test_drop_duplicates_categorical_non_bool(self, dtype, ordered_fixture): sc.drop_duplicates(keep=False, inplace=True) tm.assert_series_equal(sc, tc2[~expected]) - def test_drop_duplicates_categorical_bool(self, ordered_fixture): + def test_drop_duplicates_categorical_bool(self, ordered): tc = Series( Categorical( - [True, False, True, False], - categories=[True, False], - ordered=ordered_fixture, + [True, False, True, False], categories=[True, False], ordered=ordered, ) )