Skip to content

Clear divisions on single_partitions_merge - #1666

Merged
mrocklin merged 4 commits into
dask:masterfrom
chmp:master
Oct 17, 2016
Merged

mrocklin merged 4 commits into
dask:masterfrom
chmp:master

Conversation

@chmp

@chmp chmp commented Oct 15, 2016

Copy link
Copy Markdown
Contributor

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.

Comment thread dask/dataframe/tests/test_multi.py Outdated
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'))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mrocklin

Copy link
Copy Markdown
Member

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'))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you assert bb.merge(aa, right_index=True, left_on='x', how='inner').known_divisions here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Just getting the hang of the dask internals ;)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also added a corresponding test for the on-column merges, where divisions are no longer known after a merge.

Comment thread dask/dataframe/multi.py Outdated
kwargs))
for i, right_key in enumerate(right._keys()))
divisions = right.divisions
divisions = get_divisions(right.divisions, kwargs.get('right_index'))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no strong preference either. I used an if-statement to stay within the 80 characters.

@mrocklin

Copy link
Copy Markdown
Member

+1 from me. Merging in 24 hours if no further comments.

@chmp

chmp commented Oct 16, 2016

Copy link
Copy Markdown
Contributor Author

Thanks for merging and the constructive feedback.

@mrocklin
mrocklin merged commit 24b0e63 into dask:master Oct 17, 2016
@mrocklin

Copy link
Copy Markdown
Member

This is in. Thanks @chmp !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants