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: pd.DataFrame.transform recursively loops in some cases #34224

Closed
2 of 3 tasks
adamczykm opened this issue May 17, 2020 · 5 comments · Fixed by #34377
Closed
2 of 3 tasks

BUG: pd.DataFrame.transform recursively loops in some cases #34224

adamczykm opened this issue May 17, 2020 · 5 comments · Fixed by #34377
Labels
Apply Apply, Aggregate, Transform Bug Error Reporting Incorrect or improved errors from pandas
Milestone

Comments

@adamczykm
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.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

pd.DataFrame({"a":[None]}).transform({"a":int})

Problem description

Executing the above causes recursion depth limit exception. This is confusing and it is harder to pinpoint/debug than the expected exception.

Expected Output

Something akin to the output of int(None)

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit : None python : 3.7.5.final.0 python-bits : 64 OS : Darwin OS-release : 18.6.0 machine : x86_64 processor : i386 byteorder : little LC_ALL : None LANG : None LOCALE : None.UTF-8

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

@adamczykm adamczykm added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 17, 2020
@charlesdong1991
Copy link
Member

charlesdong1991 commented May 17, 2020

thanks for the report, and would be nicer to have a descriptive issue title!

@charlesdong1991 charlesdong1991 added Groupby and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 17, 2020
@MarcoGorelli MarcoGorelli added the Error Reporting Incorrect or improved errors from pandas label May 17, 2020
@pedrooa
Copy link
Contributor

pedrooa commented May 17, 2020

hi, can i take this?

@mroeschke mroeschke added Apply Apply, Aggregate, Transform and removed Groupby labels May 18, 2020
@charlesdong1991
Copy link
Member

sure, go ahead! @pedrooa

@adamczykm adamczykm changed the title BUG: BUG: pd.DataFrame.transform recursively loops in some cases May 18, 2020
@dsaxton
Copy link
Member

dsaxton commented May 19, 2020

@pedrooa Looks like the problem is the the try / except within aggregate of frame.py, would be interesting to look into why that's needed and if there's a better way to handle things

@pedrooa
Copy link
Contributor

pedrooa commented May 21, 2020

I've looked into the try / except you mentioned(within aggregate of frame.py), and the recurssion occurs because the except is not doing anything with the error:

try:
    result, how = self._aggregate(func, axis=axis, *args, **kwargs)
except TypeError:
    pass

I've managed to fix it raising an error printing what went wrong, as in the following code:

try:
    result, how = self._aggregate(func, axis=axis, *args, **kwargs)
except TypeError as err:
    exc = TypeError(
                    "DataFrame constructor called with "
                    f"incompatible data and dtype: {err}"
                )
    raise exc from err

I am now just making sure this fix doesn't break anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform Bug Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants