From 4d0755e9b7285cf1c7c462cb2886e7ac14a50f37 Mon Sep 17 00:00:00 2001 From: Aric Coady Date: Sat, 24 Aug 2024 08:32:37 -0700 Subject: [PATCH] Arrays from iterable scalars are now supported. --- graphique/core.py | 7 +------ graphique/interface.py | 4 +--- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/graphique/core.py b/graphique/core.py index ecb61cb..e4cec33 100644 --- a/graphique/core.py +++ b/graphique/core.py @@ -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 @@ -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 diff --git a/graphique/interface.py b/graphique/interface.py index 9d35993..9499cf7 100644 --- a/graphique/interface.py +++ b/graphique/interface.py @@ -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')