Skip to content

Commit

Permalink
replace new_from_opt_slice with new
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Dec 5, 2021
1 parent a512a3e commit b1bff70
Show file tree
Hide file tree
Showing 24 changed files with 163 additions and 217 deletions.
6 changes: 3 additions & 3 deletions polars/polars-core/src/chunked_array/categorical/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ mod test {
Some("foo"),
Some("bar"),
];
let ca = Utf8Chunked::new_from_opt_slice("a", slice);
let ca = Utf8Chunked::new("a", slice);
let out = ca.cast(&DataType::Categorical)?;
let mut out = out.categorical().unwrap().clone();
assert_eq!(out.categorical_map.take().unwrap().len(), 2);
Expand All @@ -224,9 +224,9 @@ mod test {
// Check that we don't panic if we append two categorical arrays
// build under the same string cache
// https://github.com/pola-rs/polars/issues/1115
let ca1 = Utf8Chunked::new_from_opt_slice("a", slice).cast(&DataType::Categorical)?;
let ca1 = Utf8Chunked::new("a", slice).cast(&DataType::Categorical)?;
let mut ca1 = ca1.categorical().unwrap().clone();
let ca2 = Utf8Chunked::new_from_opt_slice("a", slice).cast(&DataType::Categorical)?;
let ca2 = Utf8Chunked::new("a", slice).cast(&DataType::Categorical)?;
let ca2 = ca2.categorical().unwrap();
ca1.append(ca2);

Expand Down
2 changes: 1 addition & 1 deletion polars/polars-core/src/chunked_array/categorical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ mod test {
Some("foo"),
Some("bar"),
];
let ca = Utf8Chunked::new_from_opt_slice("a", slice);
let ca = Utf8Chunked::new("a", slice);
let ca = ca.cast(&DataType::Categorical)?;
let ca = ca.categorical().unwrap();

Expand Down
4 changes: 2 additions & 2 deletions polars/polars-core/src/chunked_array/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ mod test {
#[test]
fn test_bitwise_ops() {
let a = BooleanChunked::new_from_slice("a", &[true, false, false]);
let b = BooleanChunked::new_from_opt_slice("b", &[Some(true), Some(true), None]);
let b = BooleanChunked::new("b", &[Some(true), Some(true), None]);
assert_eq!(Vec::from(&a | &b), &[Some(true), Some(true), None]);
assert_eq!(Vec::from(&a & &b), &[Some(true), Some(false), Some(false)]);
assert_eq!(Vec::from(!b), &[Some(false), Some(false), None]);
Expand Down Expand Up @@ -1056,7 +1056,7 @@ mod test {

#[test]
fn test_kleene() {
let a = BooleanChunked::new_from_opt_slice("", &[Some(true), Some(false), None]);
let a = BooleanChunked::new("", &[Some(true), Some(false), None]);
let trues = BooleanChunked::new_from_slice("", &[true, true, true]);
let falses = BooleanChunked::new_from_slice("", &[false, false, false]);

Expand Down
27 changes: 9 additions & 18 deletions polars/polars-core/src/chunked_array/iterator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,7 @@ mod test {
($test_name:ident, $ca_type:ty, $first_val:expr, $second_val:expr, $third_val:expr) => {
#[test]
fn $test_name() {
let a =
<$ca_type>::new_from_opt_slice("test", &[$first_val, $second_val, $third_val]);
let a = <$ca_type>::new("test", &[$first_val, $second_val, $third_val]);

// normal iterator
let mut it = a.into_iter();
Expand Down Expand Up @@ -617,8 +616,8 @@ mod test {
($test_name:ident, $ca_type:ty, $first_val:expr, $second_val:expr, $third_val:expr) => {
#[test]
fn $test_name() {
let mut a = <$ca_type>::new_from_opt_slice("test", &[$first_val, $second_val]);
let a_b = <$ca_type>::new_from_opt_slice("", &[$third_val]);
let mut a = <$ca_type>::new("test", &[$first_val, $second_val]);
let a_b = <$ca_type>::new("", &[$third_val]);
a.append(&a_b);

// normal iterator
Expand Down Expand Up @@ -886,7 +885,7 @@ mod test {
8,
Some("0"),
None,
{ Utf8Chunked::new_from_opt_slice("test", &generate_opt_utf8_vec(SKIP_ITERATOR_SIZE)) }
{ Utf8Chunked::new("test", &generate_opt_utf8_vec(SKIP_ITERATOR_SIZE)) }
);

impl_test_iter_skip!(utf8_iter_many_chunk_skip, 18, Some("0"), Some("9"), {
Expand All @@ -897,10 +896,8 @@ mod test {
});

impl_test_iter_skip!(utf8_iter_many_chunk_null_check_skip, 18, Some("0"), None, {
let mut a =
Utf8Chunked::new_from_opt_slice("test", &generate_opt_utf8_vec(SKIP_ITERATOR_SIZE));
let a_b =
Utf8Chunked::new_from_opt_slice("test", &generate_opt_utf8_vec(SKIP_ITERATOR_SIZE));
let mut a = Utf8Chunked::new("test", &generate_opt_utf8_vec(SKIP_ITERATOR_SIZE));
let a_b = Utf8Chunked::new("test", &generate_opt_utf8_vec(SKIP_ITERATOR_SIZE));
a.append(&a_b);
a
});
Expand All @@ -925,7 +922,7 @@ mod test {
});

impl_test_iter_skip!(bool_iter_single_chunk_null_check_skip, 8, None, None, {
BooleanChunked::new_from_opt_slice("test", &generate_opt_boolean_vec(SKIP_ITERATOR_SIZE))
BooleanChunked::new("test", &generate_opt_boolean_vec(SKIP_ITERATOR_SIZE))
});

impl_test_iter_skip!(bool_iter_many_chunk_skip, 18, Some(true), Some(false), {
Expand All @@ -937,14 +934,8 @@ mod test {
});

impl_test_iter_skip!(bool_iter_many_chunk_null_check_skip, 18, None, None, {
let mut a = BooleanChunked::new_from_opt_slice(
"test",
&generate_opt_boolean_vec(SKIP_ITERATOR_SIZE),
);
let a_b = BooleanChunked::new_from_opt_slice(
"test",
&generate_opt_boolean_vec(SKIP_ITERATOR_SIZE),
);
let mut a = BooleanChunked::new("test", &generate_opt_boolean_vec(SKIP_ITERATOR_SIZE));
let a_b = BooleanChunked::new("test", &generate_opt_boolean_vec(SKIP_ITERATOR_SIZE));
a.append(&a_b);
a
});
Expand Down
57 changes: 15 additions & 42 deletions polars/polars-core/src/chunked_array/iterator/par/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,32 +194,17 @@ mod test {
// Single Chunk Null Check Parallel Iterator Tests.
impl_par_iter_return_option_map_test!(
boolean_par_iter_single_chunk_null_check_return_option_map,
{
BooleanChunked::new_from_opt_slice(
"a",
&generate_opt_boolean_vec(BOOLEAN_CHUNKED_ARRAY_SIZE),
)
}
{ BooleanChunked::new("a", &generate_opt_boolean_vec(BOOLEAN_CHUNKED_ARRAY_SIZE),) }
);

impl_par_iter_return_option_filter_test!(
boolean_par_iter_single_chunk_null_check_return_option_filter,
{
BooleanChunked::new_from_opt_slice(
"a",
&generate_opt_boolean_vec(BOOLEAN_CHUNKED_ARRAY_SIZE),
)
}
{ BooleanChunked::new("a", &generate_opt_boolean_vec(BOOLEAN_CHUNKED_ARRAY_SIZE),) }
);

impl_par_iter_return_option_fold_test!(
boolean_par_iter_single_chunk_null_check_return_option_fold,
{
BooleanChunked::new_from_opt_slice(
"a",
&generate_opt_boolean_vec(BOOLEAN_CHUNKED_ARRAY_SIZE),
)
}
{ BooleanChunked::new("a", &generate_opt_boolean_vec(BOOLEAN_CHUNKED_ARRAY_SIZE),) }
);

// Many Chunk Parallel Iterator Tests.
Expand Down Expand Up @@ -254,14 +239,10 @@ mod test {
impl_par_iter_return_option_map_test!(
boolean_par_iter_many_chunk_null_check_return_option_map,
{
let mut a = BooleanChunked::new_from_opt_slice(
"a",
&generate_opt_boolean_vec(BOOLEAN_CHUNKED_ARRAY_SIZE),
);
let a_b = BooleanChunked::new_from_opt_slice(
"a",
&generate_opt_boolean_vec(BOOLEAN_CHUNKED_ARRAY_SIZE),
);
let mut a =
BooleanChunked::new("a", &generate_opt_boolean_vec(BOOLEAN_CHUNKED_ARRAY_SIZE));
let a_b =
BooleanChunked::new("a", &generate_opt_boolean_vec(BOOLEAN_CHUNKED_ARRAY_SIZE));
a.append(&a_b);
a
}
Expand All @@ -270,14 +251,10 @@ mod test {
impl_par_iter_return_option_filter_test!(
boolean_par_iter_many_chunk_null_check_return_option_filter,
{
let mut a = BooleanChunked::new_from_opt_slice(
"a",
&generate_opt_boolean_vec(BOOLEAN_CHUNKED_ARRAY_SIZE),
);
let a_b = BooleanChunked::new_from_opt_slice(
"a",
&generate_opt_boolean_vec(BOOLEAN_CHUNKED_ARRAY_SIZE),
);
let mut a =
BooleanChunked::new("a", &generate_opt_boolean_vec(BOOLEAN_CHUNKED_ARRAY_SIZE));
let a_b =
BooleanChunked::new("a", &generate_opt_boolean_vec(BOOLEAN_CHUNKED_ARRAY_SIZE));
a.append(&a_b);
a
}
Expand All @@ -286,14 +263,10 @@ mod test {
impl_par_iter_return_option_fold_test!(
boolean_par_iter_many_chunk_null_check_return_option_fold,
{
let mut a = BooleanChunked::new_from_opt_slice(
"a",
&generate_opt_boolean_vec(BOOLEAN_CHUNKED_ARRAY_SIZE),
);
let a_b = BooleanChunked::new_from_opt_slice(
"a",
&generate_opt_boolean_vec(BOOLEAN_CHUNKED_ARRAY_SIZE),
);
let mut a =
BooleanChunked::new("a", &generate_opt_boolean_vec(BOOLEAN_CHUNKED_ARRAY_SIZE));
let a_b =
BooleanChunked::new("a", &generate_opt_boolean_vec(BOOLEAN_CHUNKED_ARRAY_SIZE));
a.append(&a_b);
a
}
Expand Down
54 changes: 12 additions & 42 deletions polars/polars-core/src/chunked_array/iterator/par/numeric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,32 +966,17 @@ mod test {
// Single Chunk Null Check Parallel Iterator Tests.
impl_par_iter_return_option_map_test!(
uint32_par_iter_single_chunk_null_check_return_option_map,
{
UInt32Chunked::new_from_opt_slice(
"a",
&generate_opt_uint32_vec(UINT32_CHUNKED_ARRAY_SIZE),
)
}
{ UInt32Chunked::new("a", &generate_opt_uint32_vec(UINT32_CHUNKED_ARRAY_SIZE),) }
);

impl_par_iter_return_option_filter_test!(
uint32_par_iter_single_chunk_null_check_return_option_filter,
{
UInt32Chunked::new_from_opt_slice(
"a",
&generate_opt_uint32_vec(UINT32_CHUNKED_ARRAY_SIZE),
)
}
{ UInt32Chunked::new("a", &generate_opt_uint32_vec(UINT32_CHUNKED_ARRAY_SIZE),) }
);

impl_par_iter_return_option_fold_test!(
uint32_par_iter_single_chunk_null_check_return_option_fold,
{
UInt32Chunked::new_from_opt_slice(
"a",
&generate_opt_uint32_vec(UINT32_CHUNKED_ARRAY_SIZE),
)
}
{ UInt32Chunked::new("a", &generate_opt_uint32_vec(UINT32_CHUNKED_ARRAY_SIZE),) }
);

// Many Chunk Parallel Iterator Tests.
Expand Down Expand Up @@ -1026,14 +1011,9 @@ mod test {
impl_par_iter_return_option_map_test!(
uint32_par_iter_many_chunk_null_check_return_option_map,
{
let mut a = UInt32Chunked::new_from_opt_slice(
"a",
&generate_opt_uint32_vec(UINT32_CHUNKED_ARRAY_SIZE),
);
let a_b = UInt32Chunked::new_from_opt_slice(
"a",
&generate_opt_uint32_vec(UINT32_CHUNKED_ARRAY_SIZE),
);
let mut a =
UInt32Chunked::new("a", &generate_opt_uint32_vec(UINT32_CHUNKED_ARRAY_SIZE));
let a_b = UInt32Chunked::new("a", &generate_opt_uint32_vec(UINT32_CHUNKED_ARRAY_SIZE));
a.append(&a_b);
a
}
Expand All @@ -1042,14 +1022,9 @@ mod test {
impl_par_iter_return_option_filter_test!(
uint32_par_iter_many_chunk_null_check_return_option_filter,
{
let mut a = UInt32Chunked::new_from_opt_slice(
"a",
&generate_opt_uint32_vec(UINT32_CHUNKED_ARRAY_SIZE),
);
let a_b = UInt32Chunked::new_from_opt_slice(
"a",
&generate_opt_uint32_vec(UINT32_CHUNKED_ARRAY_SIZE),
);
let mut a =
UInt32Chunked::new("a", &generate_opt_uint32_vec(UINT32_CHUNKED_ARRAY_SIZE));
let a_b = UInt32Chunked::new("a", &generate_opt_uint32_vec(UINT32_CHUNKED_ARRAY_SIZE));
a.append(&a_b);
a
}
Expand All @@ -1058,14 +1033,9 @@ mod test {
impl_par_iter_return_option_fold_test!(
uint32_par_iter_many_chunk_null_check_return_option_fold,
{
let mut a = UInt32Chunked::new_from_opt_slice(
"a",
&generate_opt_uint32_vec(UINT32_CHUNKED_ARRAY_SIZE),
);
let a_b = UInt32Chunked::new_from_opt_slice(
"a",
&generate_opt_uint32_vec(UINT32_CHUNKED_ARRAY_SIZE),
);
let mut a =
UInt32Chunked::new("a", &generate_opt_uint32_vec(UINT32_CHUNKED_ARRAY_SIZE));
let a_b = UInt32Chunked::new("a", &generate_opt_uint32_vec(UINT32_CHUNKED_ARRAY_SIZE));
a.append(&a_b);
a
}
Expand Down
32 changes: 9 additions & 23 deletions polars/polars-core/src/chunked_array/iterator/par/utf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,17 @@ mod test {
// Single Chunk Null Check Parallel Iterator Tests.
impl_par_iter_return_option_map_test!(
utf8_par_iter_single_chunk_null_check_return_option_map,
{ Utf8Chunked::new_from_opt_slice("a", &generate_opt_utf8_vec(UTF8_CHUNKED_ARRAY_SIZE)) }
{ Utf8Chunked::new("a", &generate_opt_utf8_vec(UTF8_CHUNKED_ARRAY_SIZE)) }
);

impl_par_iter_return_option_filter_test!(
utf8_par_iter_single_chunk_null_check_return_option_filter,
{ Utf8Chunked::new_from_opt_slice("a", &generate_opt_utf8_vec(UTF8_CHUNKED_ARRAY_SIZE)) }
{ Utf8Chunked::new("a", &generate_opt_utf8_vec(UTF8_CHUNKED_ARRAY_SIZE)) }
);

impl_par_iter_return_option_fold_test!(
utf8_par_iter_single_chunk_null_check_return_option_fold,
{ Utf8Chunked::new_from_opt_slice("a", &generate_opt_utf8_vec(UTF8_CHUNKED_ARRAY_SIZE)) }
{ Utf8Chunked::new("a", &generate_opt_utf8_vec(UTF8_CHUNKED_ARRAY_SIZE)) }
);

// Many Chunk Parallel Iterator Tests.
Expand All @@ -242,25 +242,17 @@ mod test {

// Many Chunk Null Check Parallel Iterator Tests.
impl_par_iter_return_option_map_test!(utf8_par_iter_many_chunk_null_check_return_option_map, {
let mut a =
Utf8Chunked::new_from_opt_slice("a", &generate_opt_utf8_vec(UTF8_CHUNKED_ARRAY_SIZE));
let a_b =
Utf8Chunked::new_from_opt_slice("a", &generate_opt_utf8_vec(UTF8_CHUNKED_ARRAY_SIZE));
let mut a = Utf8Chunked::new("a", &generate_opt_utf8_vec(UTF8_CHUNKED_ARRAY_SIZE));
let a_b = Utf8Chunked::new("a", &generate_opt_utf8_vec(UTF8_CHUNKED_ARRAY_SIZE));
a.append(&a_b);
a
});

impl_par_iter_return_option_filter_test!(
utf8_par_iter_many_chunk_null_check_return_option_filter,
{
let mut a = Utf8Chunked::new_from_opt_slice(
"a",
&generate_opt_utf8_vec(UTF8_CHUNKED_ARRAY_SIZE),
);
let a_b = Utf8Chunked::new_from_opt_slice(
"a",
&generate_opt_utf8_vec(UTF8_CHUNKED_ARRAY_SIZE),
);
let mut a = Utf8Chunked::new("a", &generate_opt_utf8_vec(UTF8_CHUNKED_ARRAY_SIZE));
let a_b = Utf8Chunked::new("a", &generate_opt_utf8_vec(UTF8_CHUNKED_ARRAY_SIZE));
a.append(&a_b);
a
}
Expand All @@ -269,14 +261,8 @@ mod test {
impl_par_iter_return_option_fold_test!(
utf8_par_iter_many_chunk_null_check_return_option_fold,
{
let mut a = Utf8Chunked::new_from_opt_slice(
"a",
&generate_opt_utf8_vec(UTF8_CHUNKED_ARRAY_SIZE),
);
let a_b = Utf8Chunked::new_from_opt_slice(
"a",
&generate_opt_utf8_vec(UTF8_CHUNKED_ARRAY_SIZE),
);
let mut a = Utf8Chunked::new("a", &generate_opt_utf8_vec(UTF8_CHUNKED_ARRAY_SIZE));
let a_b = Utf8Chunked::new("a", &generate_opt_utf8_vec(UTF8_CHUNKED_ARRAY_SIZE));
a.append(&a_b);
a
}
Expand Down
7 changes: 3 additions & 4 deletions polars/polars-core/src/chunked_array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,15 +766,15 @@ pub(crate) mod test {
// path with continuous slice
assert_slice_equal(&s.reverse(), &[3, 2, 1]);
// path with options
let s = UInt32Chunked::new_from_opt_slice("", &[Some(1), None, Some(3)]);
let s = UInt32Chunked::new("", &[Some(1), None, Some(3)]);
assert_eq!(Vec::from(&s.reverse()), &[Some(3), None, Some(1)]);
let s = BooleanChunked::new_from_slice("", &[true, false]);
assert_eq!(Vec::from(&s.reverse()), &[Some(false), Some(true)]);

let s = Utf8Chunked::new_from_slice("", &["a", "b", "c"]);
assert_eq!(Vec::from(&s.reverse()), &[Some("c"), Some("b"), Some("a")]);

let s = Utf8Chunked::new_from_opt_slice("", &[Some("a"), None, Some("c")]);
let s = Utf8Chunked::new("", &[Some("a"), None, Some("c")]);
assert_eq!(Vec::from(&s.reverse()), &[Some("c"), None, Some("a")]);
}

Expand All @@ -795,8 +795,7 @@ pub(crate) mod test {
use crate::SINGLE_LOCK;
let _lock = SINGLE_LOCK.lock();
reset_string_cache();
let ca =
Utf8Chunked::new_from_opt_slice("", &[Some("foo"), None, Some("bar"), Some("ham")]);
let ca = Utf8Chunked::new("", &[Some("foo"), None, Some("bar"), Some("ham")]);
let ca = ca.cast(&DataType::Categorical).unwrap();
let ca = ca.categorical().unwrap();
let v: Vec<_> = ca.into_iter().collect();
Expand Down

0 comments on commit b1bff70

Please sign in to comment.