Skip to content

Commit 89be1f0

Browse files
authored
DOC: Added docstrings to fixtures defined in array module (#47211)
1 parent 72e84c4 commit 89be1f0

17 files changed

+84
-3
lines changed

pandas/tests/arrays/boolean/test_arithmetic.py

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
@pytest.fixture
1111
def data():
12+
"""Fixture returning boolean array with valid and missing values."""
1213
return pd.array(
1314
[True, False] * 4 + [np.nan] + [True, False] * 44 + [np.nan] + [True, False],
1415
dtype="boolean",
@@ -17,11 +18,13 @@ def data():
1718

1819
@pytest.fixture
1920
def left_array():
21+
"""Fixture returning boolean array with valid and missing values."""
2022
return pd.array([True] * 3 + [False] * 3 + [None] * 3, dtype="boolean")
2123

2224

2325
@pytest.fixture
2426
def right_array():
27+
"""Fixture returning boolean array with valid and missing values."""
2528
return pd.array([True, False, None] * 3, dtype="boolean")
2629

2730

pandas/tests/arrays/boolean/test_comparison.py

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
@pytest.fixture
1111
def data():
12+
"""Fixture returning boolean array with valid and missing data"""
1213
return pd.array(
1314
[True, False] * 4 + [np.nan] + [True, False] * 44 + [np.nan] + [True, False],
1415
dtype="boolean",
@@ -17,6 +18,7 @@ def data():
1718

1819
@pytest.fixture
1920
def dtype():
21+
"""Fixture returning BooleanDtype"""
2022
return pd.BooleanDtype()
2123

2224

pandas/tests/arrays/boolean/test_reduction.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
@pytest.fixture
88
def data():
9+
"""Fixture returning boolean array, with valid and missing values."""
910
return pd.array(
1011
[True, False] * 4 + [np.nan] + [True, False] * 44 + [np.nan] + [True, False],
1112
dtype="boolean",

pandas/tests/arrays/categorical/conftest.py

+1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ def allow_fill(request):
1111

1212
@pytest.fixture
1313
def factor():
14+
"""Fixture returning a Categorical object"""
1415
return Categorical(["a", "b", "b", "a", "a", "c", "c", "c"], ordered=True)

pandas/tests/arrays/datetimes/test_reductions.py

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
class TestReductions:
1313
@pytest.fixture
1414
def arr1d(self, tz_naive_fixture):
15+
"""Fixture returning DatetimeArray with parametrized timezones"""
1516
tz = tz_naive_fixture
1617
dtype = DatetimeTZDtype(tz=tz) if tz is not None else np.dtype("M8[ns]")
1718
arr = DatetimeArray._from_sequence(

pandas/tests/arrays/floating/conftest.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010

1111
@pytest.fixture(params=[Float32Dtype, Float64Dtype])
1212
def dtype(request):
13+
"""Parametrized fixture returning a float 'dtype'"""
1314
return request.param()
1415

1516

1617
@pytest.fixture
1718
def data(dtype):
19+
"""Fixture returning 'data' array according to parametrized float 'dtype'"""
1820
return pd.array(
1921
list(np.arange(0.1, 0.9, 0.1))
2022
+ [pd.NA]
@@ -27,12 +29,19 @@ def data(dtype):
2729

2830
@pytest.fixture
2931
def data_missing(dtype):
32+
"""
33+
Fixture returning array with missing data according to parametrized float
34+
'dtype'.
35+
"""
3036
return pd.array([np.nan, 0.1], dtype=dtype)
3137

3238

3339
@pytest.fixture(params=["data", "data_missing"])
3440
def all_data(request, data, data_missing):
35-
"""Parametrized fixture giving 'data' and 'data_missing'"""
41+
"""Parametrized fixture returning 'data' or 'data_missing' float arrays.
42+
43+
Used to test dtype conversion with and without missing values.
44+
"""
3645
if request.param == "data":
3746
return data
3847
elif request.param == "data_missing":

pandas/tests/arrays/integer/conftest.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@
2727
]
2828
)
2929
def dtype(request):
30+
"""Parametrized fixture returning integer 'dtype'"""
3031
return request.param()
3132

3233

3334
@pytest.fixture
3435
def data(dtype):
36+
"""
37+
Fixture returning 'data' array with valid and missing values according to
38+
parametrized integer 'dtype'.
39+
40+
Used to test dtype conversion with and without missing values.
41+
"""
3542
return pd.array(
3643
list(range(8)) + [np.nan] + list(range(10, 98)) + [np.nan] + [99, 100],
3744
dtype=dtype,
@@ -40,12 +47,21 @@ def data(dtype):
4047

4148
@pytest.fixture
4249
def data_missing(dtype):
50+
"""
51+
Fixture returning array with exactly one NaN and one valid integer,
52+
according to parametrized integer 'dtype'.
53+
54+
Used to test dtype conversion with and without missing values.
55+
"""
4356
return pd.array([np.nan, 1], dtype=dtype)
4457

4558

4659
@pytest.fixture(params=["data", "data_missing"])
4760
def all_data(request, data, data_missing):
48-
"""Parametrized fixture giving 'data' and 'data_missing'"""
61+
"""Parametrized fixture returning 'data' or 'data_missing' integer arrays.
62+
63+
Used to test dtype conversion with and without missing values.
64+
"""
4965
if request.param == "data":
5066
return data
5167
elif request.param == "data_missing":

pandas/tests/arrays/integer/test_construction.py

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
@pytest.fixture(params=[pd.array, IntegerArray._from_sequence])
1616
def constructor(request):
17+
"""Fixture returning parametrized IntegerArray from given sequence.
18+
19+
Used to test dtype conversions.
20+
"""
1721
return request.param
1822

1923

pandas/tests/arrays/masked/test_arithmetic.py

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121

2222
@pytest.fixture(params=zip(arrays, scalars), ids=[a.dtype.name for a in arrays])
2323
def data(request):
24+
"""Fixture returning parametrized (array, scalar) tuple.
25+
26+
Used to test equivalence of scalars, numpy arrays with array ops, and the
27+
equivalence of DataFrame and Series ops.
28+
"""
2429
return request.param
2530

2631

pandas/tests/arrays/masked/test_arrow_compat.py

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515

1616
@pytest.fixture(params=arrays, ids=[a.dtype.name for a in arrays])
1717
def data(request):
18+
"""
19+
Fixture returning parametrized array from given dtype, including integer,
20+
float and boolean
21+
"""
1822
return request.param
1923

2024

@@ -101,6 +105,10 @@ def test_arrow_sliced(data):
101105

102106
@pytest.fixture
103107
def np_dtype_to_arrays(any_real_numpy_dtype):
108+
"""
109+
Fixture returning actual and expected dtype, pandas and numpy arrays and
110+
mask from a given numpy dtype
111+
"""
104112
np_dtype = np.dtype(any_real_numpy_dtype)
105113
pa_type = pa.from_numpy_dtype(np_dtype)
106114

pandas/tests/arrays/masked/test_function.py

+7
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,18 @@
1414

1515
@pytest.fixture(params=arrays, ids=[a.dtype.name for a in arrays])
1616
def data(request):
17+
"""
18+
Fixture returning parametrized 'data' array with different integer and
19+
floating point types
20+
"""
1721
return request.param
1822

1923

2024
@pytest.fixture()
2125
def numpy_dtype(data):
26+
"""
27+
Fixture returning numpy dtype from 'data' input array.
28+
"""
2229
# For integer dtype, the numpy conversion must be done to float
2330
if is_integer_dtype(data):
2431
numpy_dtype = float

pandas/tests/arrays/sparse/test_arithmetics.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ def kind(request):
2222

2323
@pytest.fixture(params=[True, False])
2424
def mix(request):
25-
# whether to operate op(sparse, dense) instead of op(sparse, sparse)
25+
"""
26+
Fixture returning True or False, determining whether to operate
27+
op(sparse, dense) instead of op(sparse, sparse)
28+
"""
2629
return request.param
2730

2831

pandas/tests/arrays/sparse/test_array.py

+3
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@
1818

1919
@pytest.fixture
2020
def arr_data():
21+
"""Fixture returning numpy array with valid and missing entries"""
2122
return np.array([np.nan, np.nan, 1, 2, 3, np.nan, 4, 5, np.nan, 6])
2223

2324

2425
@pytest.fixture
2526
def arr(arr_data):
27+
"""Fixture returning SparseArray from 'arr_data'"""
2628
return SparseArray(arr_data)
2729

2830

2931
@pytest.fixture
3032
def zarr():
33+
"""Fixture returning SparseArray with integer entries and 'fill_value=0'"""
3134
return SparseArray([0, 0, 1, 2, 3, 0, 4, 5, 0, 6], fill_value=0)
3235

3336

pandas/tests/arrays/string_/test_string.py

+2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818

1919
@pytest.fixture
2020
def dtype(string_storage):
21+
"""Fixture giving StringDtype from parametrized 'string_storage'"""
2122
return pd.StringDtype(storage=string_storage)
2223

2324

2425
@pytest.fixture
2526
def cls(dtype):
27+
"""Fixture giving array type from parametrized 'dtype'"""
2628
return dtype.construct_array_type()
2729

2830

pandas/tests/arrays/test_array.py

+1
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ def test_array_unboxes(index_or_series):
379379

380380
@pytest.fixture
381381
def registry_without_decimal():
382+
"""Fixture yielding 'registry' with no DecimalDtype entries"""
382383
idx = registry.dtypes.index(DecimalDtype)
383384
registry.dtypes.pop(idx)
384385
yield

pandas/tests/arrays/test_datetimelike.py

+13
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
# TODO: more freq variants
3434
@pytest.fixture(params=["D", "B", "W", "M", "Q", "Y"])
3535
def freqstr(request):
36+
"""Fixture returning parametrized frequency in string format."""
3637
return request.param
3738

3839

@@ -81,6 +82,7 @@ class SharedTests:
8182

8283
@pytest.fixture
8384
def arr1d(self):
85+
"""Fixture returning DatetimeArray with daily frequency."""
8486
data = np.arange(10, dtype="i8") * 24 * 3600 * 10**9
8587
arr = self.array_cls(data, freq="D")
8688
return arr
@@ -635,6 +637,10 @@ class TestDatetimeArray(SharedTests):
635637

636638
@pytest.fixture
637639
def arr1d(self, tz_naive_fixture, freqstr):
640+
"""
641+
Fixture returning DatetimeArray with parametrized frequency and
642+
timezones
643+
"""
638644
tz = tz_naive_fixture
639645
dti = pd.date_range("2016-01-01 01:01:00", periods=5, freq=freqstr, tz=tz)
640646
dta = dti._data
@@ -1068,6 +1074,9 @@ class TestPeriodArray(SharedTests):
10681074

10691075
@pytest.fixture
10701076
def arr1d(self, period_index):
1077+
"""
1078+
Fixture returning DatetimeArray from parametrized PeriodIndex objects
1079+
"""
10711080
return period_index._data
10721081

10731082
def test_from_pi(self, arr1d):
@@ -1389,6 +1398,10 @@ def test_from_pandas_array(dtype):
13891398
]
13901399
)
13911400
def array_likes(request):
1401+
"""
1402+
Fixture giving a numpy array and a parametrized 'data' object, which can
1403+
be a memoryview, array, dask or xarray object created from the numpy array.
1404+
"""
13921405
# GH#24539 recognize e.g xarray, dask, ...
13931406
arr = np.array([1, 2, 3], dtype=np.int64)
13941407

pandas/tests/arrays/test_datetimes.py

+2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
class TestNonNano:
1515
@pytest.fixture(params=["s", "ms", "us"])
1616
def unit(self, request):
17+
"""Fixture returning parametrized time units"""
1718
return request.param
1819

1920
@pytest.fixture
2021
def reso(self, unit):
22+
"""Fixture returning datetime resolution for a given time unit"""
2123
# TODO: avoid hard-coding
2224
return {"s": 7, "ms": 8, "us": 9}[unit]
2325

0 commit comments

Comments
 (0)