File tree 3 files changed +22
-0
lines changed
3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ Fixed regressions
21
21
- Fixed regression in :class: `pandas.core.groupby.RollingGroupby ` where column selection was ignored (:issue: `35486 `)
22
22
- Fixed regression in :meth: `DataFrame.shift ` with ``axis=1 `` and heterogeneous dtypes (:issue: `35488 `)
23
23
- Fixed regression in ``.groupby(..).rolling(..) `` where a segfault would occur with ``center=True `` and an odd number of values (:issue: `35552 `)
24
+ - Fixed regression in :meth: `DataFrame.apply ` where functions that altered the input in-place only operated on a single row (:issue: `35462 `)
24
25
25
26
.. ---------------------------------------------------------------------------
26
27
Original file line number Diff line number Diff line change @@ -389,6 +389,8 @@ def series_generator(self):
389
389
blk = mgr .blocks [0 ]
390
390
391
391
for (arr , name ) in zip (values , self .index ):
392
+ # GH#35462 re-pin mgr in case setitem changed it
393
+ ser ._mgr = mgr
392
394
blk .values = arr
393
395
ser .name = name
394
396
yield ser
Original file line number Diff line number Diff line change @@ -1522,3 +1522,22 @@ def test_apply_dtype(self, col):
1522
1522
expected = df .dtypes
1523
1523
1524
1524
tm .assert_series_equal (result , expected )
1525
+
1526
+
1527
+ def test_apply_mutating ():
1528
+ # GH#35462 case where applied func pins a new BlockManager to a row
1529
+ df = pd .DataFrame ({"a" : range (100 ), "b" : range (100 , 200 )})
1530
+
1531
+ def func (row ):
1532
+ mgr = row ._mgr
1533
+ row .loc ["a" ] += 1
1534
+ assert row ._mgr is not mgr
1535
+ return row
1536
+
1537
+ expected = df .copy ()
1538
+ expected ["a" ] += 1
1539
+
1540
+ result = df .apply (func , axis = 1 )
1541
+
1542
+ tm .assert_frame_equal (result , expected )
1543
+ tm .assert_frame_equal (df , result )
You can’t perform that action at this time.
0 commit comments