Skip to content

Commit

Permalink
chore: move length check up
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Jan 21, 2024
1 parent 083a346 commit b9f9bbe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions ibis/backends/dask/execution/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
@execute_node.register(ops.Array, tuple)
def execute_array_column(op, cols, **kwargs):
vals = [execute(arg, **kwargs) for arg in cols]

length = next((len(v) for v in vals if isinstance(v, dd.Series)), None)
if length is None:
return vals

n_partitions = next((v.npartitions for v in vals if isinstance(v, dd.Series)), None)

def ensure_series(v):
Expand All @@ -47,8 +51,6 @@ def ensure_series(v):
else:
return dd.from_pandas(pd.Series([v] * length), npartitions=n_partitions)

if length is None:
return vals
# dd.concat() can only handle array-likes.
# If we're given a scalar, we need to broadcast it as a Series.
df = dd.concat([ensure_series(v) for v in vals], axis=1)
Expand Down
5 changes: 3 additions & 2 deletions ibis/backends/pandas/execution/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ def execute_array(op, cols, **kwargs):
vals = [execute(arg, **kwargs) for arg in cols]
length = next((len(v) for v in vals if isinstance(v, pd.Series)), None)

if length is None:
return vals

def ensure_series(v):
if isinstance(v, pd.Series):
return v
else:
return pd.Series(v, index=range(length))

if length is None:
return vals
# pd.concat() can only handle array-likes.
# If we're given a scalar, we need to broadcast it as a Series.
df = pd.concat([ensure_series(v) for v in vals], axis=1)
Expand Down

0 comments on commit b9f9bbe

Please sign in to comment.