Skip to content

Commit

Permalink
refactor coalesce to support columns as input
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesbluca committed Nov 23, 2022
1 parent cd1a147 commit 2000932
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 7 additions & 5 deletions dask_sql/physical/rex/core/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,16 +577,18 @@ def __init__(self):
super().__init__(self.coalesce)

def coalesce(self, *operands):
result = None
for operand in operands:
if is_frame(operand):
# Check if frame evaluates to nan or NA
if not operand.isnull().all().compute():
return operand
if len(operand) == 1 and not operand.isnull().all().compute():
return operand if result is None else result.fillna(operand)
else:
continue
result = operand if result is None else result.fillna(operand)
elif not pd.isna(operand):
return operand if result is None else result.fillna(operand)

if not pd.isna(operand):
return operand
return result


class ExtractOperation(Operation):
Expand Down
4 changes: 1 addition & 3 deletions tests/integration/test_rex.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,7 @@ def test_coalesce(c, gpu):
}
)

df["c2"] = df["c2"].astype("float64")
df["c5"] = df["c5"].astype("O")
assert_eq(df, expected_df)
assert_eq(df, expected_df, check_dtype=False)
c.drop_table("df")


Expand Down

0 comments on commit 2000932

Please sign in to comment.