【问题标题】:Is it possible to access underlying data from Polars in cython?是否可以在 cython 中访问 Polars 的基础数据?
【发布时间】:2022-08-04 00:10:53
【问题描述】:

无论如何可以访问cython/c++中的底层结构吗?

我有许多脚本可以抓取 np.ndarrays 并进行迭代。北极星有类似的东西吗?

  • 应该是可以的。如果它已经公开了一个可以记忆查看的字节接口,应该能够很容易地破译它。否则去看看它下面有什么柱状格式。并制作一个相当于 rust 的 c++。
  • 我不太确定如何查看箭头数据
  • 它是引擎盖下的箭头,但我看不到如何本地访问

标签: python cython python-polars


【解决方案1】:

这绝对应该是可能的。 Polars 内存可以导出到 pyarrow 零拷贝。然后您可以使用箭头的C data interface 来获取该内存。

这是 Polars 存储库中的一个示例,他们使用 C 数据接口在 Rust 中再次获取该内存。 https://github.com/pola-rs/polars/tree/master/examples/python_rust_compiled_function

【讨论】:

  • 知道怎么做吗?
【解决方案2】:

polars.DataFrame([1,2,3]).to_arrow() 会得到一个可以修改的表 并编辑。

 cimport pyarrow
 cimport pyarrow.lib
 from libcpp.memory cimport shared_ptr
 cdef  iterate_through_table(polars_obj):
     cdef:
         shared_ptr[pyarrow.CTable] table = pyarrow.lib.unwrap_table(polars.to_arrow())   
     

【讨论】:

    猜你喜欢
    • 2023-02-10
    • 1970-01-01
    • 2012-06-02
    • 2018-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-28
    • 2012-12-07
    相关资源
    最近更新 更多