0

When pass two dataframe obj into the func.It goes right. While using partial, it says:

TypeError: fall() got multiple values for argument 'dfn'

Here is the test code? Any one knows why?

from functools import partial
from multiprocessing import Pool 
import pandas as pd

def fall(dfn,x):
    return dfn,x


if __name__ == "__main__":
    df=pd.DataFrame([['a'],['b']])
    dfxn=pd.DataFrame([['c'],['d']])

    print(fall(dfxn,df))
    f=partial(fall,dfn=dfxn)
    print(f(df))

In addtion, It goes right when

f=partial(fall,x=dfxn)
print(f(df))
WilsonF
  • 85
  • 6
  • It's not working for the same reason `fall(dfxn, dfn=df)` won't work, there is both a positional and keyword argument for dfn. Try changing the last line to `print(f(x=df))`. – kmac Dec 26 '18 at 16:13
  • Then if I want to push the f=partial(fall,dfn=dfxn) into a multiprocess pool. How shall I call it ? – WilsonF Dec 29 '18 at 08:01
  • from functools import partial from multiprocessing import Pool import pandas as pd def fall(dfn,x): return dfn,x if __name__ == "__main__": df=pd.DataFrame([['a'],['b']]) dfxn=pd.DataFrame([['c'],['d']]) pool=Pool(2) f=partial(fall,dfn=dfxn) pool.map(f,[df,df]) #how to put df into f(x)? it can only send df to first argument to dfn? pool.close() pool.join() – WilsonF Dec 29 '18 at 08:10
  • `pool.map(f,[df,df])` or `pool.map(f,x=[df,df])` may raise errors. – WilsonF Dec 29 '18 at 08:31
  • Probably the easiest way is to switch the argument order so your partial application can use positional arguments. Otherwise you can do the partial with a lambda instead. – kmac Dec 30 '18 at 14:43

0 Answers0