Repository navigation
Clear divisions on single_partitions_merge - #1666
Conversation
| bb = dd.from_pandas(b, npartitions=1, sort=False) | ||
|
|
||
| assert_divisions(aa.merge(bb, on='x', how='inner')) | ||
| assert_divisions(bb.merge(aa, on='x', how='inner')) |
There was a problem hiding this comment.
What happens if we merge a dask.dataframe on its index with a pandas dataframe on some other column. Do we still lose division information?
There was a problem hiding this comment.
In my current implementation, all division information is lost. I agree, that in case of on-index joins, the division information is potentially lost unnecessarily. I will update the PR by adding corresponding tests and the required logic.
|
Your analysis generally seems correct to me. Thank you for the fix. |
| a.merge(b, left_index=True, right_on='x', how='inner')) | ||
| assert eq(bb.merge(aa, right_index=True, left_on='x', how='inner'), | ||
| b.merge(a, right_index=True, left_on='x', how='inner')) | ||
|
|
There was a problem hiding this comment.
Can you assert bb.merge(aa, right_index=True, left_on='x', how='inner').known_divisions here?
There was a problem hiding this comment.
Sure. Just getting the hang of the dask internals ;)
There was a problem hiding this comment.
I also added a corresponding test for the on-column merges, where divisions are no longer known after a merge.
| kwargs)) | ||
| for i, right_key in enumerate(right._keys())) | ||
| divisions = right.divisions | ||
| divisions = get_divisions(right.divisions, kwargs.get('right_index')) |
There was a problem hiding this comment.
I would slightly prefer inlining your function above. The code repetition is not so great and it seems a bit simpler:
divisions = right.divisions if right_index else [None for _ in divisions]
divisions = left.divisions if left_index else [None for _ in divisions]
There was a problem hiding this comment.
I have no strong preference either. I used an if-statement to stay within the 80 characters.
|
+1 from me. Merging in 24 hours if no further comments. |
|
Thanks for merging and the constructive feedback. |
|
This is in. Thanks @chmp ! |
I ran into a problem when performing joins with small dataframes in my unittests using the eq helper, where assert_divisions raised an error. I belief the reason for this behavior to be, that the single partition merge copies the divisions from one dataframe. If I understand the division concept correctly, they give divisions of the index values. However, in general the index after a pandas merge is not related to the original index. Therefore, I belief that the divisions should be reset after a single partition merge.
I added a unittest that fails with dask head, but passes with an additional reset of the divisions.