Skip to content

Commit 2ff410b

Browse files
committed
test(arrow): add is_null nan_is_null coverage for dictionary-encoded floats
1 parent 68c6ca8 commit 2ff410b

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

cpp/src/arrow/compute/kernels/scalar_validity_test.cc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,37 @@ TEST(TestValidityKernels, IsNullSetsZeroNullCount) {
152152
ASSERT_EQ(out.array()->null_count, 0);
153153
}
154154

155+
TEST(TestValidityKernels, IsNullDictionaryNanIsNull) {
156+
NullOptions default_options;
157+
NullOptions nan_is_null_options(/*nan_is_null=*/true);
158+
159+
auto dict_ty = dictionary(int32(), float64());
160+
auto arr = DictArrayFromJSON(dict_ty, "[0, 1, 2, null, 1]", "[1.5, NaN, -0.0]");
161+
162+
// Without nan_is_null, dictionary-encoded NaNs are not treated as null.
163+
CheckScalarUnary("is_null", arr,
164+
ArrayFromJSON(boolean(), "[false, false, false, true, false]"));
165+
CheckScalarUnary("is_null", arr,
166+
ArrayFromJSON(boolean(), "[false, false, false, true, false]"),
167+
&default_options);
168+
169+
// With nan_is_null, the dictionary entry backing index 1 is NaN, so every
170+
// slot referencing it is null; the pre-existing null index stays null.
171+
CheckScalarUnary("is_null", arr,
172+
ArrayFromJSON(boolean(), "[false, true, false, true, true]"),
173+
&nan_is_null_options);
174+
}
175+
176+
TEST(TestValidityKernels, IsNullDictionaryNanIsNullHalfFloat) {
177+
NullOptions nan_is_null_options(/*nan_is_null=*/true);
178+
179+
auto dict_ty = dictionary(int8(), float16());
180+
auto arr = DictArrayFromJSON(dict_ty, "[0, 1]", "[1.5, NaN]");
181+
182+
CheckScalarUnary("is_null", arr, ArrayFromJSON(boolean(), "[false, true]"),
183+
&nan_is_null_options);
184+
}
185+
155186
template <typename ArrowType>
156187
class TestFloatingPointValidityKernels : public TestValidityKernels<ArrowType> {
157188
public:

0 commit comments

Comments
 (0)