From dc2dbb1465f46aa6a2a73ca3e591c5764f3883da Mon Sep 17 00:00:00 2001 From: Mola-maker <229602071+Mola-maker@users.noreply.github.com> Date: Tue, 13 Oct 2026 09:50:48 +0800 Subject: [PATCH] GH-53500: [Python][Parquet] Reject None in metadata equality --- python/pyarrow/_parquet.pyx | 10 ++++---- python/pyarrow/tests/parquet/test_metadata.py | 25 +++++++++++++++++-- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/python/pyarrow/_parquet.pyx b/python/pyarrow/_parquet.pyx index 2621c3bd6d61..a9b876d58286 100644 --- a/python/pyarrow/_parquet.pyx +++ b/python/pyarrow/_parquet.pyx @@ -108,7 +108,7 @@ cdef class Statistics(_Weakrefable): except TypeError: return NotImplemented - def equals(self, Statistics other): + def equals(self, Statistics other not None): """ Return whether the two column statistics objects are equal. @@ -521,7 +521,7 @@ cdef class ColumnChunkMetaData(_Weakrefable): except TypeError: return NotImplemented - def equals(self, ColumnChunkMetaData other): + def equals(self, ColumnChunkMetaData other not None): """ Return whether the two column chunk metadata objects are equal. @@ -919,7 +919,7 @@ cdef class RowGroupMetaData(_Weakrefable): except TypeError: return NotImplemented - def equals(self, RowGroupMetaData other): + def equals(self, RowGroupMetaData other not None): """ Return whether the two row group metadata objects are equal. @@ -1295,7 +1295,7 @@ cdef class ParquetSchema(_Weakrefable): except TypeError: return NotImplemented - def equals(self, ParquetSchema other): + def equals(self, ParquetSchema other not None): """ Return whether the two schemas are equal. @@ -1350,7 +1350,7 @@ cdef class ColumnSchema(_Weakrefable): def __reduce__(self): return ColumnSchema, (self.parent, self.index) - def equals(self, ColumnSchema other): + def equals(self, ColumnSchema other not None): """ Return whether the two column schemas are equal. diff --git a/python/pyarrow/tests/parquet/test_metadata.py b/python/pyarrow/tests/parquet/test_metadata.py index 9eee70b125e5..f36257714b96 100644 --- a/python/pyarrow/tests/parquet/test_metadata.py +++ b/python/pyarrow/tests/parquet/test_metadata.py @@ -19,6 +19,7 @@ import decimal from collections import OrderedDict import io +import operator try: import numpy as np @@ -712,16 +713,36 @@ def test_metadata_schema_filesystem(tempdir): fname, filesystem=LocalFileSystem()).equals(schema) -def test_metadata_equals(): +@pytest.mark.parametrize("kind", [ + "file", "row_group", "column_chunk", "statistics", "schema", "column_schema" +]) +def test_metadata_equals(kind): table = pa.table({"a": [1, 2, 3]}) with pa.BufferOutputStream() as out: pq.write_table(table, out) buf = out.getvalue() original_metadata = pq.read_metadata(pa.BufferReader(buf)) + row_group = original_metadata.row_group(0) + column_chunk = row_group.column(0) + metadata = { + "file": original_metadata, + "row_group": row_group, + "column_chunk": column_chunk, + "statistics": column_chunk.statistics, + "schema": original_metadata.schema, + "column_schema": original_metadata.schema.column(0), + }[kind] + + assert metadata.equals(metadata) + assert operator.eq(metadata, metadata) + assert not operator.eq(metadata, None) + assert not operator.eq(None, metadata) + assert operator.ne(metadata, None) + assert operator.ne(None, metadata) match = "Argument 'other' has incorrect type" with pytest.raises(TypeError, match=match): - original_metadata.equals(None) + metadata.equals(None) @pytest.mark.parametrize("t1,t2,expected_error", (