AttributeError: 'AsyncResult' object has no attribute 'head'

AttributeError: 'AsyncResult' object has no attribute 'head'

In my file the error throwing at data = df.head(50) when i'm running and retrive the data as asynchronous background task.
Could anybody help me here?

def eda_flow_task(path, mode):
        with, mode) as f:
            df = pd.read_csv(f, low_memory=False)
        return 'data load success'
    except Exception as e:
        response_dict.update({'error': str(e)})

def eda_flow(request):
    path = '/data/satyajit/us_amz.csv'
    mode = 'rb'
    df = eda_flow_task.delay(path, mode)
    data = df.head(50)
    json_records = data.reset_index().to_json(orient ='records')
    data = []
    data = json.loads(json_records)
    context = {'data': data}
    return render(request, "home/tables-simple.html", context)

The following statement is wrong: df = eda_flow_task.delay(path, mode) delay() returns AsyncResult, not Pandas data-frame... I am not even sure you can return data frame as it probably is not serializable. I certainly never tried it so I do not know. In the case it is as I suspect (not serializable), you should return an object of type that is serializable, like a list of objects for an example.

Your task actually returns a string data load success or None in case of an exception.

In order to get result of Celery task you need to do the following:

res = eda_flow_task.delay(path, mode).get()  # NOTE: this blocks!

As mentioned above, res will most likely end up being a hard-coded string.

Back to Top