Skip to content
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: 2 additions & 0 deletions pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
pa_version_under17p0,
pa_version_under18p0,
pa_version_under19p0,
pa_version_under20p0,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -168,4 +169,5 @@ def is_ci_environment() -> bool:
"pa_version_under17p0",
"pa_version_under18p0",
"pa_version_under19p0",
"pa_version_under20p0",
]
39 changes: 26 additions & 13 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
pa_version_under11p0,
pa_version_under13p0,
pa_version_under14p0,
pa_version_under20p0,
)

from pandas.core.dtypes.dtypes import (
Expand Down Expand Up @@ -453,31 +454,24 @@ 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"]:
if op_name == "kurt" or (pa_version_under20p0 and op_name == "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", "prod"]:
if pa.types.is_temporal(pa_dtype) and op_name in ["sum", "var", "prod", "skew"]:
if pa.types.is_duration(pa_dtype) and op_name in ["sum"]:
# summing timedeltas is one case that *is* well-defined
pass
else:
return False
elif pa.types.is_binary(pa_dtype) and op_name == "sum":
elif pa.types.is_binary(pa_dtype) and op_name in ["sum", "skew"]:
return False
elif (
pa.types.is_string(pa_dtype) or pa.types.is_binary(pa_dtype)
) and op_name in [
"mean",
"median",
"prod",
"std",
"sem",
"var",
]:
) and op_name in ["mean", "median", "prod", "std", "sem", "var", "skew"]:
return False

if (
Expand Down Expand Up @@ -561,7 +555,7 @@ 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", "sem"]:
if op_name not in ["median", "var", "std", "sem", "skew"]:
cmp_dtype = arr.dtype
else:
cmp_dtype = "float64[pyarrow]"
Expand All @@ -579,10 +573,29 @@ def _get_expected_reduction_dtype(self, arr, op_name: str, skipna: bool):
}[arr.dtype.kind]
return cmp_dtype

@pytest.mark.filterwarnings("ignore::RuntimeWarning")
@pytest.mark.parametrize("skipna", [True, False])
def test_reduce_series_numeric(self, data, all_numeric_reductions, skipna, request):
if (
not pa_version_under20p0
and skipna
and all_numeric_reductions == "skew"
and (
pa.types.is_integer(data.dtype.pyarrow_dtype)
or pa.types.is_floating(data.dtype.pyarrow_dtype)
)
):
request.applymarker(
pytest.mark.xfail(
reason="https://github.com/apache/arrow/issues/45733",
)
)
return 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):
op_name = all_numeric_reductions
if op_name == "skew":
if op_name == "skew" and pa_version_under20p0:
if data.dtype._is_numeric:
mark = pytest.mark.xfail(reason="skew not implemented")
request.applymarker(mark)
Expand Down
Loading