Skip to content

DOC: Added docstrings to fixtures defined in array module #47211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pandas/tests/arrays/boolean/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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")


Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/arrays/boolean/test_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -17,6 +18,7 @@ def data():

@pytest.fixture
def dtype():
"""Fixture returning BooleanDtype"""
return pd.BooleanDtype()


Expand Down
1 change: 1 addition & 0 deletions pandas/tests/arrays/boolean/test_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/arrays/categorical/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions pandas/tests/arrays/datetimes/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 10 additions & 1 deletion pandas/tests/arrays/floating/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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":
Expand Down
18 changes: 17 additions & 1 deletion pandas/tests/arrays/integer/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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":
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/arrays/integer/test_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/arrays/masked/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/arrays/masked/test_arrow_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)

Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/arrays/masked/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion pandas/tests/arrays/sparse/test_arithmetics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/arrays/sparse/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/arrays/string_/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
1 change: 1 addition & 0 deletions pandas/tests/arrays/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/arrays/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/arrays/test_datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down