0

I have a function that takes a GeoSeries as input and returns a value. When I call said function over all rows in a large geodataframe (gdf) with gdf.apply(), setting the output as a new column in the dataframe, it works:

# successful:
gdf = gpd.read_file(inShp)
gdf['output_column'] = gdf.apply(lambda f: myFunction(f, arg), axis = 1)

But when I try to split the dataframe up with dask_geopandas and call the same function:

# not successful:
ddf = dask_geopandas.from_geopandas(gdf, npartitions=2)
out = ddf.apply(lambda f: myFunction(f, arg), axis = 1, meta=metaArg)
comp = out.compute()

I get this error:

AttributeError: 'GeoDataFrame' object has no attribute 'name'

The same error occurs when metaArg = ddf; ddf._meta; or gdf.

If my function is something simple such as the following, I still get the same error on out.compute():

def myFunction(gs):

    return len(gs)

What am I doing wrong?

2
  • can you try to make a reproducible example?
    – Shawn
    Commented Sep 14, 2022 at 0:37
  • The value passed to metaArg might be wrong? (I suppose it expects a Series and not a DataFrame, that could explain the error)
    – joris
    Commented Oct 26, 2022 at 23:32

1 Answer 1

0

As if happens, adding this line before setting ddf makes it work. Seems like a bug?

gdf['name'] = 'name'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.