Skip to content

[C++] During unit testing, the float array contains nan equality judgment #38624

@Light-City

Description

@Light-City

Describe the bug, including details regarding any error messages, version, and platform.

The default array options now have a nan comparison of false, but in a unit test situation we might expect nan=true.
for example:

  auto schema = ::arrow::schema({
      {field("a", float32())},
      {field("b", float64())},
  });

  std::vector<std::string> expected = {R"([{"a": 1,    "b": 5},
                                           {"a": 1,    "b": 3},
                                           {"a": 3,    "b": null},
                                           {"a": NaN,  "b": 5},
                                           {"a": NaN,  "b": NaN},
                                           {"a": NaN,   "b": null},
                                           {"a": null, "b": 5},
                                           {"a": null, "b": null}
                                          ])"};
  std::vector<std::string> actual = {R"([{"a": 1,    "b": 5},
                                         {"a": 1,    "b": 3},
                                         {"a": 3,    "b": null},
                                         {"a": NaN,  "b": 5},
                                         {"a": NaN,  "b": NaN},
                                         {"a": NaN,   "b": null},
                                         {"a": null, "b": 5},
                                         {"a": null, "b": null}
                                        ])"};
  ASSERT_TABLES_EQUAL(*TableFromJSON(schema, expected), *TableFromJSON(schema, actual));

Now the test will fail.

The reasons were found to be as follows:

  bool Equals(const Array& arr, const EqualOptions& = EqualOptions::Defaults()) const;
  bool Equals(const std::shared_ptr<Array>& arr,
              const EqualOptions& = EqualOptions::Defaults()) const;

So how can I modify the interface to support this function?

since ASSERT_TABLES_EQUAL will invoke ChunkedArray::ApproxEquals funciton.There is no way to pass options here

  return internal::ApplyBinaryChunked(
             *this, other,
             [&](const Array& left_piece, const Array& right_piece,
                 int64_t ARROW_ARG_UNUSED(position)) {
               if (!left_piece.ApproxEquals(right_piece, equal_options)) {
                 return Status::Invalid("Unequal piece");
               }
               return Status::OK();
             })
      .ok();

Component(s)

C++

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions