From 23daea38e2a14336f9c41709ca52cba4cb4abe40 Mon Sep 17 00:00:00 2001 From: Yimche Date: Fri, 18 Oct 2024 15:40:59 +1100 Subject: [PATCH 1/4] :test_tube: added #43985 test case --- python/pyarrow/table.pxi | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/python/pyarrow/table.pxi b/python/pyarrow/table.pxi index af241e4be07d9..c0ea0dfca110f 100644 --- a/python/pyarrow/table.pxi +++ b/python/pyarrow/table.pxi @@ -401,6 +401,15 @@ cdef class ChunkedArray(_PandasConvertible): return _pc().is_valid(self) def __eq__(self, other): + """ + >>> table = pa.Table.from_pydict({"foo": [float("nan")]}) + >>> table.equals(table) + True + >>> table_1 = pa.Table.from_pydict({"foo": [float("nan")]}) + >>> table_2 = pa.Table.from_pydict({"foo": [float("nan")]}) + >>> table_1.equals(table_2) + True + """ try: return self.equals(other) except TypeError: From ea70712557a8e517d786e7933a7dd8db77a1ed9b Mon Sep 17 00:00:00 2001 From: Yimche Date: Fri, 18 Oct 2024 20:15:19 +1100 Subject: [PATCH 2/4] :test_tube: added actual test (not doctest) --- python/pyarrow/tests/test_table.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/python/pyarrow/tests/test_table.py b/python/pyarrow/tests/test_table.py index 4c058ccecda5e..b13e87f40797c 100644 --- a/python/pyarrow/tests/test_table.py +++ b/python/pyarrow/tests/test_table.py @@ -2301,6 +2301,11 @@ def test_table_from_pydict(cls): with pytest.raises(TypeError): cls.from_pydict({'a': [1, 2, 3]}, schema={}) + # Dict with NaN floats + table_1 = pa.Table.from_pydict({"foo": [float("nan")]}) + table_2 = pa.Table.from_pydict({"foo": [float("nan")]}) + assert table_1 == table_2 + @pytest.mark.parametrize('data, klass', [ ((['', 'foo', 'bar'], [4.5, 5, None]), pa.array), From ab806973113e0df4d8befcd45ca601e0d80ef8c7 Mon Sep 17 00:00:00 2001 From: Yimche Date: Mon, 21 Oct 2024 19:11:41 +1100 Subject: [PATCH 3/4] :beers: removed doctest, removed potential source of buggy behaviour --- cpp/src/arrow/table.cc | 3 --- python/pyarrow/table.pxi | 9 --------- 2 files changed, 12 deletions(-) diff --git a/cpp/src/arrow/table.cc b/cpp/src/arrow/table.cc index 5dc5e4c1a9a8c..44eab9902d89c 100644 --- a/cpp/src/arrow/table.cc +++ b/cpp/src/arrow/table.cc @@ -534,9 +534,6 @@ Result> PromoteTableToSchema(const std::shared_ptr } bool Table::Equals(const Table& other, bool check_metadata) const { - if (this == &other) { - return true; - } if (!schema_->Equals(*other.schema(), check_metadata)) { return false; } diff --git a/python/pyarrow/table.pxi b/python/pyarrow/table.pxi index c0ea0dfca110f..af241e4be07d9 100644 --- a/python/pyarrow/table.pxi +++ b/python/pyarrow/table.pxi @@ -401,15 +401,6 @@ cdef class ChunkedArray(_PandasConvertible): return _pc().is_valid(self) def __eq__(self, other): - """ - >>> table = pa.Table.from_pydict({"foo": [float("nan")]}) - >>> table.equals(table) - True - >>> table_1 = pa.Table.from_pydict({"foo": [float("nan")]}) - >>> table_2 = pa.Table.from_pydict({"foo": [float("nan")]}) - >>> table_1.equals(table_2) - True - """ try: return self.equals(other) except TypeError: From 09f418e7776b3adf3577b7369339ef4458d55216 Mon Sep 17 00:00:00 2001 From: Yimche Date: Mon, 21 Oct 2024 22:05:23 +1100 Subject: [PATCH 4/4] :white_check_mark: potentially fixed test --- python/pyarrow/tests/test_table.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/python/pyarrow/tests/test_table.py b/python/pyarrow/tests/test_table.py index b13e87f40797c..e8242fe116ec1 100644 --- a/python/pyarrow/tests/test_table.py +++ b/python/pyarrow/tests/test_table.py @@ -2301,10 +2301,9 @@ def test_table_from_pydict(cls): with pytest.raises(TypeError): cls.from_pydict({'a': [1, 2, 3]}, schema={}) - # Dict with NaN floats - table_1 = pa.Table.from_pydict({"foo": [float("nan")]}) - table_2 = pa.Table.from_pydict({"foo": [float("nan")]}) - assert table_1 == table_2 + # With dicts containing NaNs + table = cls.from_pydict({"foo": [float("nan")]}) + assert table != table @pytest.mark.parametrize('data, klass', [