Skip to content

TST: unskip EA reduction tests #59247

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
Jul 15, 2024
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
2 changes: 1 addition & 1 deletion pandas/core/arrays/masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ def _wrap_na_result(self, *, name, axis, mask_size):
mask = np.ones(mask_size, dtype=bool)

float_dtyp = "float32" if self.dtype == "Float32" else "float64"
if name in ["mean", "median", "var", "std", "skew", "kurt"]:
if name in ["mean", "median", "var", "std", "skew", "kurt", "sem"]:
np_dtype = float_dtyp
elif name in ["min", "max"] or self.dtype.itemsize == 8:
np_dtype = self.dtype.numpy_dtype.name
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/extension/base/reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def check_reduce_frame(self, ser: pd.Series, op_name: str, skipna: bool):
arr = ser.array
df = pd.DataFrame({"a": arr})

kwargs = {"ddof": 1} if op_name in ["var", "std"] else {}
kwargs = {"ddof": 1} if op_name in ["var", "std", "sem"] else {}

cmp_dtype = self._get_expected_reduction_dtype(arr, op_name, skipna)

Expand Down Expand Up @@ -119,7 +119,7 @@ def test_reduce_frame(self, data, all_numeric_reductions, skipna):
op_name = all_numeric_reductions
ser = pd.Series(data)

if op_name in ["count", "kurt", "sem"]:
if op_name == "count":
pytest.skip(f"{op_name} not an array method")

if not self._supports_reduction(ser, op_name):
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/extension/decimal/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def _get_expected_exception(
return None

def _supports_reduction(self, ser: pd.Series, op_name: str) -> bool:
if op_name in ["kurt", "sem"]:
return False
return True

def check_reduce(self, ser: pd.Series, op_name: str, skipna: bool):
Expand Down
40 changes: 11 additions & 29 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,17 +467,14 @@ def test_accumulate_series(self, data, all_numeric_accumulations, skipna, reques
self.check_accumulate(ser, op_name, skipna)

def _supports_reduction(self, ser: pd.Series, op_name: str) -> bool:
if op_name in ["kurt", "skew"]:
return False

dtype = ser.dtype
# error: Item "dtype[Any]" of "dtype[Any] | ExtensionDtype" has
# no attribute "pyarrow_dtype"
pa_dtype = dtype.pyarrow_dtype # type: ignore[union-attr]
if pa.types.is_temporal(pa_dtype) and op_name in [
"sum",
"var",
"skew",
"kurt",
"prod",
]:
if pa.types.is_temporal(pa_dtype) and op_name in ["sum", "var", "prod"]:
if pa.types.is_duration(pa_dtype) and op_name in ["sum"]:
# summing timedeltas is one case that *is* well-defined
pass
Expand All @@ -493,8 +490,6 @@ def _supports_reduction(self, ser: pd.Series, op_name: str) -> bool:
"std",
"sem",
"var",
"skew",
"kurt",
]:
return False

Expand Down Expand Up @@ -541,23 +536,6 @@ 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

xfail_mark = pytest.mark.xfail(
raises=TypeError,
reason=(
f"{all_numeric_reductions} is not implemented in "
f"pyarrow={pa.__version__} for {pa_dtype}"
),
)
if all_numeric_reductions in {"skew", "kurt"} and dtype._is_numeric:
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 @@ -596,11 +574,11 @@ def _get_expected_reduction_dtype(self, arr, op_name: str, skipna: bool):
else:
cmp_dtype = arr.dtype
elif arr.dtype.name == "decimal128(7, 3)[pyarrow]":
if op_name not in ["median", "var", "std"]:
if op_name not in ["median", "var", "std", "sem"]:
cmp_dtype = arr.dtype
else:
cmp_dtype = "float64[pyarrow]"
elif op_name in ["median", "var", "std", "mean", "skew"]:
elif op_name in ["median", "var", "std", "mean", "skew", "sem"]:
cmp_dtype = "float64[pyarrow]"
elif op_name in ["sum", "prod"] and pa.types.is_boolean(pa_type):
cmp_dtype = "uint64[pyarrow]"
Expand All @@ -619,7 +597,11 @@ def test_reduce_frame(self, data, all_numeric_reductions, skipna, request):
if data.dtype._is_numeric:
mark = pytest.mark.xfail(reason="skew not implemented")
request.applymarker(mark)
elif op_name == "std" and pa.types.is_date64(data._pa_array.type) and skipna:
elif (
op_name in ["std", "sem"]
and pa.types.is_date64(data._pa_array.type)
and skipna
):
# overflow
mark = pytest.mark.xfail(reason="Cannot cast")
request.applymarker(mark)
Expand Down
6 changes: 2 additions & 4 deletions pandas/tests/extension/test_masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def check_reduce(self, ser: pd.Series, op_name: str, skipna: bool):
def _get_expected_reduction_dtype(self, arr, op_name: str, skipna: bool):
if is_float_dtype(arr.dtype):
cmp_dtype = arr.dtype.name
elif op_name in ["mean", "median", "var", "std", "skew"]:
elif op_name in ["mean", "median", "var", "std", "skew", "kurt", "sem"]:
cmp_dtype = "Float64"
elif op_name in ["max", "min"]:
cmp_dtype = arr.dtype.name
Expand All @@ -323,9 +323,7 @@ def _get_expected_reduction_dtype(self, arr, op_name: str, skipna: bool):
else "UInt64"
)
elif arr.dtype.kind == "b":
if op_name in ["mean", "median", "var", "std", "skew"]:
cmp_dtype = "Float64"
elif op_name in ["min", "max"]:
if op_name in ["min", "max"]:
cmp_dtype = "boolean"
elif op_name in ["sum", "prod"]:
cmp_dtype = (
Expand Down
Loading