You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
dataframe merge returns incorrect result when data is from multi-partition parquet #2730
Similar to issue #2237 , I am seeing dask dataframe merge result can be incorrect when data is from multi-partition parquet. pandas merge always produces correct results.
One example of missing row in ddf is KEY==135337982:
#dask merge result does not contain the row
ddf.loc[ddf.KEY==135337982].compute()
#Empty DataFrame
#Columns: [KEY, ID]
#Index: []
#pandas merge result contains the row
df.loc[df.KEY==135337982]
# KEY ID
#122842 135337982 149107799
Single-partition parquet works
#use nlargest to write to a single-partition parquet
ddf1.nlargest(n=505850,columns='KEY').to_parquet('keys_one_partition.parq')
ddf2.nlargest(n=1960255,columns='KEY').to_parquet('key_ids_one_partition.parq')
ddf1_one = dd.read_parquet('keys_one_partition.parq')
ddf2_one = dd.read_parquet('key_ids_one_partition.parq')
ddf_one = ddf1_one.merge(ddf2_one,how='inner',on='KEY')
len(ddf_one)
#505847
df_one = ddf1_one.compute().merge(ddf2_one.compute(),how='inner',on='KEY')
df_one.shape
#(505847, 2)
Hmmm, I get incorrect result with different schedulers, even with a single-threaded scheduler (get=dask.get). The only way that I can get the correct result is to do the merge with pandas dataframes.
To summarize it again, here are the different merges I have tried, and only pandas merge worked.
But if I don't init the client at all, the single-threaded scheduler returns the correct result (and a few times slower):
from dask.distributed import Client
import dask.dataframe as dd
import dask
############# do not init the distributed client ############### client = Client("localhost:9898")
ddf1 = dd.read_parquet("keys_133m.parq")
ddf2 = dd.read_parquet("key_ids_133m.parq")
ddf = ddf1.merge(ddf2,how='inner',on='KEY')
df = ddf.compute(get=dask.get)
print(df.loc[df.KEY==135337982])
#result:
# KEY ID
#62 135337982 149107799
In both cases, I checked the status bokeh app and scheduler and worker log, there didn't seem to be any activities with the local cluster.
Another that I noticed is that, with the client init'ed, the ddf.dask has 28044 tasks with len(ddf.dask), while without it the ddf.dask as only 4779 tasks.
So, the results seem to indicate that even though not used, a client to the local cluster affects the task graph, the correctness of the merge results as well as the speed. This is totally unexpected to me.
When dask.distributed starts up it changes the global shuffle mechanism from "disk" to "tasks". You can also control this with the dask.set_options(shuffle='tasks') context manager. It might be useful to try that out on your problem to see if you can recreate your issue without starting a client.
Interesting. If I make the "KEY" column as the index for both dask dataframes, then use join, the result would come out correct. It is slightly slower than doing merge directly due to the overhead of set_index.
If I persist the indexed dataframes and the non-indexed dataframes, the join on the indexed would be much faster than the merge on the non-indexed, with the additional benefit of the result being correct!
I tried to debug and pin-point the issue with the merge but haven't been able to get anywhere.
@brendancol I'm not working on it currently, nor is anyone that I know of. Generally people write on an issue when they start work. I agree that this is important. I don't personally plan to work on it any time in the next week or two. If anyone wants to take it on that would be great.
@mrocklin i am working on creating a reproducible example. I haven't been able to reproduce this issue outside of the production environment though. Will update this thread.
bump - Any news on this? I also find this issue very important because merge is a very common operation and forced to set the index first slows me down quite a bit.
It looks like this is waiting on a reproducible example that demonstrates the failure in a simple way. Perhaps you are able to provide such an example @dennis-ec ?
This is a really weird one. It appears that the task shuffle breaks down when number of tasks increase to a big number. here is a reproducible example (perhaps not minimal):
Thank you for this @hussainsultan . Most of the work to resolve this problem is probably in the reproducible example that you just made. I really appreciate your effort here.
I will try to take a look at this later this morning.
On Feb 24, 2018, at 9:03 AM, Matthew Rocklin ***@***.***> wrote:
Closed #2730 via #3201.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
Activity
Update README.md
martindurant commentedon Sep 29, 2017
Interestingly, dask returns the correct value on the threaded scheduler.
ningsean commentedon Oct 2, 2017
Hmmm, I get incorrect result with different schedulers, even with a single-threaded scheduler (get=dask.get). The only way that I can get the correct result is to do the merge with pandas dataframes.
To summarize it again, here are the different merges I have tried, and only pandas merge worked.
ningsean commentedon Oct 4, 2017
Strange, if I init a distributed client, the single-threaded scheduler gives the wrong result.
But if I don't init the client at all, the single-threaded scheduler returns the correct result (and a few times slower):
In both cases, I checked the status bokeh app and scheduler and worker log, there didn't seem to be any activities with the local cluster.
Another that I noticed is that, with the client init'ed, the ddf.dask has 28044 tasks with len(ddf.dask), while without it the ddf.dask as only 4779 tasks.
So, the results seem to indicate that even though not used, a client to the local cluster affects the task graph, the correctness of the merge results as well as the speed. This is totally unexpected to me.
mrocklin commentedon Oct 4, 2017
When dask.distributed starts up it changes the global shuffle mechanism from "disk" to "tasks". You can also control this with the
dask.set_options(shuffle='tasks')context manager. It might be useful to try that out on your problem to see if you can recreate your issue without starting a client.If so then that will help to isolate the error.
ningsean commentedon Oct 4, 2017
Yes,
dask.set_options(shuffle='tasks')has the same effect as starting a client. Now the error happens even without starting the client.ningsean commentedon Nov 8, 2017
Interesting. If I make the "KEY" column as the index for both dask dataframes, then use join, the result would come out correct. It is slightly slower than doing merge directly due to the overhead of set_index.
If I persist the indexed dataframes and the non-indexed dataframes, the join on the indexed would be much faster than the merge on the non-indexed, with the additional benefit of the result being correct!
I tried to debug and pin-point the issue with the merge but haven't been able to get anywhere.
hussainsultan commentedon Dec 11, 2017
bump - this is something that i am seeing as well.
brendancol commentedon Dec 11, 2017
@mrocklin @jcrist Anybody actively working on this one? Just ran into this too.
mrocklin commentedon Dec 12, 2017
@brendancol I'm not working on it currently, nor is anyone that I know of. Generally people write on an issue when they start work. I agree that this is important. I don't personally plan to work on it any time in the next week or two. If anyone wants to take it on that would be great.
hussainsultan commentedon Dec 12, 2017
@mrocklin i am working on creating a reproducible example. I haven't been able to reproduce this issue outside of the production environment though. Will update this thread.
dennis-ec commentedon Feb 21, 2018
bump - Any news on this? I also find this issue very important because merge is a very common operation and forced to set the index first slows me down quite a bit.
mrocklin commentedon Feb 21, 2018
It looks like this is waiting on a reproducible example that demonstrates the failure in a simple way. Perhaps you are able to provide such an example @dennis-ec ?
hussainsultan commentedon Feb 21, 2018
I haven't been able to reproduce this using synthetic data. However, the issue persists with the parquet files that @ningsean uploaded.
Output
Hope this is helpful.
mrocklin commentedon Feb 21, 2018
Unfortunately we won't be able to include these files in tests. We really do need something that can be generated automatically.
hussainsultan commentedon Feb 21, 2018
yea i will play around some more to reproduce this with synthetic data
hussainsultan commentedon Feb 23, 2018
This is a really weird one. It appears that the task shuffle breaks down when number of tasks increase to a big number. here is a reproducible example (perhaps not minimal):
however, the following works just fine:
hussainsultan commentedon Feb 23, 2018
cc: @jcrist @brendancol
mrocklin commentedon Feb 23, 2018
Thank you for this @hussainsultan . Most of the work to resolve this problem is probably in the reproducible example that you just made. I really appreciate your effort here.
I will try to take a look at this later this morning.
Mod before truncate in shufle_group
Mod before truncate in shufle_group
mrocklin commentedon Feb 23, 2018
Mod before truncate in shufle_group
hussainsultan commentedon Feb 23, 2018
Thank you for the fix! This also works with the original data that @ningsean posted.
Mod before truncate in shufle_group (#3201)
ningsean commentedon Feb 24, 2018