Attribute Error while unpickling sklearn object

What I’m trying to do:
I am trying to unpickle a file that I have imported via data table. This is a pickle file that I am successfully able to unpickle in my local script.

Code Sample:

    cv = app_tables.table_1.get(text="cv")['media'].get_bytes()
    cv = pickle.loads(cv)
    my_post = "THIS IS A TEST"
    c = cv.transform([tokeniser(my_post)])

Error Message:
AttributeError: Can't get attribute 'dummy_fn' on <module 'anvil_downlink_worker.full_python_worker' from '/home/anvil/.downlink-sources/downlink-2022-10-05-15-15-26/anvil_downlink_worker/full_python_worker.py'>

  • at an_server, line 954 ← this is the last line of the code sample

What I’ve tried and what’s not working:
I have tried adding the below line but it did not fix the issue:
dummy_fn = lambda x:x

I haven’t used Pickle, having been warned away from it in many places – including Python’s own documentation. (A Google search will find them for you.)

The pickling process is notoriously fickle. The slightest difference in how a class is defined, at the point where loads is called, can result in failure or an unusable result.

Based purely on those warnings, I strongly suspect that this is what’s happened here. One or more of the classes or supporting functions referenced in the file is defined differently – or not at all – versus the definitions in effect at the time and place where the file was created.

1 Like