Skip to content

Commit

Permalink
🐛 Fix erroneous concat when n_chunks=1 on axis=1 apply (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelange committed Feb 17, 2021
1 parent 8f966a4 commit 0306dfb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/mapply/mapply.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ def run_apply(func, df_or_series, args=(), **kwargs):
progressbar=progressbar,
)

if not isseries and results[0].index.equals(df_or_series.index):
if (
not isseries
and len(results) > 1
and results[0].index.equals(df_or_series.index)
):
return concat(results, axis=1, copy=False)

return concat(results, copy=False)
8 changes: 8 additions & 0 deletions tests/test_mapply.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ def test_df_mapply():
df.mapply(lambda x: x ** 2),
)

# concat for only one result
mapply.init(progressbar=False, chunk_size=100, n_workers=2)
df = pd.DataFrame(list(range(1, 200))) # (199, 1)
pd.testing.assert_series_equal(
df.apply(sum, axis=1),
df.mapply(sum, axis=1),
)


def test_series_mapply():
# chunk_size>1
Expand Down

0 comments on commit 0306dfb

Please sign in to comment.