Skip to content
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

BUG: DataFrame apply is swallowing exceptions #47966

Closed
2 of 3 tasks
emsi opened this issue Aug 4, 2022 · 1 comment
Closed
2 of 3 tasks

BUG: DataFrame apply is swallowing exceptions #47966

emsi opened this issue Aug 4, 2022 · 1 comment
Labels
Apply Apply, Aggregate, Transform, Map Bug Groupby

Comments

@emsi
Copy link

emsi commented Aug 4, 2022

Pandas version checks

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

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

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
df = pd.DataFrame(columns=["a", "b"])
df.apply(lambda x: 7/0, axis=1)

Out[5]: 
Empty DataFrame
Columns: [a, b]
Index: []
In [6]: df.apply(lambda x: undefined, axis=1)
Out[6]: 
Empty DataFrame
Columns: [a, b]
Index: []

The same seems to be true for any exception:

def e():
    raise Exception
df.apply(lambda x: e(), axis=1)
Out[9]: 
Empty DataFrame
Columns: [a, b]
Index: []

Issue Description

DataFrame apply() is quietly swallowing exceptions. It returns the DataFrame itself rather than propagating the error.

Please note that in previous versions of pandas (e.g. 0.24) this behavior was documented when reduce was None (default). However there is no mention of such behavior in documentation of current version.

Expected Behavior

En exception should be thrown or this behavior should be documented.

Installed Versions

INSTALLED VERSIONS

commit : e8093ba
python : 3.9.12.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-121-generic
Version : #137-Ubuntu SMP Wed Jun 15 13:33:07 UTC 2022
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : None
LOCALE : en_US.UTF-8
pandas : 1.4.3
numpy : 1.22.3
pytz : 2022.1
dateutil : 2.8.2
setuptools : 58.1.0
pip : 22.0.4
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.8.0
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.1
IPython : 8.2.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli : None
fastparquet : None
fsspec : 2022.3.0
gcsfs : None
markupsafe : 2.1.1
matplotlib : 3.5.1
numba : None
numexpr : 2.8.1
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.0
snappy : None
sqlalchemy : None
tables : 3.7.0
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : None
zstandard : None

@emsi emsi added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 4, 2022
@emsi emsi changed the title BUG: BUG: DataFrame apply swallows exceptions Aug 4, 2022
@emsi emsi changed the title BUG: DataFrame apply swallows exceptions BUG: DataFrame apply is swallowing exceptions Aug 4, 2022
@phofl
Copy link
Member

phofl commented Aug 4, 2022

Hi, thanks for your report. This is a duplicate of #41997

@phofl phofl closed this as completed Aug 4, 2022
@phofl phofl added Groupby Apply Apply, Aggregate, Transform, Map and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map Bug Groupby
Projects
None yet
Development

No branches or pull requests

2 participants