Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion python/pyarrow/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1331,10 +1331,13 @@ def __init__(self, schema):
def __arrow_c_schema__(self):
return self.schema.__arrow_c_schema__()

schema = pa.schema([pa.field("field_name", pa.int32())])
schema = pa.schema([pa.field("field_name", pa.int32())], metadata={"a": "b"})
assert schema.metadata == {b"a": b"b"}
wrapped_schema = Wrapper(schema)

assert pa.schema(wrapped_schema) == schema
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you additionally need to test is pa.schema(wrapped_schema, metadata=..), i.e. passing metadata to the pa.schema(..) constructor function when passing a schema object to it (the test as you edited it now will already pass, I think, and so not cover the regression)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks. I tried pushing just the test first hoping CI would run them but got lazy when it didn't. :)

assert pa.schema(wrapped_schema).metadata == {b"a": b"b"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this additional line, because assert pa.schema(wrapped_schema) == schema (the line above) in itself does not check the metadata (that gets ignored in basic equality testing)

assert pa.schema(wrapped_schema, metadata={"a": "c"}).metadata == {b"a": b"c"}


def test_field_import_c_schema_interface():
Expand Down
5 changes: 4 additions & 1 deletion python/pyarrow/types.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -5332,7 +5332,10 @@ def schema(fields, metadata=None):
if isinstance(fields, Mapping):
fields = fields.items()
elif hasattr(fields, "__arrow_c_schema__"):
return Schema._import_from_c_capsule(fields.__arrow_c_schema__())
result = Schema._import_from_c_capsule(fields.__arrow_c_schema__())
if metadata is not None:
result = result.with_metadata(metadata)
return result

for item in fields:
if isinstance(item, tuple):
Expand Down