From 032b6a01c6546f3b5553b92f5ec3d57364e4943b Mon Sep 17 00:00:00 2001 From: melissawm Date: Thu, 2 Jun 2022 14:06:48 -0300 Subject: [PATCH] DOC: Added docstrings to fixtures defined in array module --- pandas/tests/arrays/boolean/test_arithmetic.py | 3 +++ pandas/tests/arrays/boolean/test_comparison.py | 2 ++ pandas/tests/arrays/boolean/test_reduction.py | 1 + pandas/tests/arrays/categorical/conftest.py | 1 + .../tests/arrays/datetimes/test_reductions.py | 1 + pandas/tests/arrays/floating/conftest.py | 11 ++++++++++- pandas/tests/arrays/integer/conftest.py | 18 +++++++++++++++++- .../tests/arrays/integer/test_construction.py | 4 ++++ pandas/tests/arrays/masked/test_arithmetic.py | 5 +++++ .../tests/arrays/masked/test_arrow_compat.py | 8 ++++++++ pandas/tests/arrays/masked/test_function.py | 7 +++++++ pandas/tests/arrays/sparse/test_arithmetics.py | 5 ++++- pandas/tests/arrays/sparse/test_array.py | 3 +++ pandas/tests/arrays/string_/test_string.py | 2 ++ pandas/tests/arrays/test_array.py | 1 + pandas/tests/arrays/test_datetimelike.py | 13 +++++++++++++ pandas/tests/arrays/test_datetimes.py | 2 ++ 17 files changed, 84 insertions(+), 3 deletions(-) diff --git a/pandas/tests/arrays/boolean/test_arithmetic.py b/pandas/tests/arrays/boolean/test_arithmetic.py index 6e9b4b3f2b32e..197e83121567e 100644 --- a/pandas/tests/arrays/boolean/test_arithmetic.py +++ b/pandas/tests/arrays/boolean/test_arithmetic.py @@ -9,6 +9,7 @@ @pytest.fixture def data(): + """Fixture returning boolean array with valid and missing values.""" return pd.array( [True, False] * 4 + [np.nan] + [True, False] * 44 + [np.nan] + [True, False], dtype="boolean", @@ -17,11 +18,13 @@ def data(): @pytest.fixture def left_array(): + """Fixture returning boolean array with valid and missing values.""" return pd.array([True] * 3 + [False] * 3 + [None] * 3, dtype="boolean") @pytest.fixture def right_array(): + """Fixture returning boolean array with valid and missing values.""" return pd.array([True, False, None] * 3, dtype="boolean") diff --git a/pandas/tests/arrays/boolean/test_comparison.py b/pandas/tests/arrays/boolean/test_comparison.py index 2741d13ee599b..2eeb9da574b1e 100644 --- a/pandas/tests/arrays/boolean/test_comparison.py +++ b/pandas/tests/arrays/boolean/test_comparison.py @@ -9,6 +9,7 @@ @pytest.fixture def data(): + """Fixture returning boolean array with valid and missing data""" return pd.array( [True, False] * 4 + [np.nan] + [True, False] * 44 + [np.nan] + [True, False], dtype="boolean", @@ -17,6 +18,7 @@ def data(): @pytest.fixture def dtype(): + """Fixture returning BooleanDtype""" return pd.BooleanDtype() diff --git a/pandas/tests/arrays/boolean/test_reduction.py b/pandas/tests/arrays/boolean/test_reduction.py index a5c18a25f8e16..f3807df929f9a 100644 --- a/pandas/tests/arrays/boolean/test_reduction.py +++ b/pandas/tests/arrays/boolean/test_reduction.py @@ -6,6 +6,7 @@ @pytest.fixture def data(): + """Fixture returning boolean array, with valid and missing values.""" return pd.array( [True, False] * 4 + [np.nan] + [True, False] * 44 + [np.nan] + [True, False], dtype="boolean", diff --git a/pandas/tests/arrays/categorical/conftest.py b/pandas/tests/arrays/categorical/conftest.py index 99c601274de80..d5b49e3e5e8c8 100644 --- a/pandas/tests/arrays/categorical/conftest.py +++ b/pandas/tests/arrays/categorical/conftest.py @@ -11,4 +11,5 @@ def allow_fill(request): @pytest.fixture def factor(): + """Fixture returning a Categorical object""" return Categorical(["a", "b", "b", "a", "a", "c", "c", "c"], ordered=True) diff --git a/pandas/tests/arrays/datetimes/test_reductions.py b/pandas/tests/arrays/datetimes/test_reductions.py index 6e9c8f7b08a72..d0553f9608f25 100644 --- a/pandas/tests/arrays/datetimes/test_reductions.py +++ b/pandas/tests/arrays/datetimes/test_reductions.py @@ -12,6 +12,7 @@ class TestReductions: @pytest.fixture def arr1d(self, tz_naive_fixture): + """Fixture returning DatetimeArray with parametrized timezones""" tz = tz_naive_fixture dtype = DatetimeTZDtype(tz=tz) if tz is not None else np.dtype("M8[ns]") arr = DatetimeArray._from_sequence( diff --git a/pandas/tests/arrays/floating/conftest.py b/pandas/tests/arrays/floating/conftest.py index 9eab11516c295..5e971c66029d5 100644 --- a/pandas/tests/arrays/floating/conftest.py +++ b/pandas/tests/arrays/floating/conftest.py @@ -10,11 +10,13 @@ @pytest.fixture(params=[Float32Dtype, Float64Dtype]) def dtype(request): + """Parametrized fixture returning a float 'dtype'""" return request.param() @pytest.fixture def data(dtype): + """Fixture returning 'data' array according to parametrized float 'dtype'""" return pd.array( list(np.arange(0.1, 0.9, 0.1)) + [pd.NA] @@ -27,12 +29,19 @@ def data(dtype): @pytest.fixture def data_missing(dtype): + """ + Fixture returning array with missing data according to parametrized float + 'dtype'. + """ return pd.array([np.nan, 0.1], dtype=dtype) @pytest.fixture(params=["data", "data_missing"]) def all_data(request, data, data_missing): - """Parametrized fixture giving 'data' and 'data_missing'""" + """Parametrized fixture returning 'data' or 'data_missing' float arrays. + + Used to test dtype conversion with and without missing values. + """ if request.param == "data": return data elif request.param == "data_missing": diff --git a/pandas/tests/arrays/integer/conftest.py b/pandas/tests/arrays/integer/conftest.py index 080ca180337f0..f73400dfe689e 100644 --- a/pandas/tests/arrays/integer/conftest.py +++ b/pandas/tests/arrays/integer/conftest.py @@ -27,11 +27,18 @@ ] ) def dtype(request): + """Parametrized fixture returning integer 'dtype'""" return request.param() @pytest.fixture def data(dtype): + """ + Fixture returning 'data' array with valid and missing values according to + parametrized integer 'dtype'. + + Used to test dtype conversion with and without missing values. + """ return pd.array( list(range(8)) + [np.nan] + list(range(10, 98)) + [np.nan] + [99, 100], dtype=dtype, @@ -40,12 +47,21 @@ def data(dtype): @pytest.fixture def data_missing(dtype): + """ + Fixture returning array with exactly one NaN and one valid integer, + according to parametrized integer 'dtype'. + + Used to test dtype conversion with and without missing values. + """ return pd.array([np.nan, 1], dtype=dtype) @pytest.fixture(params=["data", "data_missing"]) def all_data(request, data, data_missing): - """Parametrized fixture giving 'data' and 'data_missing'""" + """Parametrized fixture returning 'data' or 'data_missing' integer arrays. + + Used to test dtype conversion with and without missing values. + """ if request.param == "data": return data elif request.param == "data_missing": diff --git a/pandas/tests/arrays/integer/test_construction.py b/pandas/tests/arrays/integer/test_construction.py index 0e415fcfc366a..43ef46ddfb581 100644 --- a/pandas/tests/arrays/integer/test_construction.py +++ b/pandas/tests/arrays/integer/test_construction.py @@ -14,6 +14,10 @@ @pytest.fixture(params=[pd.array, IntegerArray._from_sequence]) def constructor(request): + """Fixture returning parametrized IntegerArray from given sequence. + + Used to test dtype conversions. + """ return request.param diff --git a/pandas/tests/arrays/masked/test_arithmetic.py b/pandas/tests/arrays/masked/test_arithmetic.py index 93857ad441351..f4b571ca627b3 100644 --- a/pandas/tests/arrays/masked/test_arithmetic.py +++ b/pandas/tests/arrays/masked/test_arithmetic.py @@ -21,6 +21,11 @@ @pytest.fixture(params=zip(arrays, scalars), ids=[a.dtype.name for a in arrays]) def data(request): + """Fixture returning parametrized (array, scalar) tuple. + + Used to test equivalence of scalars, numpy arrays with array ops, and the + equivalence of DataFrame and Series ops. + """ return request.param diff --git a/pandas/tests/arrays/masked/test_arrow_compat.py b/pandas/tests/arrays/masked/test_arrow_compat.py index 4ccc54636eaee..6b0081321ef22 100644 --- a/pandas/tests/arrays/masked/test_arrow_compat.py +++ b/pandas/tests/arrays/masked/test_arrow_compat.py @@ -15,6 +15,10 @@ @pytest.fixture(params=arrays, ids=[a.dtype.name for a in arrays]) def data(request): + """ + Fixture returning parametrized array from given dtype, including integer, + float and boolean + """ return request.param @@ -101,6 +105,10 @@ def test_arrow_sliced(data): @pytest.fixture def np_dtype_to_arrays(any_real_numpy_dtype): + """ + Fixture returning actual and expected dtype, pandas and numpy arrays and + mask from a given numpy dtype + """ np_dtype = np.dtype(any_real_numpy_dtype) pa_type = pa.from_numpy_dtype(np_dtype) diff --git a/pandas/tests/arrays/masked/test_function.py b/pandas/tests/arrays/masked/test_function.py index bf310c7aa455e..9a86ef835e5ef 100644 --- a/pandas/tests/arrays/masked/test_function.py +++ b/pandas/tests/arrays/masked/test_function.py @@ -14,11 +14,18 @@ @pytest.fixture(params=arrays, ids=[a.dtype.name for a in arrays]) def data(request): + """ + Fixture returning parametrized 'data' array with different integer and + floating point types + """ return request.param @pytest.fixture() def numpy_dtype(data): + """ + Fixture returning numpy dtype from 'data' input array. + """ # For integer dtype, the numpy conversion must be done to float if is_integer_dtype(data): numpy_dtype = float diff --git a/pandas/tests/arrays/sparse/test_arithmetics.py b/pandas/tests/arrays/sparse/test_arithmetics.py index 35c183db7ad9b..9593152735ed6 100644 --- a/pandas/tests/arrays/sparse/test_arithmetics.py +++ b/pandas/tests/arrays/sparse/test_arithmetics.py @@ -22,7 +22,10 @@ def kind(request): @pytest.fixture(params=[True, False]) def mix(request): - # whether to operate op(sparse, dense) instead of op(sparse, sparse) + """ + Fixture returning True or False, determining whether to operate + op(sparse, dense) instead of op(sparse, sparse) + """ return request.param diff --git a/pandas/tests/arrays/sparse/test_array.py b/pandas/tests/arrays/sparse/test_array.py index d728cf4c8a9a2..492427b2be213 100644 --- a/pandas/tests/arrays/sparse/test_array.py +++ b/pandas/tests/arrays/sparse/test_array.py @@ -18,16 +18,19 @@ @pytest.fixture def arr_data(): + """Fixture returning numpy array with valid and missing entries""" return np.array([np.nan, np.nan, 1, 2, 3, np.nan, 4, 5, np.nan, 6]) @pytest.fixture def arr(arr_data): + """Fixture returning SparseArray from 'arr_data'""" return SparseArray(arr_data) @pytest.fixture def zarr(): + """Fixture returning SparseArray with integer entries and 'fill_value=0'""" return SparseArray([0, 0, 1, 2, 3, 0, 4, 5, 0, 6], fill_value=0) diff --git a/pandas/tests/arrays/string_/test_string.py b/pandas/tests/arrays/string_/test_string.py index 5442f96ab2d22..e9d48eb937b36 100644 --- a/pandas/tests/arrays/string_/test_string.py +++ b/pandas/tests/arrays/string_/test_string.py @@ -18,11 +18,13 @@ @pytest.fixture def dtype(string_storage): + """Fixture giving StringDtype from parametrized 'string_storage'""" return pd.StringDtype(storage=string_storage) @pytest.fixture def cls(dtype): + """Fixture giving array type from parametrized 'dtype'""" return dtype.construct_array_type() diff --git a/pandas/tests/arrays/test_array.py b/pandas/tests/arrays/test_array.py index bf7dca9e1d5a0..f7f015cbe4a23 100644 --- a/pandas/tests/arrays/test_array.py +++ b/pandas/tests/arrays/test_array.py @@ -379,6 +379,7 @@ def test_array_unboxes(index_or_series): @pytest.fixture def registry_without_decimal(): + """Fixture yielding 'registry' with no DecimalDtype entries""" idx = registry.dtypes.index(DecimalDtype) registry.dtypes.pop(idx) yield diff --git a/pandas/tests/arrays/test_datetimelike.py b/pandas/tests/arrays/test_datetimelike.py index 56dc3363a7f52..10881495c27b3 100644 --- a/pandas/tests/arrays/test_datetimelike.py +++ b/pandas/tests/arrays/test_datetimelike.py @@ -33,6 +33,7 @@ # TODO: more freq variants @pytest.fixture(params=["D", "B", "W", "M", "Q", "Y"]) def freqstr(request): + """Fixture returning parametrized frequency in string format.""" return request.param @@ -81,6 +82,7 @@ class SharedTests: @pytest.fixture def arr1d(self): + """Fixture returning DatetimeArray with daily frequency.""" data = np.arange(10, dtype="i8") * 24 * 3600 * 10**9 arr = self.array_cls(data, freq="D") return arr @@ -635,6 +637,10 @@ class TestDatetimeArray(SharedTests): @pytest.fixture def arr1d(self, tz_naive_fixture, freqstr): + """ + Fixture returning DatetimeArray with parametrized frequency and + timezones + """ tz = tz_naive_fixture dti = pd.date_range("2016-01-01 01:01:00", periods=5, freq=freqstr, tz=tz) dta = dti._data @@ -1068,6 +1074,9 @@ class TestPeriodArray(SharedTests): @pytest.fixture def arr1d(self, period_index): + """ + Fixture returning DatetimeArray from parametrized PeriodIndex objects + """ return period_index._data def test_from_pi(self, arr1d): @@ -1389,6 +1398,10 @@ def test_from_pandas_array(dtype): ] ) def array_likes(request): + """ + Fixture giving a numpy array and a parametrized 'data' object, which can + be a memoryview, array, dask or xarray object created from the numpy array. + """ # GH#24539 recognize e.g xarray, dask, ... arr = np.array([1, 2, 3], dtype=np.int64) diff --git a/pandas/tests/arrays/test_datetimes.py b/pandas/tests/arrays/test_datetimes.py index d00eab8c10e1c..14d33ee52aae2 100644 --- a/pandas/tests/arrays/test_datetimes.py +++ b/pandas/tests/arrays/test_datetimes.py @@ -14,10 +14,12 @@ class TestNonNano: @pytest.fixture(params=["s", "ms", "us"]) def unit(self, request): + """Fixture returning parametrized time units""" return request.param @pytest.fixture def reso(self, unit): + """Fixture returning datetime resolution for a given time unit""" # TODO: avoid hard-coding return {"s": 7, "ms": 8, "us": 9}[unit]