Skip to content

BUG: the behavior of DataFrameGroupBy.apply(..., include_groups=True) breaks post-mortem debugging #61627

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

Open
2 of 3 tasks
pulkin opened this issue Jun 10, 2025 · 0 comments
Open
2 of 3 tasks
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@pulkin
Copy link

pulkin commented Jun 10, 2025

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

def f(df):
    df["group"]
    raise TypeError("a very subtle bug")

pd.DataFrame({"group": ["a", "a", "b", "b"], "data": [0, 1, 2, 3]}).groupby("group").apply(f)

Issue Description

The argument in the title and the corresponding behavior is described like this:

When True, will attempt to apply func to the groupings in the case that they are columns of the DataFrame.
If this raises a TypeError, the result will be computed with the groupings excluded. When False,
the groupings will be excluded when applying func.

https://pandas.pydata.org/docs/reference/api/pandas.core.groupby.DataFrameGroupBy.apply.html

I think the described behavior is problematic and it renders close to impossible to use post-mortem debugging for the TypeError("a very subtle bug"). pandas should not swallow TypeError hoping that developers will figure it out in a pile of logs.

Expected Behavior

There should be no "attempts" from the docs and pandas should not catch and swallow any exceptions from the payload.

Installed Versions

INSTALLED VERSIONS

commit : 2cc3762
python : 3.13.3
python-bits : 64
OS : Linux
OS-release : 6.14.9-300.fc42.x86_64
Version : #1 SMP PREEMPT_DYNAMIC Thu May 29 14:27:53 UTC 2025
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.3.0
numpy : 2.3.0
pytz : 2025.2
dateutil : 2.9.0.post0
pip : 24.3.1
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.5
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : 20.0.0
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.2
qtpy : None
pyqt5 : None

@pulkin pulkin added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

1 participant