Repository: pola-rs/polars
File: crates/polars-core/src/frame/horizontal.rs (Rust)

Code before:
    /// ```rust
    /// # use polars_core::prelude::*;
    /// fn stack(df: &mut DataFrame, columns: &[Column]) {
    ///     df.hstack_mut(columns);
    /// }
    /// ```
    pub fn hstack_mut(&mut self, columns: &[Column]) -> PolarsResult<&mut Self> {
        self.clear_schema();
        self.columns.extend_from_slice(columns);

        if let err @ Err(_) = DataFrame::validate_columns_slice(&self.columns) {
            // Reset DataFrame state to before extend.
            self.columns.truncate(self.columns.len() - columns.len());
            err?;
        }

        if let Some(c) = self.columns.first() {
            unsafe { self.set_height(c.len()) };
        }

        Ok(self)
    }
}

/// Concat [`DataFrame`]s horizontally.
/// Concat horizontally and when extend with null values if lengths don't match and `strict`=false, raises `ShapeError` otherwise
pub fn concat_df_horizontal(
    dfs: &[DataFrame],
    check_duplicates: bool,
    strict: bool,
) -> PolarsResult<DataFrame> {
    let output_height = dfs
        .iter()
        .map(|df| df.height())
        .max()
        .ok_or_else(|| polars_err!(ComputeError: "cannot concat empty dataframes"))?;

    let owned_df;

    let mut out_width = 0;

    let all_equal_height = dfs.iter().all(|df| {
        out_width += df.width();
        df.height() == output_height
    });

    // if not all equal length, extend the DataFrame with nulls
    let dfs = if !all_equal_height {
        if strict {
            return Err(
                polars_err!(ShapeMismatch: "cannot concat dataframes with different heights in 'strict' mode"),

Review comment (suggestion):
Docstring repeats itself and is missing a period. I'd suggest

```rust
/// Concat [`DataFrame`]s horizontally.
/// 
/// If the lengths don't match and strict is false we pad with nulls, or return a `ShapeError` if strict is true.
```

Code after:
    /// ```rust
    /// # use polars_core::prelude::*;
    /// fn stack(df: &mut DataFrame, columns: &[Column]) {
    ///     df.hstack_mut(columns);
    /// }
    /// ```
    pub fn hstack_mut(&mut self, columns: &[Column]) -> PolarsResult<&mut Self> {
        self.clear_schema();
        self.columns.extend_from_slice(columns);

        if let err @ Err(_) = DataFrame::validate_columns_slice(&self.columns) {
            // Reset DataFrame state to before extend.
            self.columns.truncate(self.columns.len() - columns.len());
            err?;
        }

        if let Some(c) = self.columns.first() {
            unsafe { self.set_height(c.len()) };
        }

        Ok(self)
    }
}

/// Concat [`DataFrame`]s horizontally.
///
/// If the lengths don't match and strict is false we pad with nulls, or return a `ShapeError` if strict is true.
pub fn concat_df_horizontal(
    dfs: &[DataFrame],
    check_duplicates: bool,
    strict: bool,
) -> PolarsResult<DataFrame> {
    let output_height = dfs
        .iter()
        .map(|df| df.height())
        .max()
        .ok_or_else(|| polars_err!(ComputeError: "cannot concat empty dataframes"))?;

    let owned_df;

    let mut out_width = 0;

    let all_equal_height = dfs.iter().all(|df| {
        out_width += df.width();
        df.height() == output_height
    });

    // if not all equal length, extend the DataFrame with nulls
    let dfs = if !all_equal_height {
        if strict {
            return Err(