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



##########
File path: python/pyarrow/table.pxi
##########
@@ -1771,6 +1771,22 @@ cdef class Table(_PandasConvertible):
                 raise TypeError(type(item))
 
         result = pyarrow_wrap_table(CTable.Make(c_schema, columns))
+
+        # In case of an empty dataframe with RangeIndex -> create an empty 
Table with
+        # number of rows equal to Index length
+        if arrays == [] and schema is not None:
+            try:
+                kind = schema.pandas_metadata["index_columns"][0]["kind"]
+                if kind =="range":
+                    start = schema.pandas_metadata["index_columns"][0]["start"]
+                    stop = schema.pandas_metadata["index_columns"][0]["stop"]
+                    step = schema.pandas_metadata["index_columns"][0]["step"]
+                    n_rows = (stop - start - 1)//step + 1
+                    result = pyarrow_wrap_table(
+                        CTable.MakeWithRows(c_schema, columns, n_rows))
+            except IndexError:
+                pass

Review comment:
       Or we could maybe even move the actual check to `dataframe_to_arrays`, 
since you already have a `pandas_metadata` object there. And then we can add a 
third return argument that is always None, except if you have this case of no 
columns but a range index (and then can return the range index info or length)




-- 
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