Skip to content

Commit

Permalink
last changes
Browse files Browse the repository at this point in the history
  • Loading branch information
coastalwhite committed Oct 8, 2024
1 parent 1c53382 commit 2445782
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 55 deletions.
3 changes: 1 addition & 2 deletions crates/polars-arrow/src/io/avro/read/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ fn make_mutable(
.iter()
.map(|field| make_mutable(field.dtype(), None, capacity))
.collect::<PolarsResult<Vec<_>>>()?;
Box::new(DynMutableStructArray::new(values, dtype.clone()))
as Box<dyn MutableArray>
Box::new(DynMutableStructArray::new(values, dtype.clone())) as Box<dyn MutableArray>
},
other => {
polars_bail!(nyi = "Deserializing type {other:#?} is still not implemented")
Expand Down
6 changes: 5 additions & 1 deletion crates/polars-core/src/serde/series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,11 @@ impl<'de> Deserialize<'de> for Series {

for (f, v) in fields.iter().zip(values.iter()) {
if f.dtype() != v.dtype() {
let err = format!("type mismatch for struct. expected: {}, given: {}", f.dtype(), v.dtype());
let err = format!(
"type mismatch for struct. expected: {}, given: {}",
f.dtype(),
v.dtype()
);
return Err(de::Error::custom(err));
}
}
Expand Down
7 changes: 5 additions & 2 deletions crates/polars-expr/src/expressions/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,11 @@ impl PhysicalExpr for WindowExpr {
.1,
)
} else {
let df_right = unsafe { DataFrame::new_no_checks_height_from_first(keys) };
let df_left = unsafe { DataFrame::new_no_checks_height_from_first(group_by_columns) };
let df_right =
unsafe { DataFrame::new_no_checks_height_from_first(keys) };
let df_left = unsafe {
DataFrame::new_no_checks_height_from_first(group_by_columns)
};
Ok(private_left_join_multiple_keys(&df_left, &df_right, true)?.1)
}
};
Expand Down
6 changes: 1 addition & 5 deletions crates/polars-ops/src/series/ops/to_dummies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ impl ToDummies for Series {
})
.collect::<Vec<_>>();

Ok(unsafe {
DataFrame::new_no_checks_height_from_first(
sort_columns(columns),
)
})
Ok(unsafe { DataFrame::new_no_checks_height_from_first(sort_columns(columns)) })
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/polars-pipe/src/executors/sources/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl Source for CsvSource {
for data_chunk in &mut out {
// The batched reader creates the column containing all nulls because the schema it
// gets passed contains the column.
//
//
// SAFETY: Columns are only replaced with columns
// 1. of the same name, and
// 2. of the same length.
Expand Down
6 changes: 2 additions & 4 deletions crates/polars-plan/src/plans/functions/merge_sorted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ pub(super) fn merge_sorted(df: &DataFrame, column: &str) -> PolarsResult<DataFra
)
};

let left =
unsafe { DataFrame::new_no_checks_height_from_first(left_cols) };
let right =
unsafe { DataFrame::new_no_checks_height_from_first(right_cols) };
let left = unsafe { DataFrame::new_no_checks_height_from_first(left_cols) };
let right = unsafe { DataFrame::new_no_checks_height_from_first(right_cols) };

let lhs = left.column(column)?;
let rhs = right.column(column)?;
Expand Down
43 changes: 23 additions & 20 deletions crates/polars/tests/it/io/avro/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,26 +265,29 @@ fn struct_data() -> RecordBatchT<Box<dyn Array>> {
Field::new("item2".into(), ArrowDataType::Int32, true),
]);

RecordBatchT::new(2, vec![
Box::new(StructArray::new(
struct_dt.clone(),
2,
vec![
Box::new(PrimitiveArray::<i32>::from_slice([1, 2])),
Box::new(PrimitiveArray::<i32>::from([None, Some(1)])),
],
None,
)),
Box::new(StructArray::new(
struct_dt,
2,
vec![
Box::new(PrimitiveArray::<i32>::from_slice([1, 2])),
Box::new(PrimitiveArray::<i32>::from([None, Some(1)])),
],
Some([true, false].into()),
)),
])
RecordBatchT::new(
2,
vec![
Box::new(StructArray::new(
struct_dt.clone(),
2,
vec![
Box::new(PrimitiveArray::<i32>::from_slice([1, 2])),
Box::new(PrimitiveArray::<i32>::from([None, Some(1)])),
],
None,
)),
Box::new(StructArray::new(
struct_dt,
2,
vec![
Box::new(PrimitiveArray::<i32>::from_slice([1, 2])),
Box::new(PrimitiveArray::<i32>::from([None, Some(1)])),
],
Some([true, false].into()),
)),
],
)
}

fn avro_record() -> Record {
Expand Down
31 changes: 17 additions & 14 deletions crates/polars/tests/it/io/parquet/arrow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1421,20 +1421,23 @@ fn generic_data() -> PolarsResult<(ArrowSchema, RecordBatchT<Box<dyn Array>>)> {
Field::new("a12".into(), array12.dtype().clone(), true),
Field::new("a13".into(), array13.dtype().clone(), true),
]);
let chunk = RecordBatchT::try_new(array1.len(), vec![
array1.boxed(),
array2.boxed(),
array3.boxed(),
array4.boxed(),
array6.boxed(),
array7.boxed(),
array8.boxed(),
array9.boxed(),
array10.boxed(),
array11.boxed(),
array12.boxed(),
array13.boxed(),
])?;
let chunk = RecordBatchT::try_new(
array1.len(),
vec![
array1.boxed(),
array2.boxed(),
array3.boxed(),
array4.boxed(),
array6.boxed(),
array7.boxed(),
array8.boxed(),
array9.boxed(),
array10.boxed(),
array11.boxed(),
array12.boxed(),
array13.boxed(),
],
)?;

Ok((schema, chunk))
}
Expand Down
9 changes: 3 additions & 6 deletions py-polars/tests/unit/dataframe/test_null_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
def test_null_count(df: pl.DataFrame) -> None:
# note: the zero-row and zero-col cases are always passed as explicit examples
null_count, ncols = df.null_count(), len(df.columns)
if ncols == 0:
assert null_count.shape == (0, 0)
else:
assert null_count.shape == (1, ncols)
for idx, count in enumerate(null_count.rows()[0]):
assert count == sum(v is None for v in df.to_series(idx).to_list())
assert null_count.shape == (1, ncols)
for idx, count in enumerate(null_count.rows()[0]):
assert count == sum(v is None for v in df.to_series(idx).to_list())

0 comments on commit 2445782

Please sign in to comment.