jorisvandenbossche commented on issue #43626: URL: https://github.com/apache/arrow/issues/43626#issuecomment-2286493827
The `Schema` object is very much tied to actual data (i.e. a RecordBatch or Table having a schema), and in that context pyarrow doesn't really support such notion of optional column (in an actual table, the columns are either present or are not). So I think adding that concept to just a Schema seems unlikely that we would want to do that. But, we can maybe look at ways to make your use case easier to do, as it is definitely a valid and logical thing to do. One idea could be to add an option to `Table.cast(schema)` to ignore columns in the target schema that are not present in the calling object (i.e. essentially take the calling table's set of columns as the ground truth for the columns of the result, and only use the passed `schema` to lookup the type for each column). Another idea could be to make it easier to select a subset of columns in the schema. For example, assume that a `Schema` had a `select` method to select a subset of the fields of the schema, one could do something like (in two steps): ```python arrow_table = df.to_arrow() arrow_table = arrow_table.cast(label_schema.select(arrow_table.schema.names) ``` -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
