Skip to content

BUG: merge_ordered should raise when elements in by not exist in df #38167

Closed
@GYHHAHA

Description

@GYHHAHA
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


>>>l = pd.DataFrame([['g', 'h', 1], ['g', 'h', 3]], columns=list('GHT'))
>>>l
   G  H  T
0  g  h  1
1  g  h  3
>>>r = pd.DataFrame([[2, 1]], columns=list('TE'))
>>>r
   T  E
0  2  1

Result

>>>pd.merge_ordered(l, r, on='T', left_by=['G', 'h'])
G H T E h
0 G h 1 nan G
1 G nan 2 1 G
2 h nan 2 1 h
3 h h 3 nan h

expected

>>>pd.merge_ordered(l, r, on='T', left_by=['G', 'h'])
KeyError: "['h'] not found in left columns"

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions