diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7dcb950d279fe..92c10df3e4e97 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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/ diff --git a/pandas/core/internals/array_manager.py b/pandas/core/internals/array_manager.py index 1dae3d586a0a9..2177839eb34ce 100644 --- a/pandas/core/internals/array_manager.py +++ b/pandas/core/internals/array_manager.py @@ -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]) diff --git a/pandas/tests/apply/test_frame_apply.py b/pandas/tests/apply/test_frame_apply.py index 8cebe1a888b77..227037ecba664 100644 --- a/pandas/tests/apply/test_frame_apply.py +++ b/pandas/tests/apply/test_frame_apply.py @@ -1435,9 +1435,10 @@ 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)}) + df_orig = df.copy() def func(row): mgr = row._mgr @@ -1451,7 +1452,12 @@ 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 + tm.assert_frame_equal(df, result) + else: + tm.assert_frame_equal(df, df_orig) def test_apply_empty_list_reduce(): diff --git a/pandas/tests/apply/test_frame_transform.py b/pandas/tests/apply/test_frame_transform.py index 212a54b78dead..1a12cbff47092 100644 --- a/pandas/tests/apply/test_frame_transform.py +++ b/pandas/tests/apply/test_frame_transform.py @@ -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": diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index afde1daca74c1..12247e2445295 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -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))