Python and GitHub/stackoverflow newbie here, trying to speed up my workflow in Python using joblib and multiprocessing for the first time.
I have defined an empty OrderedDict to store the DataFrames generated by a function (my_function). The function takes in the elements of the column of a separate DataFrame, performs some operations, and is supposed to return the (hopefully filled) OrderedDict and another DataFrame.
Allow me to provide some pseudo-code to explain this:
from joblib import Parallel, delayed
from collections import OrderedDict
from tqdm import tqdm
import pandas as pd
import multiprocessing
my_dict = OrderedDict()
my_df = DataFrameofvalues
def my_function(k):
my_dict[k] = someoperationswithpandasresultinginDataFrames
my_df = someooperationswithpandas
return my_dict, my_df
num_cores = multiprocessing.cpu_count()
inputs = tqdm(my_df['my_column'])
if __name__ == '__main__':
my_dict, my_df = Parallel(n_jobs = num_cores)(delayed(my_function)(k for k in inputs)
This results in the following error:
File "<ipython-input-52-df771b916ba5>", line 8, in <module>
my_dict, my_df = Parallel(n_jobs = num_cores)(delayed(my_function)(k) for k in inputs)
ValueError: too many values to unpack (expected 2)
I think I've overlooked something minor, but I just can't find it. Could somebody perhaps take a look and help me out?
I haven't been able to find much online on how to figure out how many values my function is trying to unpack, exactly (I'm guessing the number of elements in inputs?) or if it's giving me all the DataFrames that are supposed to be going into the OrderedDict, all at once.
Thanks, much appreciated!
Edit based on further troubleshooting:
I think I know where the problem is coming from: the function is iterating through inputs and simply generating dataframes, which it then cannot put together as a dict, which it expects. I figured this out by setting inputs = tqdm(my_df.loc[0:1, 'my_column']). It works when I do this, but fails to unpack if I set it to inputs = tqdm(my_df.loc[0:2, 'my_column']). No solutions thus far though.