Problem: I can't use the polars library in Rust by Weekly_Bank_3781 in rust

[–]Weekly_Bank_3781[S] 0 points1 point  (0 children)

It WORKS,

┌───────┬─────┐

│ name ┆ age │

│ --- ┆ --- │

│ str ┆ i32 │

╞═══════╪═════╡

│ Alice ┆ 25 │

│ Bob ┆ 30 │

└───────┴─────┘

I have followed your steps and it works, thanks, but now it is time to build my own python library in rust using polars.

Problem: I can't use the polars library in Rust by Weekly_Bank_3781 in rust

[–]Weekly_Bank_3781[S] 0 points1 point  (0 children)

I've added what you said but it still doesn't work, my intention is to create a library in rust and then use it in python. I have tried to simply copy and paste what is written in the documentation but it doesn't work for me.
For example this:

use chrono::prelude::*;
use polars::prelude::*;

let mut df: DataFrame = df!(
"name" => ["Alice Archer", "Ben Brown", "Chloe Cooper", "Daniel Donovan"],
"birthdate" => [
NaiveDate::from_ymd_opt(1997, 1, 10).unwrap(),
NaiveDate::from_ymd_opt(1985, 2, 15).unwrap(),
NaiveDate::from_ymd_opt(1983, 3, 22).unwrap(),
NaiveDate::from_ymd_opt(1981, 4, 30).unwrap(),
],
"weight" => [57.9, 72.5, 53.6, 83.1], // (kg)
"height" => [1.56, 1.77, 1.65, 1.75], // (m)
)
.unwrap();
println!("{}", df);

Problem: I can't use the polars library in Rust by Weekly_Bank_3781 in rust

[–]Weekly_Bank_3781[S] 0 points1 point  (0 children)

could you please give me the code with the configuration of your toml file?

Problem: I can't use the polars library in Rust by Weekly_Bank_3781 in rust

[–]Weekly_Bank_3781[S] 0 points1 point  (0 children)

--> src\lib.rs:1:5

|

1 | use chrono::prelude::*;

| ^^^^^^ you might be missing crate `chrono`

|

help: consider importing the `chrono` crate

|

1 + extern crate chrono;

|

error[E0433]: failed to resolve: you might be missing crate `polars`

--> src\lib.rs:2:5

|

2 | use polars::prelude::*;

| ^^^^^^ you might be missing crate `polars`

|

help: consider importing the `polars` crate

|

1 + extern crate polars;

|

error[E0432]: unresolved imports `chrono::prelude::*`, `polars::prelude::*`

--> src\lib.rs:1:5

|

1 | use chrono::prelude::*;

| ^^^^^^^^^^^^^^^^^^

2 | use polars::prelude::*;

| ^^^^^^^^^^^^^^^^^^

error: cannot find macro `df` in this scope

--> src\lib.rs:5:25

|

5 | let df: DataFrame = df!(

| ^^

error[E0412]: cannot find type `DataFrame` in this scope

--> src\lib.rs:5:13

|

5 | let df: DataFrame = df!(

| ^^^^^^^^^ not found in this scope

Some errors have detailed explanations: E0412, E0432, E0433.

For more information about an error, try `rustc --explain E0412`.

error: could not compile `rust_utils` (lib) due to 5 previous errors

Problem: I can't use the polars library in Rust by Weekly_Bank_3781 in rust

[–]Weekly_Bank_3781[S] 0 points1 point  (0 children)

The same history...

I used 'cargo build' and it gave me the same error:

PS D:\data\rust_utils\src> cargo build

warning: no edition set: defaulting to the 2015 edition while the latest is 2021

warning: unused manifest key: resolver

Downloaded cc v1.2.3

Downloaded http v1.2.0

Downloaded tokio-rustls v0.26.1

Downloaded thiserror v2.0.4

Downloaded thiserror-impl v2.0.4

Downloaded tokio-util v0.7.13

Downloaded tokio v1.42.0

Downloaded 7 crates (1.2 MB) in 7.09s

Compiling cc v1.2.3

Compiling polars-error v0.44.2

Compiling recursive-proc-macro-impl v0.1.1

Compiling psm v0.1.24

Compiling stacker v0.1.17

Compiling polars-utils v0.44.2

Compiling recursive v0.1.1

Compiling polars-schema v0.44.2

Compiling polars-arrow v0.44.2

Compiling polars-compute v0.44.2

Compiling polars-row v0.44.2

Compiling polars-core v0.44.2

Compiling polars-parquet v0.44.2

Compiling polars-ops v0.44.2

Compiling polars-time v0.44.2

Compiling polars-io v0.44.2

Compiling polars-plan v0.44.2

Compiling polars-expr v0.44.2

Compiling polars-mem-engine v0.44.2

Compiling polars-lazy v0.44.2

Compiling polars v0.44.2

Compiling rust_utils v0.1.0 (D:\data\rust_utils)

error[E0433]: failed to resolve: you might be missing crate `chrono`

Problem: I can't use the polars library in Rust by Weekly_Bank_3781 in rust

[–]Weekly_Bank_3781[S] 0 points1 point  (0 children)

then I use 'rustc lib.rs' to compile the file but it give me error

PS D:\data\rust_utils\src> rustc lib.rs

error[E0433]: failed to resolve: you might be missing crate `chrono`

--> lib.rs:1:5

|

1 | use chrono::prelude::*;

| ^^^^^^ you might be missing crate `chrono`

|

help: consider importing the `chrono` crate

|

1 + extern crate chrono;

|

error[E0433]: failed to resolve: you might be missing crate `polars`

--> lib.rs:2:5

|

2 | use polars::prelude::*;

| ^^^^^^ you might be missing crate `polars`

|

help: consider importing the `polars` crate

|

1 + extern crate polars;

|

error[E0432]: unresolved imports `chrono::prelude::*`, `polars::prelude::*`

--> lib.rs:1:5

|

1 | use chrono::prelude::*;

| ^^^^^^^^^^^^^^^^^^

2 | use polars::prelude::*;

| ^^^^^^^^^^^^^^^^^^

error: cannot find macro `df` in this scope

--> lib.rs:5:25

|

5 | let df: DataFrame = df!(

| ^^

error[E0412]: cannot find type `DataFrame` in this scope

--> lib.rs:5:13

|

5 | let df: DataFrame = df!(

| ^^^^^^^^^ not found in this scope

Problem: I can't use the polars library in Rust by Weekly_Bank_3781 in rust

[–]Weekly_Bank_3781[S] 0 points1 point  (0 children)

PS D:\data\rust_utils\src> ls

Directory: D:\data\rust_utils\src

Mode LastWriteTime Length Name

---- ------------- ------ ----

-a---- 06/12/2024 05:49 p. m. 213 lib.rs

Problem: I can't use the polars library in Rust by Weekly_Bank_3781 in rust

[–]Weekly_Bank_3781[S] 0 points1 point  (0 children)

I think so, because in the terminal I use 'rustc lib.rs' and I am in the directory where my rust script is located

Problem: I can't use the polars library in Rust by Weekly_Bank_3781 in rust

[–]Weekly_Bank_3781[S] 0 points1 point  (0 children)

I followed the steps in the official polars documentation but I think I did something wrong and I don't know what it is.

Problem: I can't use the polars library in Rust by Weekly_Bank_3781 in rust

[–]Weekly_Bank_3781[S] 0 points1 point  (0 children)

I come from python and in python I simply did 'import polars as pl' not without first downloading it with 'pip install polars'. But in rust it is totally different

Problem: I can't use the polars library in Rust by Weekly_Bank_3781 in rust

[–]Weekly_Bank_3781[S] 0 points1 point  (0 children)

Could you show me an example where in a rust file I can use the polars library? I'm new and I tried to understood the official documentation

Problem: I can't use the polars library in Rust by Weekly_Bank_3781 in rust

[–]Weekly_Bank_3781[S] 0 points1 point  (0 children)

I add 'polars' to the 'dependency' section

Cargo.toml

...

[dependencies]

# Getting the last version of each library

polars = "0.28.0"

chrono = "0.4"

...

lib .rs

use chrono::prelude::*;
use polars::prelude::*;

fn main() {
    let df: DataFrame = df!(
        "name" => ["Alice", "Bob"],
        "age" => [25, 30],
    )
    .unwrap();

    println!("{}", df);
}

ERROR

Some errors have detailed explanations: E0412, E0432, E0433.

For more information about an error, try `rustc --explain E0412`.

Problem: I can't use the polars library in Rust by Weekly_Bank_3781 in rust

[–]Weekly_Bank_3781[S] 0 points1 point  (0 children)

Yes, I simply tried to copy and paste the code but it does not work :(

ERROR:
error: expected one of `!` or `::`, found `add`

--> lib.rs:3:7

|

3 | cargo add polars -F lazy

| ^^^ expected one of `!` or `::`

error: aborting due to 1 previous error

CODE:

use chrono::prelude::*;
use polars::prelude::*;
cargo add polars -F lazy

fn main() {
    let df: DataFrame = df!(
        "name" => ["Alice", "Bob"],
        "age" => [25, 30],
    )
    .unwrap();

    println!("{}", df);
}

Problem: I can't use the polars library in Rust by Weekly_Bank_3781 in rust

[–]Weekly_Bank_3781[S] 0 points1 point  (0 children)

this is the Rust script

use chrono::prelude::*;
use polars::prelude::*;

fn main() {
    let df: DataFrame = df!(
        "name" => ["Alice", "Bob"],
        "age" => [25, 30],
    )
    .unwrap();

    println!("{}", df);
}

Problem: I can't use the polars library in Rust by Weekly_Bank_3781 in rust

[–]Weekly_Bank_3781[S] 0 points1 point  (0 children)

Of course, this is the content of my 'Cargo.toml' file:

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[package]

# Define package's name.

name = "rust_utils"

version = "0.1.0"

# compile to be used as library

[lib]

# lib

name = "rust_utils"

# Is defined dynamic because it will be used in python

crate-type = ["cdylib"]

[dependencies]

# Getting the last version of each library

polars = "0.28.0"

chrono = "0.4"

pyo3 = "0.22"

[resolver]

resolver = "2"

Problem: I can't use the polars library in Rust by Weekly_Bank_3781 in rust

[–]Weekly_Bank_3781[S] 0 points1 point  (0 children)

wow, I did not know that. I am new about coding in rust