You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/02/02 08:46:04 UTC

[GitHub] [arrow] AlenkaF commented on a change in pull request #12311: ARROW-10643: [Python] Pandas<->pyarrow roundtrip failing to recreate index for empty dataframe

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



##########
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:
       Good idea! Agree 💯 
   Will try it out now and see if I can make it work.




-- 
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-unsubscribe@arrow.apache.org

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