Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-core/src/series/ops/extend.rs
6940 views
1
use crate::prelude::*;
2
3
impl Series {
4
/// Extend with a constant value.
5
pub fn extend_constant(&self, value: AnyValue, n: usize) -> PolarsResult<Self> {
6
// TODO: Use `from_any_values_and_dtype` here instead of casting afterwards
7
let s = Series::from_any_values(PlSmallStr::EMPTY, &[value], true).unwrap();
8
let s = s.cast(self.dtype())?;
9
let to_append = s.new_from_index(0, n);
10
11
let mut out = self.clone();
12
out.append(&to_append)?;
13
Ok(out)
14
}
15
}
16
17