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 2020/05/07 17:26:35 UTC

[GitHub] [arrow] jorisvandenbossche commented on a change in pull request #7122: ARROW-8641: [C++][Python] Sort included indices in IpcReader - Respect column selection in FeatherReader

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



##########
File path: python/pyarrow/feather.py
##########
@@ -234,11 +234,24 @@ def read_table(source, columns=None, memory_map=True):
 
     column_types = [type(column) for column in columns]
     if all(map(lambda t: t == int, column_types)):
-        return reader.read_indices(columns)
+        table = reader.read_indices(columns)
     elif all(map(lambda t: t == str, column_types)):
-        return reader.read_names(columns)
-
-    column_type_names = [t.__name__ for t in column_types]
-    raise TypeError("Columns must be indices or names. "
-                    "Got columns {} of types {}"
-                    .format(columns, column_type_names))
+        table = reader.read_names(columns)
+    else:
+        column_type_names = [t.__name__ for t in column_types]
+        raise TypeError("Columns must be indices or names. "
+                        "Got columns {} of types {}"
+                        .format(columns, column_type_names))
+
+    # Feather v1 already respects the column selection
+    if reader.version < 3:
+        return table
+    # Feather v2 reads with sorted / deduplicated selection
+    elif sorted(set(columns)) == columns:
+        return table
+    else:
+        # follow exact order / selection of names
+        new_fields = [table.schema.field(c) for c in columns]
+        new_schema = schema(new_fields, metadata=table.schema.metadata)
+        new_columns = [table.column(c) for c in columns]
+        return Table.from_arrays(new_columns, schema=new_schema)

Review comment:
       Yes, I opened https://issues.apache.org/jira/browse/ARROW-8314 for something like this a while ago (I suppose it can basically be the above code moved into a helper function or method)




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

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