Skip to content

Commit

Permalink
perf[rust]: set sorted flag on series filled with constant (#4459)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Aug 17, 2022
1 parent f161659 commit b2f70bb
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions polars/polars-core/src/chunked_array/ops/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ use polars_arrow::array::default_arrays::FromData;

use crate::chunked_array::builder::get_list_builder;
use crate::prelude::*;
use crate::series::IsSorted;

impl<T> ChunkFull<T::Native> for ChunkedArray<T>
where
T: PolarsNumericType,
{
fn full(name: &str, value: T::Native, length: usize) -> Self {
let data = vec![value; length];
ChunkedArray::from_vec(name, data)
let mut out = ChunkedArray::from_vec(name, data);
out.set_sorted2(IsSorted::Ascending);
out
}
}

Expand All @@ -27,7 +30,10 @@ impl ChunkFull<bool> for BooleanChunked {
fn full(name: &str, value: bool, length: usize) -> Self {
let mut bits = MutableBitmap::with_capacity(length);
bits.extend_constant(length, value);
(name, BooleanArray::from_data_default(bits.into(), None)).into()
let mut out: BooleanChunked =
(name, BooleanArray::from_data_default(bits.into(), None)).into();
out.set_sorted2(IsSorted::Ascending);
out
}
}

Expand All @@ -45,7 +51,9 @@ impl<'a> ChunkFull<&'a str> for Utf8Chunked {
for _ in 0..length {
builder.append_value(value);
}
builder.finish()
let mut out = builder.finish();
out.set_sorted2(IsSorted::Ascending);
out
}
}

Expand Down

0 comments on commit b2f70bb

Please sign in to comment.