Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make IdxVec generic as UnitVec #14196

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub(crate) fn create_extension<I: Iterator<Item = Option<T>> + TrustedLen, T: Si
mod test {
use std::fmt::{Display, Formatter};

use polars_utils::idxvec;
use polars_utils::unitvec;

use super::*;

Expand Down Expand Up @@ -200,7 +200,7 @@ mod test {
let ca = ObjectChunked::new("", values);

let groups =
GroupsProxy::Idx(vec![(0, idxvec![0, 1]), (2, idxvec![2]), (3, idxvec![3])].into());
GroupsProxy::Idx(vec![(0, unitvec![0, 1]), (2, unitvec![2]), (3, unitvec![3])].into());
let out = unsafe { ca.agg_list(&groups) };
assert!(matches!(out.dtype(), DataType::List(_)));
assert_eq!(out.len(), groups.len());
Expand All @@ -223,7 +223,7 @@ mod test {
let values = &[Some(foo1.clone()), None, Some(foo2.clone()), None];
let ca = ObjectChunked::new("", values);

let groups = vec![(0, idxvec![0, 1]), (2, idxvec![2]), (3, idxvec![3])].into();
let groups = vec![(0, unitvec![0, 1]), (2, unitvec![2]), (3, unitvec![3])].into();
let out = unsafe { ca.agg_list(&GroupsProxy::Idx(groups)) };
let a = out.explode().unwrap();

Expand Down
12 changes: 6 additions & 6 deletions crates/polars-core/src/frame/group_by/hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use hashbrown::hash_map::{Entry, RawEntryMut};
use hashbrown::HashMap;
use polars_utils::hashing::{hash_to_partition, DirtyHash};
use polars_utils::idx_vec::IdxVec;
use polars_utils::idxvec;
use polars_utils::iter::EnumerateIdxTrait;
use polars_utils::sync::SyncPtr;
use polars_utils::unitvec;
use rayon::prelude::*;

use super::GroupsProxy;
Expand Down Expand Up @@ -156,7 +156,7 @@ where

match entry {
Entry::Vacant(entry) => {
let tuples = idxvec![idx];
let tuples = unitvec![idx];
entry.insert((idx, tuples));
},
Entry::Occupied(mut entry) => {
Expand Down Expand Up @@ -220,7 +220,7 @@ where

match entry {
RawEntryMut::Vacant(entry) => {
let tuples = idxvec![idx];
let tuples = unitvec![idx];
entry.insert_with_hasher(hash, *k, (idx, tuples), |k| {
hasher.hash_one(k)
});
Expand Down Expand Up @@ -283,7 +283,7 @@ where

match entry {
RawEntryMut::Vacant(entry) => {
let tuples = idxvec![idx];
let tuples = unitvec![idx];
entry.insert_with_hasher(hash, k, (idx, tuples), |k| {
hasher.hash_one(k)
});
Expand Down Expand Up @@ -438,7 +438,7 @@ pub(crate) fn group_by_threaded_multiple_keys_flat(
let all_vals = &mut *(all_buf_ptr as *mut Vec<IdxVec>);
let offset_idx = first_vals.len() as IdxSize;

let tuples = idxvec![row_idx];
let tuples = unitvec![row_idx];
all_vals.push(tuples);
first_vals.push(row_idx);
offset_idx
Expand Down Expand Up @@ -501,7 +501,7 @@ pub(crate) fn group_by_multiple_keys(keys: DataFrame, sorted: bool) -> PolarsRes
let all_vals = &mut *(all_buf_ptr as *mut Vec<IdxVec>);
let offset_idx = first_vals.len() as IdxSize;

let tuples = idxvec![row_idx];
let tuples = unitvec![row_idx];
all_vals.push(tuples);
first_vals.push(row_idx);
offset_idx
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-lazy/src/tests/aggregations.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use polars_ops::prelude::ListNameSpaceImpl;
use polars_utils::idxvec;
use polars_utils::unitvec;

use super::*;

Expand All @@ -9,7 +9,7 @@ fn test_agg_list_type() -> PolarsResult<()> {
let s = Series::new("foo", &[1, 2, 3]);
let s = s.cast(&DataType::Datetime(TimeUnit::Nanoseconds, None))?;

let l = unsafe { s.agg_list(&GroupsProxy::Idx(vec![(0, idxvec![0, 1, 2])].into())) };
let l = unsafe { s.agg_list(&GroupsProxy::Idx(vec![(0, unitvec![0, 1, 2])].into())) };

let result = match l.dtype() {
DataType::List(inner) => {
Expand Down
6 changes: 3 additions & 3 deletions crates/polars-ops/src/frame/join/hash_join/multiple_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use polars_core::utils::{_set_partition_size, split_df};
use polars_core::POOL;
use polars_utils::hashing::hash_to_partition;
use polars_utils::idx_vec::IdxVec;
use polars_utils::idxvec;
use polars_utils::unitvec;

use super::*;

Expand Down Expand Up @@ -61,7 +61,7 @@ pub(crate) fn create_probe_table(
idx,
*h,
keys,
|| idxvec![idx],
|| unitvec![idx],
|v| v.push(idx),
)
}
Expand Down Expand Up @@ -108,7 +108,7 @@ fn create_build_table_outer(
idx,
*h,
keys,
|| (false, idxvec![idx]),
|| (false, unitvec![idx]),
|v| v.1.push(idx),
)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-ops/src/frame/join/hash_join/single_keys.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use polars_utils::hashing::{hash_to_partition, DirtyHash};
use polars_utils::idx_vec::IdxVec;
use polars_utils::idxvec;
use polars_utils::nulls::IsNull;
use polars_utils::sync::SyncPtr;
use polars_utils::unitvec;

use super::*;

Expand Down Expand Up @@ -142,7 +142,7 @@ where
o.get_mut().push(idx as IdxSize);
},
Entry::Vacant(v) => {
let iv = idxvec![idx as IdxSize];
let iv = unitvec![idx as IdxSize];
v.insert(iv);
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use arrow::array::{MutablePrimitiveArray, PrimitiveArray};
use arrow::legacy::utils::CustomIterTools;
use polars_utils::hashing::hash_to_partition;
use polars_utils::idx_vec::IdxVec;
use polars_utils::idxvec;
use polars_utils::nulls::IsNull;
use polars_utils::unitvec;

use super::*;

Expand Down Expand Up @@ -72,7 +72,7 @@ where

match entry {
RawEntryMut::Vacant(entry) => {
entry.insert_hashed_nocheck(*h, *k, (false, idxvec![idx]));
entry.insert_hashed_nocheck(*h, *k, (false, unitvec![idx]));
},
RawEntryMut::Occupied(mut entry) => {
let (_k, v) = entry.get_key_value_mut();
Expand Down
14 changes: 7 additions & 7 deletions crates/polars-time/src/group_by/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ fn update_subgroups_idx(
mod test {
use chrono::prelude::*;
use polars_ops::prelude::*;
use polars_utils::idxvec;
use polars_utils::unitvec;

use super::*;

Expand Down Expand Up @@ -899,12 +899,12 @@ mod test {

let expected = GroupsProxy::Idx(
vec![
(0 as IdxSize, idxvec![0 as IdxSize, 1, 2]),
(2, idxvec![2]),
(5, idxvec![5, 6]),
(6, idxvec![6]),
(3, idxvec![3, 4]),
(4, idxvec![4]),
(0 as IdxSize, unitvec![0 as IdxSize, 1, 2]),
(2, unitvec![2]),
(5, unitvec![5, 6]),
(6, unitvec![6]),
(3, unitvec![3, 4]),
(4, unitvec![4]),
]
.into(),
);
Expand Down