Skip to content

Commit de10b81

Browse files
jbrockmendelJulianWgs
authored andcommitted
TST: xfail incorrect test_empty_groupby (pandas-dev#41341)
1 parent cad0e29 commit de10b81

File tree

1 file changed

+62
-7
lines changed

1 file changed

+62
-7
lines changed

pandas/tests/groupby/test_groupby.py

+62-7
Original file line numberDiff line numberDiff line change
@@ -1724,27 +1724,82 @@ def test_pivot_table_values_key_error():
17241724
[0],
17251725
[0.0],
17261726
["a"],
1727-
[Categorical([0])],
1727+
Categorical([0]),
17281728
[to_datetime(0)],
1729-
[date_range(0, 1, 1, tz="US/Eastern")],
1730-
[pd.array([0], dtype="Int64")],
1731-
[pd.array([0], dtype="Float64")],
1732-
[pd.array([False], dtype="boolean")],
1729+
date_range(0, 1, 1, tz="US/Eastern"),
1730+
pd.array([0], dtype="Int64"),
1731+
pd.array([0], dtype="Float64"),
1732+
pd.array([False], dtype="boolean"),
17331733
],
17341734
)
17351735
@pytest.mark.parametrize("method", ["attr", "agg", "apply"])
17361736
@pytest.mark.parametrize(
17371737
"op", ["idxmax", "idxmin", "mad", "min", "max", "sum", "prod", "skew"]
17381738
)
1739-
def test_empty_groupby(columns, keys, values, method, op):
1739+
def test_empty_groupby(columns, keys, values, method, op, request):
17401740
# GH8093 & GH26411
17411741

1742+
if isinstance(values, Categorical) and len(keys) == 1 and method == "apply":
1743+
mark = pytest.mark.xfail(raises=TypeError, match="'str' object is not callable")
1744+
request.node.add_marker(mark)
1745+
elif (
1746+
isinstance(values, Categorical)
1747+
and len(keys) == 1
1748+
and op in ["idxmax", "idxmin"]
1749+
):
1750+
mark = pytest.mark.xfail(
1751+
raises=ValueError, match="attempt to get arg(min|max) of an empty sequence"
1752+
)
1753+
request.node.add_marker(mark)
1754+
elif (
1755+
isinstance(values, Categorical)
1756+
and len(keys) == 1
1757+
and not isinstance(columns, list)
1758+
):
1759+
mark = pytest.mark.xfail(
1760+
raises=TypeError, match="'Categorical' does not implement"
1761+
)
1762+
request.node.add_marker(mark)
1763+
elif (
1764+
isinstance(values, Categorical)
1765+
and len(keys) == 1
1766+
and op in ["mad", "min", "max", "sum", "prod", "skew"]
1767+
):
1768+
mark = pytest.mark.xfail(
1769+
raises=AssertionError, match="(DataFrame|Series) are different"
1770+
)
1771+
request.node.add_marker(mark)
1772+
elif (
1773+
isinstance(values, Categorical)
1774+
and len(keys) == 2
1775+
and op in ["min", "max", "sum"]
1776+
and method != "apply"
1777+
):
1778+
mark = pytest.mark.xfail(
1779+
raises=AssertionError, match="(DataFrame|Series) are different"
1780+
)
1781+
request.node.add_marker(mark)
1782+
elif (
1783+
isinstance(values, pd.core.arrays.BooleanArray)
1784+
and op in ["sum", "prod"]
1785+
and method != "apply"
1786+
):
1787+
mark = pytest.mark.xfail(
1788+
raises=AssertionError, match="(DataFrame|Series) are different"
1789+
)
1790+
request.node.add_marker(mark)
1791+
17421792
override_dtype = None
17431793
if isinstance(values[0], bool) and op in ("prod", "sum") and method != "apply":
17441794
# sum/product of bools is an integer
17451795
override_dtype = "int64"
17461796

1747-
df = DataFrame([3 * values], columns=list("ABC"))
1797+
df = DataFrame({"A": values, "B": values, "C": values}, columns=list("ABC"))
1798+
1799+
if hasattr(values, "dtype"):
1800+
# check that we did the construction right
1801+
assert (df.dtypes == values.dtype).all()
1802+
17481803
df = df.iloc[:0]
17491804

17501805
gb = df.groupby(keys)[columns]

0 commit comments

Comments
 (0)