Repository navigation
Open
Labels
arrayneeds attentionIt's been a while since this was pushed on. Needs attention from the owner or a maintainer.needs infoNeeds further information from the user
Description
When I call map_partitions on my accessor, get some unexpected issues.
The first partition has data that is unrelated to the rest of my data. This is causing issues performing type specific data. How do I do I account for this first group of data? It appears the first group is the set of data from the registration of the make_nonempty.register call.
@make_array_nonempty.register(GeoType)
def _(dtype):
a = np.array([_default_geometry(), _default_geometry()], dtype=object)
return _from_geometry(a)
Is there a tag stating this is metadata? I don't want map_partitions to look at this chunk.
SHAPE fielda b
0 {"x": 0, "y": 0, "spatialReference": {"wkid": ... 1 1
1 {"x": 0, "y": 0, "spatialReference": {"wkid": ... 1 1
SHAPE fielda b
8 {"curveRings": [[[-35.09392053986361, 7.573204... 2729 2
9 {"curveRings": [[[7.505218982136703, 18.358753... 5387 2
SHAPE fielda b
2 {"curveRings": [[[35.51113767361919, 12.957382... 9575 2
3 {"curveRings": [[[-18.30138894072785, -16.9425... 9151 2
SHAPE fielda b
6 {"curveRings": [[[-21.068573113681047, 33.0624... 2846 2
7 {"curveRings": [[[-36.53534927307355, 7.872075... 4623 2
SHAPE fielda b
0 {"curveRings": [[[-21.43621100432236, 1.310434... 1708 2
1 {"curveRings": [[[-11.702427410357348, 30.1368... 9153 2
SHAPE fielda b
4 {"curveRings": [[[33.74060870013736, 40.225838... 828 2
5 {"curveRings": [[[-1.1111195840167558, -20.320... 4718 2I need the operation to skip this snippet below:
SHAPE fielda b
0 {"x": 0, "y": 0, "spatialReference": {"wkid": ... 1 1
1 {"x": 0, "y": 0, "spatialReference": {"wkid": ... 1 1I think a solution could be to use get_partitions but I think this would prevent the distribution of code to fail. Any solutions welcome.
UPDATE 1:
This only occurs is meta isn't specified on the map_partitions, but the custom type can't be understood...
Thank you
Metadata
Metadata
Assignees
Labels
arrayneeds attentionIt's been a while since this was pushed on. Needs attention from the owner or a maintainer.needs infoNeeds further information from the user
Activity
achapkowski commentedon Mar 12, 2021
The custom dtype is defined as:
Where Geometry is a base class that all other Geometries inherit from.
When given to
metaonmap_partitions, I get the following errors now:What needs to be added to the Panda's registered data type for it to work in Dask?
jsignell commentedon Mar 15, 2021
What happens if you pass in a dataframe that looks like the expected output ? So for
metain map_partitions set something likedf.head()ordf.partitions[1].head()if that is more representative.jsignell commentedon Mar 15, 2021
Actually I'm wondering if this is a manifestation of #7375
achapkowski commentedon Mar 15, 2021
If you pass what the data should look like, and it doesn't match the input, it will fail. One solution I found was to set
enforce_metadata=False.gjoseph92 commentedon Mar 15, 2021
@jsignell yes, I believe this is related to #7375. Basically right now, dask does not support
map_partitionswith a function that returns a pandas ExtensionArray. If it's going to return an array-like, it must return a NumPy array.Note that #7375 will not resolve this in general; it'll just make
.valueson such a Series with an ExtensionDtype work. The fix for the issue in generality should only be a few lines, but it breaks other tests in weird ways, so I'd like to handle it separately.@achapkowski, it seems here that you're trying to turn your dask DataFrame into a dask Array, where the chunks are GeoArrays? If you could share the function you're passing to
map_partitions, that could be helpful. I'm having trouble interpreting the output you've posted. Also, is that output what you see when you callcompute, or what you see when you callmap_partitions(as your function gets called on themetaarray), or some of both?achapkowski commentedon Mar 15, 2021
The output is the partitions of data being send to each client. The first chunk is a Point dataset which is derived from this:
Where the default geometry is:
The output for these calls is a DataFrame. I am performing operations like spatial joins or performing overlay operations like select by location (intersection operation). In the case of the
spatial join, there are cases where DataFrame A and DataFrame B can have the same schema. So I allow for a _left and _right tags. This modifies the schema and the output can be different than the input.gjoseph92 commentedon Mar 15, 2021
How are you seeing this? Print statements in the function you're passing to
map_partitions? Again, if you could share the code for the function you're passing tomap_partitions, that would be very helpful.You may already know this, but
map_partitionsworks by first calling your function on a "dummy" pandas DataFrame—in this case, the one produced by your@make_array_nonempty.register(GeoType)function. This happens immediately when you callmap_partitions, not when you callcompute.So basically, if you have a
printstatement in your mapper function, which is printing out each partition, it's expected behavior to see it getting called on thePoint({'x' : 0, 'y' : 0, 'spatialReference' : {'wkid' : 4326}})"dummy" values. Just because you see that printed doesn't mean that the Point is actually data in your DataFrame.The docs on DataFrame metadata might be helpful here: https://docs.dask.org/en/latest/dataframe-design.html#metadata
It sounds like the real issue here is that your mapper function can't handle the "dummy" data you've specified (perhaps you're using a function which can't handle
Points, onlyCurveRings?):There's nothing dask can really do to help able to handle this data. I'd say you should either a) add some
ifstatements to your mapper function to be able to handle the different data types correctly, or b) change yourmake_array_nonemptyfunction to return something more representative of the type of data you'll actually be using (put aCurveRingin it instead of aPoint, for example).Alternatively, as you saw, you can pass a
meta. It sounds to me like you tried passingGeoTypeor aGeoArrayinstance as meta, and that broke (this is the bug related to #7375). However, if the output is supposed to be a DataFrame, then aGeoArrayis actually the wrongmetatype, since that implies the result should be an Array. Instead, yourmetashould be a pandas DataFrame, where some of the columns have the dtypeGeoType. Or, if your function doesn't change the columns/types at all, you can just pass the original DataFrame for convenience:ddf.map_partitions(my_mapper, ..., meta=ddf). See themake_metaandmap_partitionsdocumentation for more details here.achapkowski commentedon Mar 16, 2021
Where
partwould be a pd.DataFrame,part.spatialis a custom Pandas' accessor, and self._sfn_method would be:This allows me to perform a spatial join on each partition for the dask dataframe, or at least that is the thought.
gjoseph92 commentedon Mar 19, 2021
What is
right_dfin this case? Apd.DataFrameor a dask DataFrame? (I don't think a dask DataFrame will work.)I'm still unclear on what the issue is.
Is this accurate? Is the problem that
joinis failing on your dummy data that contains Points?