Repository: pola-rs/polars
File: crates/polars-time/src/upsample.rs (Rust)

Code before:
            let mut out = upsample_impl(&df, by, index_column, every, stable)?;
            out.apply(index_column, |s| s.cast(time_type).unwrap())
                .unwrap();
            Ok(out)
        },
        DataType::Int64 => {
            let mut df = source.clone();
            df.apply(index_column, |s| {
                s.cast(&DataType::Datetime(TimeUnit::Nanoseconds, None))
                    .unwrap()
            })
            .unwrap();
            let mut out = upsample_impl(&df, by, index_column, every, stable)?;
            out.apply(index_column, |s| s.cast(time_type).unwrap())
                .unwrap();
            Ok(out)
        },
        _ => {
            if by.is_empty() {
                let index_column = source.column(index_column)?;
                upsample_single_impl(source, index_column.as_materialized_series(), every)
            } else {
                let height = source.height();
                let schema = source.schema();

                let group_keys_df = unsafe {
                    DataFrame::new_no_checks(
                        height,
                        by.iter()
                            .map(|name| {
                                source.get_columns()[schema.index_of(name).unwrap()].clone()
                            })
                            .collect(),
                    )
                };
                let group_keys_schema = group_keys_df.schema();

                let groups = if stable {
                    group_keys_df.group_by_stable(group_keys_schema.iter_names_cloned())
                } else {
                    group_keys_df.group_by(group_keys_schema.iter_names_cloned())
                }?
                .into_groups();

                let non_group_keys_df = unsafe {
                    DataFrame::new_no_checks(
                        height,
                        schema
                            .iter_names()
                            .filter(|name| !group_keys_schema.contains(name.as_str()))
                            .map(|name| {

Review comment (suggestion):
```rust
let group_keys_df = df.project(schema.clone()).unwrap()
```

Code after:
            let mut out = upsample_impl(&df, by, index_column, every, stable)?;
            out.apply(index_column, |s| s.cast(time_type).unwrap())
                .unwrap();
            Ok(out)
        },
        DataType::Int64 => {
            let mut df = source.clone();
            df.apply(index_column, |s| {
                s.cast(&DataType::Datetime(TimeUnit::Nanoseconds, None))
                    .unwrap()
            })
            .unwrap();
            let mut out = upsample_impl(&df, by, index_column, every, stable)?;
            out.apply(index_column, |s| s.cast(time_type).unwrap())
                .unwrap();
            Ok(out)
        },
        _ => {
            if by.is_empty() {
                let index_column = source.column(index_column)?;
                upsample_single_impl(source, index_column.as_materialized_series(), every)
            } else {
                let height = source.height();
                let source_schema = source.schema();

                let group_keys_df = source.project_names(&by)?;
                let group_keys_schema = group_keys_df.schema();

                let groups = if stable {
                    group_keys_df.group_by_stable(group_keys_schema.iter_names_cloned())
                } else {
                    group_keys_df.group_by(group_keys_schema.iter_names_cloned())
                }?
                .into_groups();

                let non_group_keys_df = unsafe {
                    DataFrame::new_no_checks(
                        height,
                        source_schema
                            .iter_names()
                            .filter(|name| !group_keys_schema.contains(name.as_str()))
                            .map(|name| {
                                source.get_columns()[source_schema.index_of(name).unwrap()].clone()
                            })
                            .collect(),
                    )
                };

                let upsample_index_col_idx: Option<usize> =
                    non_group_keys_df.schema().index_of(index_column);