Skip to content

Commit

Permalink
Add Python tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lidavidm committed Jun 30, 2024
1 parent 1456a3b commit 978a624
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cpp/src/arrow/compute/kernels/scalar_cast_numeric.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "arrow/compute/kernels/scalar_cast_internal.h"
#include "arrow/compute/kernels/util_internal.h"
#include "arrow/scalar.h"
#include "arrow/type_fwd.h"
#include "arrow/util/bit_block_counter.h"
#include "arrow/util/float16.h"
#include "arrow/util/int_util.h"
Expand Down Expand Up @@ -865,6 +866,25 @@ std::shared_ptr<CastFunction> GetCastToHalfFloat() {
return func;
}

struct NullExtensionTypeMatcher : public TypeMatcher {
~NullExtensionTypeMatcher() override = default;

bool Matches(const DataType& type) const override {
return type.id() == Type::EXTENSION &&
static_cast<const ExtensionType&>(type).storage_id() == Type::NA;
}

std::string ToString() const override { return "extension<storage_type: null>"; }

bool Equals(const TypeMatcher& other) const override {
if (this == &other) {
return true;
}
auto casted = dynamic_cast<const NullExtensionTypeMatcher*>(&other);
return casted != nullptr;
}
};

} // namespace

std::vector<std::shared_ptr<CastFunction>> GetNumericCasts() {
Expand All @@ -875,6 +895,10 @@ std::vector<std::shared_ptr<CastFunction>> GetNumericCasts() {
auto cast_null = std::make_shared<CastFunction>("cast_null", Type::NA);
DCHECK_OK(cast_null->AddKernel(Type::DICTIONARY, {InputType(Type::DICTIONARY)}, null(),
OutputAllNull));
// Explicitly allow casting extension type with null backing array to null
DCHECK_OK(cast_null->AddKernel(
Type::EXTENSION, {InputType(std::make_shared<NullExtensionTypeMatcher>())}, null(),
OutputAllNull));
functions.push_back(cast_null);

functions.push_back(GetCastToInteger<Int8Type>("cast_int8"));
Expand Down

0 comments on commit 978a624

Please sign in to comment.