How to solve "Can't pickle local object" error in using pandarallel

Viewed 1912

I am trying to use the pandarallel module to speed-up my apply functions in pandas. When I run the example provided on the git page of pandarallel I get the following error: AttributeError: Can't pickle local object 'prepare_worker..closure..wrapper'

This is my code:

from pandarallel import pandarallel
import pandas as pd
import numpy as np
import math

pandarallel.initialize(nb_workers=4)

df_size = int(5e6)
df = pd.DataFrame(dict(a=np.random.randint(1, 8, df_size),
                       b=np.random.rand(df_size)))

def func(x):
    return x

res_parallel = df.parallel_apply(func, axis=1)
1 Answers

It is a known issue: https://github.com/nalepae/pandarallel/issues/72

There is also the solution posted by C1ARKGABLE. Use a new virtual environment with the following packages with python 3.7.3:

  • numpy 1.17.4
  • pandarallel 1.4.6
  • pandas 0.25.3

Personal remark: pickle and pandas do not play well together. Avoid if possible.

Related