Skip to content

Commit

Permalink
Fix other tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl committed Oct 23, 2023
1 parent 5c58816 commit 7c400e7
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 15 deletions.
12 changes: 11 additions & 1 deletion pandas/tests/groupby/methods/test_nth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from decimal import Decimal

import numpy as np
import pytest

Expand Down Expand Up @@ -682,7 +684,15 @@ def test_first_multi_key_groupby_categorical():
@pytest.mark.parametrize("method", ["first", "last", "nth"])
def test_groupby_last_first_nth_with_none(method, nulls_fixture):
# GH29645
expected = Series(["y"])
if nulls_fixture is not pd.NA and (
nulls_fixture is pd.NaT
or isinstance(nulls_fixture, Decimal)
and Decimal.is_nan(nulls_fixture)
):
dtype = object
else:
dtype = None
expected = Series(["y"], dtype=dtype)
data = Series(
[nulls_fixture, nulls_fixture, nulls_fixture, "y", nulls_fixture],
index=[0, 0, 0, 0, 0],
Expand Down
10 changes: 7 additions & 3 deletions pandas/tests/groupby/methods/test_value_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numpy as np
import pytest

from pandas.compat import pa_version_under7p0
from pandas.compat import pa_version_under10p1

from pandas import (
Categorical,
Expand Down Expand Up @@ -377,11 +377,15 @@ def test_against_frame_and_seriesgroupby(
object,
pytest.param(
"string[pyarrow_numpy]",
marks=pytest.mark.skipif(pa_version_under7p0, reason="arrow not installed"),
marks=pytest.mark.skipif(
pa_version_under10p1, reason="arrow not installed"
),
),
pytest.param(
"string[pyarrow]",
marks=pytest.mark.skipif(pa_version_under7p0, reason="arrow not installed"),
marks=pytest.mark.skipif(
pa_version_under10p1, reason="arrow not installed"
),
),
],
)
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/groupby/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -1265,9 +1265,7 @@ def test_apply_dropna_with_indexed_same(dropna):
[
[
False,
DataFrame(
[[1, 1, 1], [2, 2, 1]], columns=Index(["a", "b", None], dtype=object)
),
DataFrame([[1, 1, 1], [2, 2, 1]], columns=Index(["a", "b", None])),
],
[
True,
Expand Down
6 changes: 5 additions & 1 deletion pandas/tests/groupby/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,18 @@ def test_apply(ordered):
tm.assert_series_equal(result, expected)


def test_observed(observed):
def test_observed(observed, using_infer_string, request):
# multiple groupers, don't re-expand the output space
# of the grouper
# gh-14942 (implement)
# gh-10132 (back-compat)
# gh-8138 (back-compat)
# gh-8869

if not observed and using_infer_string:
mark = pytest.mark.xfail(reason="fill_value=0 invalid for string dtype")
request.applymarker(mark)

cat1 = Categorical(["a", "a", "b", "b"], categories=["a", "b", "z"], ordered=True)
cat2 = Categorical(["c", "d", "c", "d"], categories=["c", "d", "y"], ordered=True)
df = DataFrame({"A": cat1, "B": cat2, "values": [1, 2, 3, 4]})
Expand Down
10 changes: 7 additions & 3 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
import pytest

from pandas.compat import pa_version_under7p0
from pandas.compat import pa_version_under10p1
from pandas.errors import (
PerformanceWarning,
SpecificationError,
Expand Down Expand Up @@ -2557,7 +2557,9 @@ def test_groupby_column_index_name_lost(func):
False,
pytest.param(
True,
marks=pytest.mark.skipif(pa_version_under7p0, reason="arrow not installed"),
marks=pytest.mark.skipif(
pa_version_under10p1, reason="arrow not installed"
),
),
],
)
Expand Down Expand Up @@ -2800,7 +2802,9 @@ def test_rolling_wrong_param_min_period():
object,
pytest.param(
"string[pyarrow_numpy]",
marks=pytest.mark.skipif(pa_version_under7p0, reason="arrow not installed"),
marks=pytest.mark.skipif(
pa_version_under10p1, reason="arrow not installed"
),
),
],
)
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/groupby/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ def test_groupby_empty(self):
# check name
assert s.groupby(s).grouper.names == ["name"]

def test_groupby_level_index_value_all_na(self):
def test_groupby_level_index_value_all_na(self, using_infer_string):
# issue 20519
df = DataFrame(
[["x", np.nan, 10], [None, np.nan, 20]], columns=["A", "B", "C"]
Expand All @@ -819,7 +819,7 @@ def test_groupby_level_index_value_all_na(self):
columns=["C"],
dtype="int64",
)
tm.assert_frame_equal(result, expected)
tm.assert_frame_equal(result, expected, check_index_type=not using_infer_string)

def test_groupby_multiindex_level_empty(self):
# https://github.com/pandas-dev/pandas/issues/31670
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/groupby/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def test_max_min_non_numeric():
assert "ss" in result


def test_max_min_object_multiple_columns(using_array_manager):
def test_max_min_object_multiple_columns(using_infer_string):
# GH#41111 case where the aggregation is valid for some columns but not
# others; we split object blocks column-wise, consistent with
# DataFrame._reduce
Expand All @@ -345,7 +345,9 @@ def test_max_min_object_multiple_columns(using_array_manager):
}
)
df._consolidate_inplace() # should already be consolidate, but double-check
if not using_array_manager:
if using_infer_string:
assert len(df._mgr.blocks) == 3
else:
assert len(df._mgr.blocks) == 2

gb = df.groupby("A")
Expand Down

0 comments on commit 7c400e7

Please sign in to comment.