Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The pivot feature does not compile in Rust polars v38-40. #16691

Closed
2 tasks done
LegoWolf opened this issue Jun 3, 2024 · 2 comments
Closed
2 tasks done

The pivot feature does not compile in Rust polars v38-40. #16691

LegoWolf opened this issue Jun 3, 2024 · 2 comments
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer rust Related to Rust Polars

Comments

@LegoWolf
Copy link

LegoWolf commented Jun 3, 2024

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

// mains.rs
use polars::prelude::*;

fn main() {
    let mut df = df![
        "foo" => ["A", "A", "B", "B", "C"],
        "bar" => ["k", "l", "m", "n", "o"],
        "N" => [1, 2, 2, 4, 2],
    ].unwrap();

    println!("{}", df);
    df = pivot::pivot(&df, ["foo"], ["bar"], ["N"], false, None, None).unwrap();
    println!("{}", df);
}
# Cargo.toml
[package]
name = "rust-runtime"
edition = "2021"

[dependencies]
polars = {version = "=0.40.0", features = ["lazy", "pivot"]}

Under Polars v37, this code compiles correctly and produces this output:

shape: (5, 3)
┌─────┬─────┬─────┐
│ foo ┆ bar ┆ N   │
│ --- ┆ --- ┆ --- │
│ str ┆ str ┆ i32 │
╞═════╪═════╪═════╡
│ A   ┆ k   ┆ 1   │
│ A   ┆ l   ┆ 2   │
│ B   ┆ m   ┆ 2   │
│ B   ┆ n   ┆ 4   │
│ C   ┆ o   ┆ 2   │
└─────┴─────┴─────┘
unstable pivot not yet supported, using stable pivot
shape: (5, 4)
┌─────┬──────┬──────┬──────┐
│ bar ┆ 1    ┆ 2    ┆ 4    │
│ --- ┆ ---  ┆ ---  ┆ ---  │
│ str ┆ str  ┆ str  ┆ str  │
╞═════╪══════╪══════╪══════╡
│ k   ┆ A    ┆ null ┆ null │
│ l   ┆ null ┆ A    ┆ null │
│ m   ┆ null ┆ B    ┆ null │
│ n   ┆ null ┆ null ┆ B    │
│ o   ┆ null ┆ C    ┆ null │
└─────┴──────┴──────┴──────┘

But under v38, 39 and 40, the polars-ops crate fails to compile in this example.

Log output

Providing compilation output:

error[E0531]: cannot find tuple struct or tuple variant `Struct` in this scope
   --> /home/ec2-user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-ops-0.40.0/src/frame/pivot/positioning.rs:252:9
    |
252 |         Struct(_) => {
    |         ^^^^^^ not found in this scope
    |
help: consider importing one of these items
    |
1   + use arrow::datatypes::ArrowDataType::Struct;
    |
1   + use polars_core::prelude::ArrowDataType::Struct;
    |

error[E0531]: cannot find tuple struct or tuple variant `Struct` in this scope
   --> /home/ec2-user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-ops-0.40.0/src/frame/pivot/positioning.rs:418:13
    |
418 |             Struct(_) => {
    |             ^^^^^^ not found in this scope
    |
help: consider importing one of these items
    |
1   + use arrow::datatypes::ArrowDataType::Struct;
    |
1   + use polars_core::prelude::ArrowDataType::Struct;
    |

error[E0599]: no method named `struct_` found for enum `std::borrow::Cow<'_, polars_core::prelude::Series>` in the current scope
   --> /home/ec2-user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-ops-0.40.0/src/frame/pivot/positioning.rs:253:42
    |
253 |             let ca = column_agg_physical.struct_().unwrap();
    |                                          ^^^^^^^ method not found in `Cow<'_, Series>`

error[E0599]: no method named `struct_` found for enum `std::borrow::Cow<'_, polars_core::prelude::Series>` in the current scope
   --> /home/ec2-user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-ops-0.40.0/src/frame/pivot/positioning.rs:419:45
    |
419 |                 let ca = index_agg_physical.struct_().unwrap();
    |                                             ^^^^^^^ method not found in `Cow<'_, Series>`

error[E0433]: failed to resolve: use of undeclared type `StructChunked`
   --> /home/ec2-user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-ops-0.40.0/src/frame/pivot/positioning.rs:461:35
    |
461 |         let index_struct_series = StructChunked::new("placeholder", fields)?.into_series();
    |                                   ^^^^^^^^^^^^^
    |                                   |
    |                                   use of undeclared type `StructChunked`
    |                                   help: a type alias with a similar name exists: `StringChunked`

error[E0599]: no method named `struct_` found for reference `&polars_core::prelude::Series` in the current scope
   --> /home/ec2-user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-ops-0.40.0/src/frame/pivot/positioning.rs:470:18
    |
469 | /             unsafe { x.get_unchecked(0) }
470 | |                 .struct_()
    | |                 -^^^^^^^ method not found in `&Series`
    | |_________________|
    | 

error[E0433]: failed to resolve: use of undeclared type `StructChunked`
   --> /home/ec2-user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-ops-0.40.0/src/frame/pivot/mod.rs:222:30
    |
222 |         let columns_struct = StructChunked::new(&column, fields).unwrap().into_series();
    |                              ^^^^^^^^^^^^^
    |                              |
    |                              use of undeclared type `StructChunked`
    |                              help: a type alias with a similar name exists: `StringChunked`

Some errors have detailed explanations: E0433, E0531, E0599.
For more information about an error, try `rustc --explain E0433`.
error: could not compile `polars-ops` (lib) due to 7 previous errors

Issue description

The provided code compiles without error using polars v37. But in every subsequent version up to v40, compilation fails in these source files:

polars-ops-0.40.0/src/frame/pivot/mod.rs
polars-ops-0.40.0/src/frame/pivot/positioning.rs

These crate files appear to be missing some use statements to include necessary data types.

Expected behavior

The polars pivot feature should compile correctly or provide an error message that explains what configuration parameters I need to change to compile correctly.

Installed versions

lazy, pivot

@LegoWolf LegoWolf added bug Something isn't working needs triage Awaiting prioritization by a maintainer rust Related to Rust Polars labels Jun 3, 2024
@cmdlineluser
Copy link
Contributor

Seems like the dtype-struct feature is now a strict requirement for pivot?

@LegoWolf
Copy link
Author

LegoWolf commented Jun 3, 2024

Thanks so much! it turns out that was the source of my problem.

@LegoWolf LegoWolf closed this as completed Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer rust Related to Rust Polars
Projects
None yet
Development

No branches or pull requests

2 participants