Skip to content

Commit

Permalink
Use null count to check for contiguous slices (#2849)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamasfe committed Mar 8, 2022
1 parent 3e1071d commit d98e752
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion polars/polars-core/src/chunked_array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ where
{
/// Contiguous slice
pub fn cont_slice(&self) -> Result<&[T::Native]> {
if self.chunks.len() == 1 && !self.chunks[0].has_validity() {
if self.chunks.len() == 1 && self.chunks[0].null_count() == 0 {
Ok(self.downcast_iter().next().map(|arr| arr.values()).unwrap())
} else {
Err(PolarsError::ComputeError("cannot take slice".into()))
Expand Down
20 changes: 20 additions & 0 deletions polars/tests/it/joins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,23 @@ fn join_nans_outer() -> Result<()> {
assert_eq!(res.shape(), (4, 4));
Ok(())
}

#[test]
#[cfg(feature = "lazy")]
fn join_empty_datasets() -> Result<()> {
let a = DataFrame::new(Vec::from([Series::new_empty("foo", &DataType::Int64)])).unwrap();
let b = DataFrame::new(Vec::from([
Series::new_empty("foo", &DataType::Int64),
Series::new_empty("bar", &DataType::Int64),
]))
.unwrap();

a.lazy()
.groupby([col("foo")])
.agg([all().last()])
.inner_join(b.lazy(), "foo", "foo")
.collect()
.unwrap();

Ok(())
}

0 comments on commit d98e752

Please sign in to comment.