groupby.parallel_apply not working int Pandas 2.0
General
- Operating System: Max
- Python version: 3.11
- Pandas version: 2.0.0
- Pandarallel version: 1.6.4
Acknowledgement
- [X ] My issue is NOT present when using
pandasalone (withoutpandarallel) - [ ] If I am on Windows, I read the Troubleshooting page before writing a new bug report
Bug description
When I use groupby.apply it works, but parallel_apply it does not. I'm assuming it's the new version of Pandas... AttributeError: 'DataFrameGroupBy' object has no attribute 'mutated'
Observed behavior
Write here the observed behavior
ttributeError Traceback (most recent call last) Cell In[20], line 4 1 from pandarallel import pandarallel 3 pandarallel.initialize(use_memory_fs=False) ----> 4 df.groupby('h_col').parallel_apply(simp_pred)
File /usr/local/lib/python3.11/site-packages/pandarallel/core.py:446, in parallelize_with_pipe.
File /usr/local/lib/python3.11/site-packages/pandarallel/data_types/dataframe_groupby.py:82, in DataFrameGroupBy.Apply.reduce(datas, extra) 77 mutated = cast(List[bool], mutated) 79 args = get_args(keys, values, df_groupby) 81 return df_groupby._wrap_applied_output( ---> 82 *args, not_indexed_same=df_groupby.mutated or mutated 83 )
File /usr/local/lib/python3.11/site-packages/pandas/core/groupby/groupby.py:952, in GroupBy.getattr(self, attr) 949 if attr in self.obj: 950 return self[attr] --> 952 raise AttributeError( 953 f"'{type(self).name}' object has no attribute '{attr}'" 954 )
AttributeError: 'DataFrameGroupBy' object has no attribute 'mutated'
Expected behavior
Write here the expected behavior
Minimal but working code sample to ease bug fix for pandarallel team
from pandarallel import pandarallel import pandas as pd import numpy as np
df = pd.DataFrame({ 'h_col': ['A'] * 4 + ['B'] * 4, 'ts_data': [np.nan, 2, 3, 4] * 2, 'time_col': pd.date_range("2018-01-01", periods=4, freq="w").to_list() * 2} )
def simp_pred(df): fcst = df.iloc[3:4, :] fcst.loc[:, 'fcst'] = 1 return fcst
This works
df.groupby('h_col').apply(simp_pred)
This does not
pandarallel.initialize(use_memory_fs=False) df.groupby('h_col').parallel_apply(simp_pred)
In dataframe_groupby.py line 81 this worked for me. I couldn't push the branch and open a pr for some reason.
pandas_version = get_pandas_version()
if pandas_version < (2, 0):
return df_groupby._wrap_applied_output(
*args, not_indexed_same=df_groupby.mutated or mutated
)
else:
return df_groupby._wrap_applied_output(
*args, not_indexed_same=mutated
)
i think i have the same issue
Python version: 3.10.8 Pandas version: 2.0.0 Pandarallel version: 1.6.4
Error message: 'DataFrameGroupBy' object has no attribute 'mutated'
Traceback:
df.parallel_apply( File "/usr/local/lib/python3.10/site-packages/pandarallel/core.py", line 446, in closure progress_bar=False, File "/usr/local/lib/python3.10/site-packages/pandarallel/data_types/dataframe_groupby.py", line 82, in reduce *args, not_indexed_same=df_groupby.mutated or mutated File "/usr/local/lib/python3.10/site-packages/pandas/core/groupby/groupby.py", line 952, in getattr raise AttributeError( AttributeError: 'DataFrameGroupBy' object has no attribute 'mutated'
Is it the same issue?
Fixed in #235, just need to get that released and it should be solved. Thanks for reporting the bug @AymanElsayeed and the fix @alexrblohm!
Thank you so much!
@till-m, thank you, when this will be merged?
@nalepae when you are planning on pushing the next release?
I can do it today.
Do you want the ability to do it too?
Hi @nalepae
I'm waiting for this; if you need help merging this change, I'll gladly help.
When is the next release date?
Hey @AymanElsayeed, this should be up already (v1.6.5). Do you still run into the same problem? Can you please check and make sure you're using version 1.6.5?
@nalepae, I think it's fine the way it is currently.
@till-m this is working, yes, in 1.6.5. Thanks