Skip to content

Commit

Permalink
Update more references
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed May 21, 2024
1 parent 2089737 commit 1e763c9
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 28 deletions.
2 changes: 1 addition & 1 deletion crates/polars-core/src/frame/explode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl DataFrame {
pub fn explode_impl(&self, mut columns: Vec<Series>) -> PolarsResult<DataFrame> {
polars_ensure!(!columns.is_empty(), InvalidOperation: "no columns provided in explode");
let mut df = self.clone();
if self.height() == 0 {
if self.is_empty() {
for s in &columns {
df.with_column(s.explode()?)?;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-core/src/frame/group_by/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl DataFrame {
.cloned()
.collect::<Vec<_>>();
if by.is_empty() {
let groups = if self.height() == 0 {
let groups = if self.is_empty() {
vec![]
} else {
vec![[0, self.height() as IdxSize]]
Expand Down
17 changes: 10 additions & 7 deletions crates/polars-core/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,19 +729,22 @@ impl DataFrame {
self.shape().0
}

/// Check if the [`DataFrame`] is empty.
/// Returns `true` if the [`DataFrame`] contains no rows.
///
/// # Example
///
/// ```rust
/// # use polars_core::prelude::*;
/// let df1: DataFrame = df!("First name" => &[],
/// "Last name" => &[])?;
/// let df1: DataFrame = DataFrame::default();
/// assert!(df1.is_empty());
///
/// let df2: DataFrame = df!("First name" => &["Forever"],
/// let df2: DataFrame = df!("First name" => &[],
/// "Last name" => &[])?;
/// assert!(df2.is_empty());
///
/// let df3: DataFrame = df!("First name" => &["Forever"],
/// "Last name" => &["Alone"])?;
/// assert!(!df2.is_empty());
/// assert!(!df3.is_empty());
/// # Ok::<(), PolarsError>(())
/// ```
pub fn is_empty(&self) -> bool {
Expand Down Expand Up @@ -780,7 +783,7 @@ impl DataFrame {
// this DataFrame is already modified when an error occurs.
for col in columns {
polars_ensure!(
col.len() == self.height() || self.height() == 0,
col.len() == self.height() || self.is_empty(),
ShapeMismatch: "unable to hstack Series of length {} and DataFrame of height {}",
col.len(), self.height(),
);
Expand Down Expand Up @@ -1796,7 +1799,7 @@ impl DataFrame {
});
};

if self.height() == 0 {
if self.is_empty() {
let mut out = self.clone();
set_sorted(&mut out);

Expand Down
2 changes: 1 addition & 1 deletion crates/polars-core/src/utils/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn flatten_df_iter(df: &DataFrame) -> impl Iterator<Item = DataFrame> + '_ {
})
.collect();
let df = unsafe { DataFrame::new_no_checks(columns) };
if df.height() == 0 {
if df.is_empty() {
None
} else {
Some(df)
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-core/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ pub fn split_df_as_ref(df: &DataFrame, target: usize, strict: bool) -> Vec<DataF
/// Split a [`DataFrame`] into `n` parts. We take a `&mut` to be able to repartition/align chunks.
/// `strict` in that it respects `n` even if the chunks are suboptimal.
pub fn split_df(df: &mut DataFrame, target: usize) -> Vec<DataFrame> {
if target == 0 || df.height() == 0 {
if target == 0 || df.is_empty() {
return vec![df.clone()];
}
// make sure that chunks are aligned.
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-expr/src/expressions/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ impl PhysicalExpr for WindowExpr {

// 4. select the final column and return

if df.height() == 0 {
if df.is_empty() {
let field = self.phys_function.to_field(&df.schema())?;
return Ok(Series::full_null(field.name(), 0, field.data_type()));
}
Expand Down
3 changes: 1 addition & 2 deletions crates/polars-io/src/csv/write/write_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ pub(crate) fn write<W: Write>(
let cols = unsafe { std::mem::transmute::<&[Series], &[Series]>(cols) };
let mut write_buffer = write_buffer_pool.get();

// don't use df.empty, won't work if there are columns.
if df.height() == 0 {
if df.is_empty() {
return Ok(write_buffer);
}

Expand Down
12 changes: 2 additions & 10 deletions crates/polars-lazy/src/physical_plan/executors/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ impl ProjectionExec {
self.has_windows,
self.options.run_parallel,
)?;
check_expand_literals(
selected_cols,
df.height() == 0,
self.options.duplicate_check,
)
check_expand_literals(selected_cols, df.is_empty(), self.options.duplicate_check)
});

let df = POOL.install(|| iter.collect::<PolarsResult<Vec<_>>>())?;
Expand All @@ -60,11 +56,7 @@ impl ProjectionExec {
self.has_windows,
self.options.run_parallel,
)?;
check_expand_literals(
selected_cols,
df.height() == 0,
self.options.duplicate_check,
)?
check_expand_literals(selected_cols, df.is_empty(), self.options.duplicate_check)?
};

// this only runs during testing and check if the runtime type matches the predicted schema
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-lazy/src/physical_plan/executors/unique.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Executor for UniqueExec {

state.record(
|| {
if df.height() == 0 {
if df.is_empty() {
return Ok(df);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/polars-pipe/src/operators/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl DataChunk {
Self::new(self.chunk_index, data)
}
pub(crate) fn is_empty(&self) -> bool {
self.data.height() == 0
self.data.is_empty()
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/polars/tests/it/lazy/predicate_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ fn test_binaryexpr_pushdown_left_join_9506() -> PolarsResult<()> {
}?;
let df = df1.lazy().left_join(df2.lazy(), col("b"), col("b"));
let out = df.filter(col("c").eq(lit("c2"))).collect()?;
assert!(out.height() == 0);
assert!(out.is_empty());
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10379,7 +10379,7 @@ def interpolate(self) -> DataFrame:

def is_empty(self) -> bool:
"""
Check if the dataframe is empty.
Returns `True` if the DataFrame contains no rows.
Examples
--------
Expand Down

0 comments on commit 1e763c9

Please sign in to comment.