Skip to content

Commit

Permalink
Arrays from iterable scalars are now supported.
Browse files Browse the repository at this point in the history
  • Loading branch information
coady committed Aug 24, 2024
1 parent 25c3acc commit 4d0755e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
7 changes: 1 addition & 6 deletions graphique/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ def quantile(self, **options) -> pa.Array:

def index(self, **options) -> pa.Array:
"""index for first occurrence of each list scalar"""
values = [pc.index(value, **options) for value in ListChunk.scalars(self)]
return Column.from_scalars(values)
return pa.array(pc.index(value, **options) for value in ListChunk.scalars(self))

@register
def list_all(ctx, self: pa.list_(pa.bool_())) -> pa.bool_(): # type: ignore
Expand All @@ -228,10 +227,6 @@ def list_any(ctx, self: pa.list_(pa.bool_())) -> pa.bool_(): # type: ignore
class Column(pa.ChunkedArray):
"""Chunked array interface as a namespace of functions."""

def from_scalars(values: Sequence) -> pa.Array:
"""Return array from arrow scalars."""
return pa.array((value.as_py() for value in values), values[0].type)

def scalar_type(self):
return self.type.value_type if pa.types.is_dictionary(self.type) else self.type

Expand Down
4 changes: 1 addition & 3 deletions graphique/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,7 @@ def fragments(self, info: Info, counts: str = '', aggregate: HashAggregates = {}
for name in row:
columns[name].append(row[name])
for name, values in columns.items():
if isinstance(values[0], pa.Scalar):
columns[name] = C.from_scalars(values)
elif isinstance(values[0], pa.Array):
if isinstance(values[0], pa.Array):
columns[name] = ListChunk.from_scalars(values)
columns |= {field.name: pa.array(columns[field.name], field.type) for field in schema}
return self.add_metric(info, pa.table(columns), mode='fragment')
Expand Down

0 comments on commit 4d0755e

Please sign in to comment.