[ 
https://issues.apache.org/jira/browse/ARROW-2170?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16369270#comment-16369270
 ] 

ASF GitHub Bot commented on ARROW-2170:
---------------------------------------

wesm closed pull request #1623: ARROW-2170: [Python] construct_metadata fails 
on reading files where no index was preserved
URL: https://github.com/apache/arrow/pull/1623
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/python/pyarrow/pandas_compat.py b/python/pyarrow/pandas_compat.py
index f5e56a9b2..e8fa83fe7 100644
--- a/python/pyarrow/pandas_compat.py
+++ b/python/pyarrow/pandas_compat.py
@@ -197,8 +197,11 @@ def construct_metadata(df, column_names, index_levels, 
index_column_names,
     -------
     dict
     """
-    df_types = types[:-len(index_levels)]
-    index_types = types[-len(index_levels):]
+    # Use ntypes instead of Python shorthand notation [:-len(x)] as [:-0]
+    # behaves differently to what we want.
+    ntypes = len(types)
+    df_types = types[:ntypes - len(index_levels)]
+    index_types = types[ntypes - len(index_levels):]
 
     column_metadata = [
         get_column_metadata(
diff --git a/python/pyarrow/tests/test_parquet.py 
b/python/pyarrow/tests/test_parquet.py
index c49f3d396..bd76feb2e 100644
--- a/python/pyarrow/tests/test_parquet.py
+++ b/python/pyarrow/tests/test_parquet.py
@@ -215,6 +215,9 @@ def 
test_pandas_parquet_2_0_rountrip_read_pandas_no_index_written(tmpdir):
     arrow_table = pa.Table.from_pandas(df, preserve_index=False)
     js = json.loads(arrow_table.schema.metadata[b'pandas'].decode('utf8'))
     assert not js['index_columns']
+    # ARROW-2170
+    # While index_columns should be empty, columns needs to be filled still.
+    assert js['columns']
 
     _write_table(arrow_table, filename.strpath, version="2.0",
                  coerce_timestamps='ms')


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> [Python] construct_metadata fails on reading files where no index was 
> preserved
> -------------------------------------------------------------------------------
>
>                 Key: ARROW-2170
>                 URL: https://issues.apache.org/jira/browse/ARROW-2170
>             Project: Apache Arrow
>          Issue Type: Bug
>          Components: Python
>            Reporter: Uwe L. Korn
>            Assignee: Uwe L. Korn
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 0.9.0
>
>
> The current master will then just return an empty DataFrame.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to