Skip to content

Commit b172a60

Browse files
[ArrayManager] TST: enable apply tests (#40345)
1 parent 7af47c9 commit b172a60

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ jobs:
169169
pytest pandas/tests/indexing/multiindex/test_setitem.py::TestMultiIndexSetItem::test_frame_setitem_multi_column
170170
171171
pytest pandas/tests/api/
172+
pytest pandas/tests/apply/
172173
pytest pandas/tests/arrays/
173174
pytest pandas/tests/base/
174175
pytest pandas/tests/computation/

pandas/core/internals/array_manager.py

+1
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,7 @@ def insert(self, loc: int, item: Hashable, value, allow_duplicates: bool = False
929929
raise ValueError(
930930
f"Expected a 1D array, got an array with shape {value.shape}"
931931
)
932+
value = ensure_wrapped_if_datetimelike(value)
932933

933934
# TODO self.arrays can be empty
934935
# assert len(value) == len(self.arrays[0])

pandas/tests/apply/test_frame_apply.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -1435,9 +1435,10 @@ def test_apply_dtype(col):
14351435
tm.assert_series_equal(result, expected)
14361436

14371437

1438-
def test_apply_mutating():
1438+
def test_apply_mutating(using_array_manager):
14391439
# GH#35462 case where applied func pins a new BlockManager to a row
14401440
df = DataFrame({"a": range(100), "b": range(100, 200)})
1441+
df_orig = df.copy()
14411442

14421443
def func(row):
14431444
mgr = row._mgr
@@ -1451,7 +1452,12 @@ def func(row):
14511452
result = df.apply(func, axis=1)
14521453

14531454
tm.assert_frame_equal(result, expected)
1454-
tm.assert_frame_equal(df, result)
1455+
if not using_array_manager:
1456+
# INFO(ArrayManager) With BlockManager, the row is a view and mutated in place,
1457+
# with ArrayManager the row is not a view, and thus not mutated in place
1458+
tm.assert_frame_equal(df, result)
1459+
else:
1460+
tm.assert_frame_equal(df, df_orig)
14551461

14561462

14571463
def test_apply_empty_list_reduce():

pandas/tests/apply/test_frame_transform.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,15 @@ def test_transform_ufunc(axis, float_frame, frame_or_series):
3939

4040

4141
@pytest.mark.parametrize("op", frame_transform_kernels)
42-
def test_transform_groupby_kernel(axis, float_frame, op):
42+
def test_transform_groupby_kernel(axis, float_frame, op, using_array_manager, request):
4343
# GH 35964
44+
if using_array_manager and op == "pct_change" and axis in (1, "columns"):
45+
# TODO(ArrayManager) shift with axis=1
46+
request.node.add_marker(
47+
pytest.mark.xfail(
48+
reason="shift axis=1 not yet implemented for ArrayManager"
49+
)
50+
)
4451

4552
args = [0.0] if op == "fillna" else []
4653
if axis == 0 or axis == "index":

pandas/tests/groupby/test_groupby.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,12 @@ def test_omit_nuisance(df):
840840

841841
# won't work with axis = 1
842842
grouped = df.groupby({"A": 0, "C": 0, "D": 1, "E": 1}, axis=1)
843-
msg = "reduction operation 'sum' not allowed for this dtype"
843+
msg = "|".join(
844+
[
845+
"reduction operation 'sum' not allowed for this dtype",
846+
"'DatetimeArray' does not implement reduction 'sum'",
847+
]
848+
)
844849
with pytest.raises(TypeError, match=msg):
845850
grouped.agg(lambda x: x.sum(0, numeric_only=False))
846851

0 commit comments

Comments
 (0)