jorisvandenbossche commented on a change in pull request #12311:
URL: https://github.com/apache/arrow/pull/12311#discussion_r800639497



##########
File path: python/pyarrow/table.pxi
##########
@@ -1177,10 +1177,18 @@ cdef class RecordBatch(_PandasConvertible):
         pyarrow.RecordBatch
         """
         from pyarrow.pandas_compat import dataframe_to_arrays
-        arrays, schema = dataframe_to_arrays(
+        arrays, schema, n_rows = dataframe_to_arrays(
             df, schema, preserve_index, nthreads=nthreads, columns=columns
         )
-        return cls.from_arrays(arrays, schema=schema)
+
+        # If df is empty but row index is not, create empty RecordBatch with 
rows >0
+        cdef:
+            vector[shared_ptr[CArray]] c_arrays

Review comment:
       ```suggestion
           cdef vector[shared_ptr[CArray]] c_arrays
   ```
   
   (for a single definition can also put it on a single line)

##########
File path: python/pyarrow/table.pxi
##########
@@ -1779,15 +1787,23 @@ cdef class Table(_PandasConvertible):
         <pyarrow.lib.Table object at 0x7f05d1fb1b40>
         """
         from pyarrow.pandas_compat import dataframe_to_arrays
-        arrays, schema = dataframe_to_arrays(
+        arrays, schema, n_rows = dataframe_to_arrays(
             df,
             schema=schema,
             preserve_index=preserve_index,
             nthreads=nthreads,
             columns=columns,
             safe=safe
         )
-        return cls.from_arrays(arrays, schema=schema)
+
+        # If df is empty but row index is not, create empty Table with rows >0
+        cdef:
+            vector[shared_ptr[CChunkedArray]] c_arrays

Review comment:
       ```suggestion
           cdef vector[shared_ptr[CChunkedArray]] c_arrays
   ```




-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to