Skip to content

Commit d286331

Browse files
committed
feat: Update ArrowSeries.from_iterable
1 parent 1feb8cc commit d286331

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

narwhals/_arrow/series.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,20 @@ def _from_native_series(
141141

142142
@classmethod
143143
def from_iterable(
144-
cls, data: Iterable[Any], *, context: _FullContext, name: str = ""
144+
cls,
145+
data: Iterable[Any],
146+
*,
147+
context: _FullContext,
148+
name: str = "",
149+
dtype: DType | type[DType] | None = None,
145150
) -> Self:
151+
version = context._version
152+
dtype_pa = narwhals_to_native_dtype(dtype, version) if dtype else None
146153
return cls(
147-
chunked_array([data]),
154+
chunked_array([data], dtype_pa),
148155
name=name,
149156
backend_version=context._backend_version,
150-
version=context._version,
157+
version=version,
151158
)
152159

153160
def _from_scalar(self, value: Any) -> Self:

narwhals/_arrow/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,13 @@ def extract_py_scalar(value: Any, /) -> Any:
7474

7575
def chunked_array(
7676
arr: ArrowArray | list[Iterable[pa.Scalar[Any]]] | ArrowChunkedArray,
77+
dtype: pa.DataType | None = None,
78+
/,
7779
) -> ArrowChunkedArray:
7880
if isinstance(arr, pa.ChunkedArray):
7981
return arr
8082
if isinstance(arr, list):
81-
return pa.chunked_array(cast("Any", arr))
83+
return pa.chunked_array(cast("Any", arr), dtype)
8284
else:
8385
return pa.chunked_array([arr], arr.type)
8486

0 commit comments

Comments
 (0)