我使用 Polars 与 ConnectorX:为什么我会收到 Dataframe 类型错误?

huangapple go评论53阅读模式
英文:

I'm using Polars with ConnectorX: why do I get Dataframe type error

问题

我试图从Postgres数据库中获取表格描述。我使用ConnectorX与Arrow2目标,尝试将其存储在Polars Dataframe中。

这是连接定义:

use connectorx::prelude::*;
use polars_core;
use std::convert::TryFrom;

let source_conn = SourceConn::try_from(
    "postgresql://postgres:postgres@127.0.0.1:5432/oceanics?cxprotocol=binary",
).expect("parse conn str failed");
let queries = &[CXQuery::from(
    "SELECT * FROM information_schema.columns where table_name = 'spicyperfmanager'",
)];
let destination: Arrow2Destination =
    get_arrow2(&source_conn, None, queries).expect("run failed");

然后我尝试从查询中提取数据:

let df: polars_core::frame::DataFrame = destination.polars().unwrap();
println!("{:?}", df);

但我收到以下错误:

error[E0308]: mismatched types
   --> src/data.rs:16:45
    |
16  |     let df: polars_core::frame::DataFrame = destination.polars().unwrap();
    |             -----------------------------   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `DataFrame`, found `polars_core::frame::DataFrame`
    |             |
    |             expected due to this
    |
    = note: `polars_core::frame::DataFrame` and `DataFrame` have similar names, but are actually distinct types

这是Cargo依赖项:

[dependencies]
connectorx = { version = "0.3.1", features = ["dst_arrow", "src_postgres", "dst_arrow2"] }
polars-core = "0.30.0"

我尝试过使用polars::prelude的DataFrame,也尝试过使用polars-core::frame的DataFrame,但似乎无法理解我在类型方面做错了什么。

英文:

I'm trying to get the table description from a Postgres database. I use ConnectorX with Arrow2 destination and I'm trying to store it in a Polars Dataframe.

Here's the connection definition:

use connectorx::prelude::*;
use polars_core;
use std::convert::TryFrom;

let source_conn = SourceConn::try_from(
    "postgresql://postgres:postgres@127.0.0.1:5432/oceanics?cxprotocol=binary",
)
.expect("parse conn str failed");
let queries = &[CXQuery::from(
    "SELECT * FROM information_schema.columns where table_name = 'spicyperfmanager'",
)];
let destination: Arrow2Destination =
    get_arrow2(&source_conn, None, queries).expect("run failed");

Then I try to extract the data from the query:

let df: polars_core::frame::DataFrame = destination.polars().unwrap();
println!("{:?}", df);

But I get the following error:

error[E0308]: mismatched types
   --> src/data.rs:16:45
    |
16  |     let df: polars_core::frame::DataFrame = destination.polars().unwrap();
    |             -----------------------------   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `DataFrame`, found `polars_core::frame::DataFrame`
    |             |
    |             expected due to this
    |
    = note: `polars_core::frame::DataFrame` and `DataFrame` have similar names, but are actually distinct types

Here's the cargo dependencies:

[dependencies]
connectorx = { version = "0.3.1", features = ["dst_arrow", "src_postgres", "dst_arrow2"] }
polars-core = "0.30.0"

I tried using the polars::prelude DataFrame, the polars-core::frame DataFrame, but I can't seem to wrap my head around what I'm doing wrong with the typing.

答案1

得分: 1

connectorx 使用的是 polars 版本 v0.20.0,与 v0.30.0 不兼容。因此,实际上您有 两个 版本的 polars,它们的类型不兼容。

将您的 polars 降级到 v0.20.0,然后它应该可以正常工作。

通常,crate 应该公开它们公开导入的 crate,以避免这种情况,但似乎 connectorx 并没有导出它的 polarspolars_core(尽管它公开了 polars_iopolars_lazypolars_time)。

英文:

connectorx uses polars v0.20.0, and it is incompatible with v0.30.0. So you actually have two versions of polars, and their types are incompatible.

Downgrade your polars to v0.20.0, and it should work.

Usually crates should expose the crates they import publicly to avoid situations like that, but it appears connectorx does not export its polars or polars_core (although it does expose polars_io, polars_lazy and polars_time).

huangapple
  • 本文由 发表于 2023年7月13日 17:24:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76677834.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定