From a8f775e1fe4fbde0a64430270fab31d9c480715e Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 14 Dec 2021 18:40:38 -0800 Subject: [PATCH] CLN/TST: remove used-once fixtures --- pandas/_testing/__init__.py | 11 ++++++++ pandas/conftest.py | 31 +--------------------- pandas/tests/base/test_misc.py | 6 +++-- pandas/tests/frame/methods/test_replace.py | 3 ++- pandas/tests/io/json/test_pandas.py | 6 +++-- 5 files changed, 22 insertions(+), 35 deletions(-) diff --git a/pandas/_testing/__init__.py b/pandas/_testing/__init__.py index 16094bd88d66f..0aad8bd95e1df 100644 --- a/pandas/_testing/__init__.py +++ b/pandas/_testing/__init__.py @@ -161,6 +161,17 @@ + BYTES_DTYPES ) +NARROW_NP_DTYPES = [ + np.float16, + np.float32, + np.int8, + np.int16, + np.int32, + np.uint8, + np.uint16, + np.uint32, +] + NULL_OBJECTS = [None, np.nan, pd.NaT, float("nan"), pd.NA, Decimal("NaN")] NP_NAT_OBJECTS = [ cls("NaT", unit) diff --git a/pandas/conftest.py b/pandas/conftest.py index eb9a952250f36..7ea0df550f1f4 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -599,11 +599,6 @@ def index_with_missing(request): # ---------------------------------------------------------------- # Series' # ---------------------------------------------------------------- -@pytest.fixture -def empty_series(): - return Series([], index=[], dtype=np.float64) - - @pytest.fixture def string_series(): """ @@ -672,31 +667,12 @@ def series_with_multilevel_index(): return ser -_narrow_dtypes = [ - np.float16, - np.float32, - np.int8, - np.int16, - np.int32, - np.uint8, - np.uint16, - np.uint32, -] _narrow_series = { f"{dtype.__name__}-series": tm.makeFloatSeries(name="a").astype(dtype) - for dtype in _narrow_dtypes + for dtype in tm.NARROW_NP_DTYPES } -@pytest.fixture(params=_narrow_series.keys()) -def narrow_series(request): - """ - Fixture for Series with low precision data types - """ - # copy to avoid mutation, e.g. setting .name - return _narrow_series[request.param].copy() - - _index_or_series_objs = {**indices_dict, **_series, **_narrow_series} @@ -712,11 +688,6 @@ def index_or_series_obj(request): # ---------------------------------------------------------------- # DataFrames # ---------------------------------------------------------------- -@pytest.fixture -def empty_frame(): - return DataFrame() - - @pytest.fixture def int_frame(): """ diff --git a/pandas/tests/base/test_misc.py b/pandas/tests/base/test_misc.py index aaaec46399fa8..8372ec92ec26e 100644 --- a/pandas/tests/base/test_misc.py +++ b/pandas/tests/base/test_misc.py @@ -18,6 +18,7 @@ Index, Series, ) +import pandas._testing as tm @pytest.mark.parametrize( @@ -109,8 +110,9 @@ def test_memory_usage_components_series(series_with_simple_index): assert total_usage == non_index_usage + index_usage -def test_memory_usage_components_narrow_series(narrow_series): - series = narrow_series +@pytest.mark.parametrize("dtype", tm.NARROW_NP_DTYPES) +def test_memory_usage_components_narrow_series(dtype): + series = tm.makeFloatSeries(name="a").astype(dtype) total_usage = series.memory_usage(index=True) non_index_usage = series.memory_usage(index=False) index_usage = series.index.memory_usage() diff --git a/pandas/tests/frame/methods/test_replace.py b/pandas/tests/frame/methods/test_replace.py index d6ecdcd155295..28e28490c73b9 100644 --- a/pandas/tests/frame/methods/test_replace.py +++ b/pandas/tests/frame/methods/test_replace.py @@ -1384,8 +1384,9 @@ def test_replace_value_category_type(self): @pytest.mark.xfail( reason="category dtype gets changed to object type after replace, see #35268", + raises=AssertionError, ) - def test_replace_dict_category_type(self, input_category_df, expected_category_df): + def test_replace_dict_category_type(self): """ Test to ensure category dtypes are maintained after replace with dict values diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index 75a92ee1b9a45..522031f466be3 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -244,7 +244,8 @@ def test_roundtrip_categorical(self, request, orient, convert_axes, numpy): @pytest.mark.parametrize("convert_axes", [True, False]) @pytest.mark.parametrize("numpy", [True, False]) - def test_roundtrip_empty(self, orient, convert_axes, numpy, empty_frame): + def test_roundtrip_empty(self, orient, convert_axes, numpy): + empty_frame = DataFrame() data = empty_frame.to_json(orient=orient) result = read_json(data, orient=orient, convert_axes=convert_axes, numpy=numpy) expected = empty_frame.copy() @@ -673,7 +674,8 @@ def test_series_roundtrip_object(self, orient, numpy, dtype, object_series): tm.assert_series_equal(result, expected) @pytest.mark.parametrize("numpy", [True, False]) - def test_series_roundtrip_empty(self, orient, numpy, empty_series): + def test_series_roundtrip_empty(self, orient, numpy): + empty_series = Series([], index=[], dtype=np.float64) data = empty_series.to_json(orient=orient) result = read_json(data, typ="series", orient=orient, numpy=numpy)