Skip to content

Commit

Permalink
Include exclusive joins
Browse files Browse the repository at this point in the history
  • Loading branch information
luis11011 committed Oct 14, 2021
1 parent 2d6970c commit fe1a4b4
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions optimus/engines/base/basedataframe.py
Expand Up @@ -1014,7 +1014,7 @@ def join(self, df_right: 'DataFrameType', how="left", on=None, left_on=None, rig
"""
Join 2 dataframes SQL style
:param df_right:
:param how{‘left’, ‘right’, ‘outer’, ‘inner’}, default ‘left’
:param how{‘left’, ‘right’, ‘outer’, ‘inner’, ‘exclusive’, ‘exclusive left’, ‘exclusive right’}, default ‘left’
:param on:
:param left_on:
:param right_on:
Expand Down Expand Up @@ -1051,8 +1051,29 @@ def join(self, df_right: 'DataFrameType', how="left", on=None, left_on=None, rig
left_names = df_left.cols.names()
right_names = df_right.cols.names()

df = self.root.new(df_left.data.merge(df_right.data, how=how, left_on=left_on, right_on=right_on,
suffixes=(suffix_left, suffix_right)))

if how in ['exclusive', 'exclusive left', 'exclusive right']:
_how = 'outer'
indicator = True
else:
_how = how
indicator = False

dfd = df_left.data.merge(df_right.data, how=_how, left_on=left_on,
right_on=right_on, suffixes=(suffix_left, suffix_right),
indicator=indicator)

if how == 'exclusive':
dfd = dfd[(dfd["_merge"] == "left_only") | (dfd["_merge"] == "right_only")]
elif how == 'exclusive left':
dfd = dfd[dfd["_merge"] == "left_only"]
elif how == 'exclusive right':
dfd = dfd[dfd["_merge"] == "right_only"]

if indicator:
dfd = dfd.drop(["_merge"], axis=1)

df = self.root.new(dfd)

# Reorder
last_column_name = left_names[-1]
Expand Down

0 comments on commit fe1a4b4

Please sign in to comment.