Skip to content

Commit 8d1d25a

Browse files
authored
🐛 Account for single-row to multi-row axis=0 apply (#23)
1 parent 3232bfd commit 8d1d25a

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

src/mapply/mapply.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ def run_apply(func, df_or_series, args=(), **kwargs):
117117
)
118118

119119
if (
120-
not isseries
121-
and len(results) > 1
122-
and results[0].index.equals(df_or_series.index)
120+
isseries
121+
or len(results) == 1
122+
or len(results[0]) * len(results) in df_or_series.shape
123123
):
124-
return concat(results, axis=1, copy=False)
124+
return concat(results, copy=False)
125125

126-
return concat(results, copy=False)
126+
return concat(results, axis=1, copy=False)

tests/test_mapply.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ def test_df_mapply():
6565
df.mapply(sum, axis=1),
6666
)
6767

68+
# single row dataframe turns into multi row dataframe with same columns
69+
mapply.init(progressbar=False, chunk_size=2, n_workers=2)
70+
pd.testing.assert_frame_equal(
71+
df.T.apply(lambda y: pd.Series(np.arange(10))),
72+
df.T.mapply(lambda y: pd.Series(np.arange(10))),
73+
)
74+
6875

6976
def test_series_mapply():
7077
# chunk_size>1

0 commit comments

Comments
 (0)