Skip to content

Commit 27550e8

Browse files
authored
BUG: taking slices in _slice_take_blocks_ax0 (#34421)
1 parent 0650c0b commit 27550e8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

pandas/core/internals/managers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,8 @@ def _slice_take_blocks_ax0(
13371337
# When filling blknos, make sure blknos is updated before appending to
13381338
# blocks list, that way new blkno is exactly len(blocks).
13391339
blocks = []
1340-
for blkno, mgr_locs in libinternals.get_blkno_placements(blknos, group=True):
1340+
group = not only_slice
1341+
for blkno, mgr_locs in libinternals.get_blkno_placements(blknos, group=group):
13411342
if blkno == -1:
13421343
# If we've got here, fill_value was not lib.no_default
13431344

pandas/tests/frame/test_arithmetic.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,3 +1514,16 @@ def test_dataframe_series_extension_dtypes():
15141514
tm.assert_frame_equal(result, expected)
15151515
result = df_ea + ser.astype("Int64")
15161516
tm.assert_frame_equal(result, expected)
1517+
1518+
1519+
def test_dataframe_blockwise_slicelike():
1520+
# GH#34367
1521+
arr = np.random.randint(0, 1000, (100, 10))
1522+
df1 = pd.DataFrame(arr)
1523+
df2 = df1.copy()
1524+
df2.iloc[0, [1, 3, 7]] = np.nan
1525+
1526+
res = df1 + df2
1527+
1528+
expected = pd.DataFrame({i: df1[i] + df2[i] for i in df1.columns})
1529+
tm.assert_frame_equal(res, expected)

0 commit comments

Comments
 (0)