Skip to content

BUG: Type error in groupby.transform(interpolate) #45802

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
3 tasks done
hliatrussellinvestments opened this issue Feb 3, 2022 · 3 comments
Closed
3 tasks done

BUG: Type error in groupby.transform(interpolate) #45802

hliatrussellinvestments opened this issue Feb 3, 2022 · 3 comments

Comments

@hliatrussellinvestments
Copy link

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 numpy as np
import pandas as pd

np.random.seed(500)
test_df = pd.DataFrame({
    'a': np.random.randint(low=0, high=1000, size=10000),
    'b': np.random.choice([1, 2, 4, 7, np.nan], size=10000, p=([0.2475] * 4 + [0.01]))
})
test_df.groupby('a').transform(pd.DataFrame.interpolate)

Issue Description

When I want to interpolation of some columns (column ‘b’ in example) in a data frame according to some other columns (column ‘a’ in example), I group by the accorded columns (column ‘a’ in example) and then transform the group using the interpolate method.
It worked in version 1.1.1.

Expected Behavior

The nan values in column ‘b’ should be replaced by interpolated value according to column ‘a’.

Installed Versions

INSTALLED VERSIONS

commit : bb1f651
python : 3.8.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 13, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252
pandas : 1.4.0
numpy : 1.19.0
pytz : 2021.3
dateutil : 2.8.1
pip : 21.3.1
setuptools : 49.2.1
Cython : None
pytest : 5.4.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.1
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : 2021.10.0
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.5.4
sqlalchemy : 1.4.31
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None

@hliatrussellinvestments hliatrussellinvestments added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 3, 2022
@jbrockmendel
Copy link
Member

If you look at the full traceback, you'll see the problem is that pd.DataFrame.interpolate is the wrong method to pass. Try pd.Series.interpolate instead.

@mroeschke
Copy link
Member

Correct, the internals were refactored since 1.1 to fix bugs related to 2D processing therefore passing in pd.Series.interpolate works instead

In [6]: import numpy as np
   ...: import pandas as pd
   ...:
   ...: np.random.seed(500)
   ...: test_df = pd.DataFrame({
   ...:     'a': np.random.randint(low=0, high=1000, size=10000),
   ...:     'b': np.random.choice([1, 2, 4, 7, np.nan], size=10000, p=([0.2475] * 4 + [0.01]))
   ...: })
   ...: test_df.groupby('a').transform(pd.Series.interpolate)
Out[6]:
        b
0     4.0
1     1.0
2     2.0
3     7.0
4     4.0
...   ...
9995  4.0
9996  7.0
9997  4.0
9998  4.0
9999  4.0

[10000 rows x 1 columns]

@mroeschke mroeschke added Groupby Usage Question and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 11, 2022
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Feb 11, 2022
@simonjayhawkins
Copy link
Member

Correct, the internals were refactored since 1.1 to fix bugs related to 2D processing therefore passing in pd.Series.interpolate works instead

hmm, looks like first bad commit: [a395185] Deprecate passing args as positional in DataFrame/Series.interpolate (#41510)

So previously DataFrame/Series.interpolate were the same function and was changed in pandas 1.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants