polars.Series.extend#
- Series.extend(other: Series) Self [source]#
Extend the memory backed by this Series with the values from another.
Different from
append
, which adds the chunks fromother
to the chunks of this series,extend
appends the data fromother
to the underlying memory locations and thus may cause a reallocation (which is expensive).If this does not cause a reallocation, the resulting data structure will not have any extra chunks and thus will yield faster queries.
Prefer
extend
overappend
when you want to do a query after a single append. For instance, during online operations where you add n rows and rerun a query.Prefer
append
overextend
when you want to append many times before doing a query. For instance, when you read in multiple files and want to store them in a singleSeries
. In the latter case, finish the sequence ofappend
operations with a rechunk.- Parameters:
- other
Series to extend the series with.
Warning
This method modifies the series in-place. The series is returned for convenience only.
See also
Examples
>>> a = pl.Series("a", [1, 2, 3]) >>> b = pl.Series("b", [4, 5]) >>> a.extend(b) shape: (5,) Series: 'a' [i64] [ 1 2 3 4 5 ]
The resulting series will consist of a single chunk.
>>> a.n_chunks() 1