Skip to content

[ArrayManager] TST: enable apply tests #40345

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 4 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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ jobs:
pytest pandas/tests/indexing/multiindex/test_setitem.py::TestMultiIndexSetItem::test_frame_setitem_multi_column

pytest pandas/tests/api/
pytest pandas/tests/apply/
pytest pandas/tests/arrays/
pytest pandas/tests/base/
pytest pandas/tests/computation/
Expand Down
1 change: 1 addition & 0 deletions pandas/core/internals/array_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ def insert(self, loc: int, item: Hashable, value, allow_duplicates: bool = False
raise ValueError(
f"Expected a 1D array, got an array with shape {value.shape}"
)
value = ensure_wrapped_if_datetimelike(value)

# TODO self.arrays can be empty
# assert len(value) == len(self.arrays[0])
Expand Down
7 changes: 5 additions & 2 deletions pandas/tests/apply/test_frame_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ def test_apply_dtype(col):
tm.assert_series_equal(result, expected)


def test_apply_mutating():
def test_apply_mutating(using_array_manager):
# GH#35462 case where applied func pins a new BlockManager to a row
df = DataFrame({"a": range(100), "b": range(100, 200)})

Expand All @@ -1451,7 +1451,10 @@ def func(row):
result = df.apply(func, axis=1)

tm.assert_frame_equal(result, expected)
tm.assert_frame_equal(df, result)
if not using_array_manager:
# INFO(ArrayManager) With BlockManager, the row is a view and mutated in place,
# with ArrayManager the row is not a view, and thus not mutated in place
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there anything we should be asserting in the AM case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the equivalent assert (but so asserting it didn't change) for AM

tm.assert_frame_equal(df, result)


def test_apply_empty_list_reduce():
Expand Down
9 changes: 8 additions & 1 deletion pandas/tests/apply/test_frame_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ def test_transform_ufunc(axis, float_frame, frame_or_series):


@pytest.mark.parametrize("op", frame_transform_kernels)
def test_transform_groupby_kernel(axis, float_frame, op):
def test_transform_groupby_kernel(axis, float_frame, op, using_array_manager, request):
# GH 35964
if using_array_manager and op == "pct_change" and axis in (1, "columns"):
# TODO(ArrayManager) shift with axis=1
request.node.add_marker(
pytest.mark.xfail(
reason="shift axis=1 not yet implemented for ArrayManager"
)
)

args = [0.0] if op == "fillna" else []
if axis == 0 or axis == "index":
Expand Down
7 changes: 6 additions & 1 deletion pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,12 @@ def test_omit_nuisance(df):

# won't work with axis = 1
grouped = df.groupby({"A": 0, "C": 0, "D": 1, "E": 1}, axis=1)
msg = "reduction operation 'sum' not allowed for this dtype"
msg = "|".join(
[
"reduction operation 'sum' not allowed for this dtype",
"'DatetimeArray' does not implement reduction 'sum'",
]
)
with pytest.raises(TypeError, match=msg):
grouped.agg(lambda x: x.sum(0, numeric_only=False))

Expand Down