Description
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