This is an automated email from the ASF dual-hosted git repository.

houqp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/master by this push:
     new 2615628  register datafusion.functions as a python package (#995)
2615628 is described below

commit 2615628007f415d5064cb05a05d234f117e55d35
Author: QP Hou <[email protected]>
AuthorDate: Mon Sep 13 18:02:31 2021 -0700

    register datafusion.functions as a python package (#995)
---
 python/src/lib.rs | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/python/src/lib.rs b/python/src/lib.rs
index aecfe99..4436781 100644
--- a/python/src/lib.rs
+++ b/python/src/lib.rs
@@ -29,6 +29,19 @@ mod types;
 mod udaf;
 mod udf;
 
+// taken from https://github.com/PyO3/pyo3/issues/471
+fn register_module_package(py: Python, package_name: &str, module: &PyModule) {
+    py.import("sys")
+        .expect("failed to import python sys module")
+        .dict()
+        .get_item("modules")
+        .expect("failed to get python modules dictionary")
+        .downcast::<pyo3::types::PyDict>()
+        .expect("failed to turn sys.modules into a PyDict")
+        .set_item(package_name, module)
+        .expect("failed to inject module");
+}
+
 /// DataFusion.
 #[pymodule]
 fn datafusion(py: Python, m: &PyModule) -> PyResult<()> {
@@ -38,6 +51,7 @@ fn datafusion(py: Python, m: &PyModule) -> PyResult<()> {
 
     let functions = PyModule::new(py, "functions")?;
     functions::init(functions)?;
+    register_module_package(py, "datafusion.functions", functions);
     m.add_submodule(functions)?;
 
     Ok(())

Reply via email to