Skip to content

BUG: apply behaviour changed when using function that returns tuple #36042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 of 3 tasks
martijnvanattekum opened this issue Sep 1, 2020 · 3 comments
Closed
2 of 3 tasks
Labels
Duplicate Report Duplicate issue or pull request

Comments

@martijnvanattekum
Copy link

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

import seaborn as sns
import pandas as pd
import numpy as np

def get_mean_sd(column):
    return np.mean(column), np.std(column)

iris = sns.load_dataset("iris")[["sepal_length", "sepal_width", "petal_length", "petal_width"]]
iris.apply(get_mean_sd)

Problem description

In version 1.0, the result was a pandas series of tuples, whereas in 1.1 the result is a data frame, thus breaking existing code that depends on apply.

The result from 1.1 is

   sepal_length  sepal_width  petal_length  petal_width
0      5.843333     3.057333      3.758000     1.199333
1      0.825301     0.434411      1.759404     0.759693

Expected Output

The output from version 1.0 was:

sepal_length     (5.843333333333334, 0.8253012917851409)
sepal_width     (3.0573333333333337, 0.4344109677354946)
petal_length     (3.7580000000000005, 1.759404065775303)
petal_width     (1.1993333333333336, 0.7596926279021594)
dtype: object

Output of pd.show_versions()

For 1.0.3:
INSTALLED VERSIONS

commit : None
python : 3.8.2.final.0
python-bits : 64
OS : Linux
OS-release : 3.10.0-1127.18.2.el7.x86_64
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : en_US.utf-8
LANG : en_US.utf-8
LOCALE : en_US.UTF-8

pandas : 1.0.3
numpy : 1.18.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.0.2
setuptools : 46.4.0.post20200518
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.13.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.2.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None

For 1.1.1:
INSTALLED VERSIONS

commit : f2ca0a2
python : 3.8.2.final.0
python-bits : 64
OS : Linux
OS-release : 3.10.0-1127.18.2.el7.x86_64
Version : #1 SMP Sun Jul 26 15:27:06 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : en_US.utf-8
LANG : en_US.utf-8
LOCALE : en_US.UTF-8

pandas : 1.1.1
numpy : 1.18.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.0.2
setuptools : 46.4.0.post20200518
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.13.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.2.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@martijnvanattekum martijnvanattekum added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 1, 2020
@jbrockmendel
Copy link
Member

This looks like a duplicate of #35518. @martijnvanattekum is that correct?

@martijnvanattekum
Copy link
Author

martijnvanattekum commented Sep 1, 2020 via email

@simonjayhawkins
Copy link
Member

closing as duplicate

@simonjayhawkins simonjayhawkins added Duplicate Report Duplicate issue or pull request and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

3 participants