Skip to content

merge() with how="cross" does not work  #8119

Closed

Description

@johanbog

What happened:
Running dd.merge(left, right, how="cross") fails with

MergeError: Can not pass on, right_on, left_on or set right_index=True or left_index=True

What you expected to happen:

Minimal Complete Verifiable Example:

left = pd.DataFrame(
    {
        "key": ["K0", "K1", "K2", "K3"],
        "A": ["A0", "A1", "A2", "A3"],
        "B": ["B0", "B1", "B2", "B3"],
    }
)
right = pd.DataFrame(
    {
        "key": ["K0", "K1", "K2", "K3"],
        "A": ["C0", "C1", "C2", "C3"],
        "B": ["D0", "D1", "D2", "D3"],
    }
)
dd.merge(left, right, how="cross")

Anything else we need to know?:

Environment:

  • Dask version: '2021.09.0'
  • Python version: 3.7.10
  • Operating System: MacOS
  • Install method (conda, pip, source): pip

Activity

  1. ncclementi commented on Sep 10, 2021

    @ncclementi
    Member

    Hi @johanbog for what I'm reading in the docs the reason why dd.merge() with how="cross" does not work, it's because it's not supported. dd.merge documentation
    merge source code

    If what you want is a feature request, you might want to open an issue requesting this feature.

  2. jsignell commented on Sep 13, 2021

    @jsignell
    Member

    In the meantime we could raise a clearer exception.

  3. ncclementi commented on Sep 13, 2021

    @ncclementi
    Member

    @jsignell that sounds like a great idea. I can take a crack at that but I have few questions

    Looking at the code where merge is defined more explicitly here

    dask/dask/dataframe/core.py

    Lines 4614 to 4634 in 9f0b00f

    if not is_dataframe_like(right):
    raise ValueError("right must be DataFrame")
    from .multi import merge
    return merge(
    self,
    right,
    how=how,
    on=on,
    left_on=left_on,
    right_on=right_on,
    left_index=left_index,
    right_index=right_index,
    suffixes=suffixes,
    npartitions=npartitions,
    indicator=indicator,
    shuffle=shuffle,
    broadcast=broadcast,
    )

    Should the raise go in the definition in .multi, like somewhere in here?

    def merge(

    probably right before

    if isinstance(left, (pd.Series, pd.DataFrame)) and isinstance(

    Would that be a good place?

  4. jsignell commented on Sep 13, 2021

    @jsignell
    Member

    Cool! Yeah I think it should go in multi right above the line that you are pointing to.

  5. added
    needs attention
    on Oct 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dataframeneeds attention

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions