kylebarron commented on code in PR #9439:
URL: https://github.com/apache/arrow-rs/pull/9439#discussion_r2955401196


##########
arrow-pyarrow/src/lib.rs:
##########
@@ -606,21 +595,52 @@ impl FromPyArrow for Table {
 /// Convert a [`Table`] into `pyarrow.Table`.
 impl IntoPyArrow for Table {
     fn into_pyarrow(self, py: Python) -> PyResult<Bound<PyAny>> {
-        let module = py.import(intern!(py, "pyarrow"))?;
-        let class = module.getattr(intern!(py, "Table"))?;
-
         let py_batches = PyList::new(py, 
self.record_batches.into_iter().map(PyArrowType))?;
         let py_schema = PyArrowType(Arc::unwrap_or_clone(self.schema));
 
         let kwargs = PyDict::new(py);
         kwargs.set_item("schema", py_schema)?;
 
-        let reader = class.call_method("from_batches", (py_batches,), 
Some(&kwargs))?;
+        let reader = table_class(py)?.call_method("from_batches", 
(py_batches,), Some(&kwargs))?;
 
         Ok(reader)
     }
 }
 
+fn array_class(py: Python<'_>) -> PyResult<&Bound<'_, PyType>> {
+    static TYPE: PyOnceLock<Py<PyType>> = PyOnceLock::new();
+    TYPE.import(py, "pyarrow", "Array")

Review Comment:
   I see; so it's just saving two lookups into the CPython HashMap? I guess 
that's not nothing, but it's not the slow module reinitialization I was worried 
it was.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to