Skip to content

TST: extension tests use its own fixtures #56889

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
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
1 change: 1 addition & 0 deletions pandas/tests/extension/base/accumulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def check_accumulate(self, ser: pd.Series, op_name: str, skipna: bool):
expected = getattr(alt, op_name)(skipna=skipna)
tm.assert_series_equal(result, expected, check_dtype=False)

@pytest.mark.parametrize("skipna", [True, False])
def test_accumulate_series(self, data, all_numeric_accumulations, skipna):
op_name = all_numeric_accumulations
ser = pd.Series(data)
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/extension/base/dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def test_get_common_dtype(self, dtype):
# only case we can test in general)
assert dtype._get_common_dtype([dtype]) == dtype

@pytest.mark.parametrize("skipna", [True, False])
def test_infer_dtype(self, data, data_missing, skipna):
# only testing that this works without raising an error
res = infer_dtype(data, skipna=skipna)
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/extension/base/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def test_grouping_grouper(self, data_for_grouping):
tm.assert_numpy_array_equal(gr1.grouping_vector, df.A.values)
tm.assert_extension_array_equal(gr2.grouping_vector, data_for_grouping)

@pytest.mark.parametrize("as_index", [True, False])
def test_groupby_extension_agg(self, as_index, data_for_grouping):
df = pd.DataFrame({"A": [1, 1, 2, 2, 3, 3, 1, 4], "B": data_for_grouping})

Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/extension/base/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_value_counts_default_dropna(self, data):
kwarg = sig.parameters["dropna"]
assert kwarg.default is True

@pytest.mark.parametrize("dropna", [True, False])
def test_value_counts(self, all_data, dropna):
all_data = all_data[:10]
if dropna:
Expand Down Expand Up @@ -96,6 +97,7 @@ def test_apply_simple_series(self, data):
result = pd.Series(data).apply(id)
assert isinstance(result, pd.Series)

@pytest.mark.parametrize("na_action", [None, "ignore"])
def test_map(self, data_missing, na_action):
result = data_missing.map(lambda x: x, na_action=na_action)
expected = data_missing.to_numpy()
Expand Down Expand Up @@ -211,6 +213,7 @@ def test_nargsort(self, data_missing_for_sorting, na_position, expected):
result = nargsort(data_missing_for_sorting, na_position=na_position)
tm.assert_numpy_array_equal(result, expected)

@pytest.mark.parametrize("ascending", [True, False])
def test_sort_values(self, data_for_sorting, ascending, sort_by_key):
ser = pd.Series(data_for_sorting)
result = ser.sort_values(ascending=ascending, key=sort_by_key)
Expand All @@ -224,6 +227,7 @@ def test_sort_values(self, data_for_sorting, ascending, sort_by_key):

tm.assert_series_equal(result, expected)

@pytest.mark.parametrize("ascending", [True, False])
def test_sort_values_missing(
self, data_missing_for_sorting, ascending, sort_by_key
):
Expand All @@ -235,6 +239,7 @@ def test_sort_values_missing(
expected = ser.iloc[[0, 2, 1]]
tm.assert_series_equal(result, expected)

@pytest.mark.parametrize("ascending", [True, False])
def test_sort_values_frame(self, data_for_sorting, ascending):
df = pd.DataFrame({"A": [1, 2, 1], "B": data_for_sorting})
result = df.sort_values(["A", "B"])
Expand All @@ -243,6 +248,7 @@ def test_sort_values_frame(self, data_for_sorting, ascending):
)
tm.assert_frame_equal(result, expected)

@pytest.mark.parametrize("keep", ["first", "last", False])
def test_duplicated(self, data, keep):
arr = data.take([0, 1, 0, 1])
result = arr.duplicated(keep=keep)
Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/extension/base/reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def check_reduce_frame(self, ser: pd.Series, op_name: str, skipna: bool):

tm.assert_extension_array_equal(result1, expected)

@pytest.mark.parametrize("skipna", [True, False])
def test_reduce_series_boolean(self, data, all_boolean_reductions, skipna):
op_name = all_boolean_reductions
ser = pd.Series(data)
Expand All @@ -95,6 +96,7 @@ def test_reduce_series_boolean(self, data, all_boolean_reductions, skipna):
self.check_reduce(ser, op_name, skipna)

@pytest.mark.filterwarnings("ignore::RuntimeWarning")
@pytest.mark.parametrize("skipna", [True, False])
def test_reduce_series_numeric(self, data, all_numeric_reductions, skipna):
op_name = all_numeric_reductions
ser = pd.Series(data)
Expand All @@ -113,6 +115,7 @@ def test_reduce_series_numeric(self, data, all_numeric_reductions, skipna):
# min/max with empty produce numpy warnings
self.check_reduce(ser, op_name, skipna)

@pytest.mark.parametrize("skipna", [True, False])
def test_reduce_frame(self, data, all_numeric_reductions, skipna):
op_name = all_numeric_reductions
ser = pd.Series(data)
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/extension/base/setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ def test_setitem_sequence_broadcasts(self, data, box_in_series):
assert data[0] == data[2]
assert data[1] == data[2]

def test_setitem_scalar(self, data, indexer_li):
@pytest.mark.parametrize("setter", ["loc", "iloc"])
def test_setitem_scalar(self, data, setter):
arr = pd.Series(data)
setter = indexer_li(arr)
setter = getattr(arr, setter)
setter[0] = data[1]
assert arr[0] == data[1]

Expand Down
1 change: 1 addition & 0 deletions pandas/tests/extension/decimal/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def test_fillna_copy_series(self, data_missing, using_copy_on_write):
with tm.assert_produces_warning(warn, match=msg, check_stacklevel=False):
super().test_fillna_copy_series(data_missing)

@pytest.mark.parametrize("dropna", [True, False])
def test_value_counts(self, all_data, dropna):
all_data = all_data[:10]
if dropna:
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def test_compare_scalar(self, data, comparison_op):
ser = pd.Series(data)
self._compare_other(ser, data, comparison_op, data[0])

@pytest.mark.parametrize("na_action", [None, "ignore"])
def test_map(self, data_missing, na_action):
if data_missing.dtype.kind in "mM":
result = data_missing.map(lambda x: x, na_action=na_action)
Expand Down Expand Up @@ -423,6 +424,7 @@ def _supports_accumulation(self, ser: pd.Series, op_name: str) -> bool:
return False
return True

@pytest.mark.parametrize("skipna", [True, False])
def test_accumulate_series(self, data, all_numeric_accumulations, skipna, request):
pa_type = data.dtype.pyarrow_dtype
op_name = all_numeric_accumulations
Expand Down Expand Up @@ -524,6 +526,7 @@ def check_reduce(self, ser: pd.Series, op_name: str, skipna: bool):
expected = getattr(alt, op_name)(skipna=skipna)
tm.assert_almost_equal(result, expected)

@pytest.mark.parametrize("skipna", [True, False])
def test_reduce_series_numeric(self, data, all_numeric_reductions, skipna, request):
dtype = data.dtype
pa_dtype = dtype.pyarrow_dtype
Expand All @@ -549,6 +552,7 @@ def test_reduce_series_numeric(self, data, all_numeric_reductions, skipna, reque
request.applymarker(xfail_mark)
super().test_reduce_series_numeric(data, all_numeric_reductions, skipna)

@pytest.mark.parametrize("skipna", [True, False])
def test_reduce_series_boolean(
self, data, all_boolean_reductions, skipna, na_value, request
):
Expand Down Expand Up @@ -585,6 +589,7 @@ def _get_expected_reduction_dtype(self, arr, op_name: str, skipna: bool):
}[arr.dtype.kind]
return cmp_dtype

@pytest.mark.parametrize("skipna", [True, False])
def test_reduce_frame(self, data, all_numeric_reductions, skipna, request):
op_name = all_numeric_reductions
if op_name == "skew":
Expand Down Expand Up @@ -2325,6 +2330,7 @@ def test_str_extract_expand():
tm.assert_series_equal(result, expected)


@pytest.mark.parametrize("unit", ["ns", "us", "ms", "s"])
def test_duration_from_strings_with_nat(unit):
# GH51175
strings = ["1000", "NaT"]
Expand Down Expand Up @@ -2827,6 +2833,7 @@ def test_dt_components():
tm.assert_frame_equal(result, expected)


@pytest.mark.parametrize("skipna", [True, False])
def test_boolean_reduce_series_all_null(all_boolean_reductions, skipna):
# GH51624
ser = pd.Series([None], dtype="float64[pyarrow]")
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/extension/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def test_combine_add(self, data_repeated):
expected = pd.Series([a + val for a in list(orig_data1)])
tm.assert_series_equal(result, expected)

@pytest.mark.parametrize("na_action", [None, "ignore"])
def test_map(self, data, na_action):
result = data.map(lambda x: x, na_action=na_action)
tm.assert_extension_array_equal(result, data)
Expand Down Expand Up @@ -174,6 +175,7 @@ def test_array_repr(self, data, size):
super().test_array_repr(data, size)

@pytest.mark.xfail(reason="TBD")
@pytest.mark.parametrize("as_index", [True, False])
def test_groupby_extension_agg(self, as_index, data_for_grouping):
super().test_groupby_extension_agg(as_index, data_for_grouping)

Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/extension/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def _supports_accumulation(self, ser, op_name: str) -> bool:
def _supports_reduction(self, obj, op_name: str) -> bool:
return op_name in ["min", "max", "median", "mean", "std", "any", "all"]

@pytest.mark.parametrize("skipna", [True, False])
def test_reduce_series_boolean(self, data, all_boolean_reductions, skipna):
meth = all_boolean_reductions
msg = f"'{meth}' with datetime64 dtypes is deprecated and will raise in"
Expand All @@ -113,6 +114,7 @@ def test_series_constructor(self, data):
data = data._with_freq(None)
super().test_series_constructor(data)

@pytest.mark.parametrize("na_action", [None, "ignore"])
def test_map(self, data, na_action):
result = data.map(lambda x: x, na_action=na_action)
tm.assert_extension_array_equal(result, data)
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/extension/test_masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def data_for_grouping(dtype):


class TestMaskedArrays(base.ExtensionTests):
@pytest.mark.parametrize("na_action", [None, "ignore"])
def test_map(self, data_missing, na_action):
result = data_missing.map(lambda x: x, na_action=na_action)
if data_missing.dtype == Float32Dtype():
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/extension/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ def check_reduce(self, ser: pd.Series, op_name: str, skipna: bool):
tm.assert_almost_equal(result, expected)

@pytest.mark.skip("TODO: tests not written yet")
@pytest.mark.parametrize("skipna", [True, False])
def test_reduce_frame(self, data, all_numeric_reductions, skipna):
pass

Expand Down
1 change: 1 addition & 0 deletions pandas/tests/extension/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def test_diff(self, data, periods):
else:
super().test_diff(data, periods)

@pytest.mark.parametrize("na_action", [None, "ignore"])
def test_map(self, data, na_action):
result = data.map(lambda x: x, na_action=na_action)
tm.assert_extension_array_equal(result, data)
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/extension/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class TestSparseArray(base.ExtensionTests):
def _supports_reduction(self, obj, op_name: str) -> bool:
return True

@pytest.mark.parametrize("skipna", [True, False])
def test_reduce_series_numeric(self, data, all_numeric_reductions, skipna, request):
if all_numeric_reductions in [
"prod",
Expand All @@ -126,6 +127,7 @@ def test_reduce_series_numeric(self, data, all_numeric_reductions, skipna, reque

super().test_reduce_series_numeric(data, all_numeric_reductions, skipna)

@pytest.mark.parametrize("skipna", [True, False])
def test_reduce_frame(self, data, all_numeric_reductions, skipna, request):
if all_numeric_reductions in [
"prod",
Expand Down Expand Up @@ -366,6 +368,7 @@ def test_map(self, func, na_action, expected):
result = data.map(func, na_action=na_action)
tm.assert_extension_array_equal(result, expected)

@pytest.mark.parametrize("na_action", [None, "ignore"])
def test_map_raises(self, data, na_action):
# GH52096
msg = "fill value in the sparse values not supported"
Expand Down Expand Up @@ -486,6 +489,7 @@ def test_array_repr(self, data, size):
super().test_array_repr(data, size)

@pytest.mark.xfail(reason="result does not match expected")
@pytest.mark.parametrize("as_index", [True, False])
def test_groupby_extension_agg(self, as_index, data_for_grouping):
super().test_groupby_extension_agg(as_index, data_for_grouping)

Expand Down