From 994c73b019536b31248f1438278c622d2f0a0f94 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 13 Jul 2023 15:28:58 +0200 Subject: [PATCH] GH-36659: [Python] Fix pyarrow.dataset.Partitioning.__eq__ when comparing with other type (#36661) ### Rationale for this change Ensure that `part == other` doesn't crash with `other` is not a Partitioning instance Small follow-up on https://github.com/apache/arrow/pull/36462 * Closes: #36659 Authored-by: Joris Van den Bossche Signed-off-by: Joris Van den Bossche --- python/pyarrow/_dataset.pyx | 5 ++--- python/pyarrow/tests/test_dataset.py | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python/pyarrow/_dataset.pyx b/python/pyarrow/_dataset.pyx index c5f0a663a814c..925565804f63e 100644 --- a/python/pyarrow/_dataset.pyx +++ b/python/pyarrow/_dataset.pyx @@ -2348,10 +2348,9 @@ cdef class Partitioning(_Weakrefable): return self.wrapped def __eq__(self, other): - try: + if isinstance(other, Partitioning): return self.partitioning.Equals(deref((other).unwrap())) - except TypeError: - return False + return False def parse(self, path): cdef CResult[CExpression] result diff --git a/python/pyarrow/tests/test_dataset.py b/python/pyarrow/tests/test_dataset.py index 2f9b6a0922351..a70cf2fbc72af 100644 --- a/python/pyarrow/tests/test_dataset.py +++ b/python/pyarrow/tests/test_dataset.py @@ -589,6 +589,7 @@ def test_partitioning(): partitioning = klass(schema) assert isinstance(partitioning, ds.Partitioning) assert partitioning == klass(schema) + assert partitioning != "other object" schema = pa.schema([ pa.field('group', pa.int64()),