error[E0599]: no method named str found for enum Expr in the current scope

When I try to build the below code, I am receiving the error

error[E0599]: no method named str found for enum Expr in the current scope
41 | col("Name").str().ends_with(lit(" Common")).or(col("Name").str().ends_with(lit(" ADR")))
| ^^^

use polars::prelude::*;
use std::result::Result;
use std::sync::Arc;

fn get() -> Result<DataFrame, PolarsError> {
    let dtypes = Schema::from_iter(
        vec![
            Field::new("Symbol", DataType::String),
            Field::new("Name", DataType::String),
            Field::new("Exchange", DataType::String)
        ]
    );

    let option_schema: Option<SchemaRef> = Some(Arc::new(dtypes));

    let exc = vec!["Cboe BZX", "OTC"];

    let df = LazyCsvReader::new("somepath/names.txt")
        .with_has_header(true)
        .with_schema(option_schema)
        .finish()?
        .filter(col("Exchange")
            .is_in(lit(Series::new("exc", exc)))
            .not()
            .and(
                col("Name").str().ends_with(lit(" Common")).or(col("Name").str().ends_with(lit(" ADR")))
            )).collect()?;
    Ok(df)
}

Thanks in advance for any help

Expr::str needs the strings feature enabled. Try adding it to the dependency declaration of Polars in your manifest file (Cargo.toml):

polars = { version = "0.42", features = ["strings"] }
2 Likes

Thank you so much! I am very competent in polars and python, but currently I literally struggle in rust.

1 Like

I don't doubt it, Polars Rust API is one of the most complex ones I've used so far.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.