This is an automated email from the ASF dual-hosted git repository.
CurtHagenlocher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git
The following commit(s) were added to refs/heads/main by this push:
new ac1aebe5fc test(csharp): test NaN and infinity in variant values
(#4922)
ac1aebe5fc is described below
commit ac1aebe5fcdbebb4c952bc5ce408e45c783c0a67
Author: Curt Hagenlocher <[email protected]>
AuthorDate: Sun Oct 18 11:09:08 2026 -0700
test(csharp): test NaN and infinity in variant values (#4922)
## What's changed
Adds the variant test promised in #4919. Variants converted to JSON use
the same writer as structs, so they already get the behavior from #4921:
NaN and ±Infinity are written as the strings `"NaN"`, `"Infinity"` and
`"-Infinity"`. This test pins that down.
`VariantNonFiniteValues` reads a variant column with a non-finite double
and float inside an object and an array, and a top-level NaN:
- With `StructBehavior.JsonString`, it checks the exact JSON.
- With `StructBehavior.Strict`, it checks that the .NET values keep the
actual NaN and infinity values.
With the #4921 change reverted, the JSON case fails with the original
`ArgumentException`.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../Client/ExtensionTypeTests.cs | 40 ++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/csharp/test/Apache.Arrow.Adbc.Tests/Client/ExtensionTypeTests.cs
b/csharp/test/Apache.Arrow.Adbc.Tests/Client/ExtensionTypeTests.cs
index f3603d0f86..062809d6a2 100644
--- a/csharp/test/Apache.Arrow.Adbc.Tests/Client/ExtensionTypeTests.cs
+++ b/csharp/test/Apache.Arrow.Adbc.Tests/Client/ExtensionTypeTests.cs
@@ -260,6 +260,46 @@ namespace Apache.Arrow.Adbc.Tests.Client
Assert.Equal(DBNull.Value, reader.GetValue(0));
}
+ /// <summary>
+ /// JSON numbers can't represent NaN or infinity, so they're written
as strings,
+ /// the same as in struct JSON. The .NET values keep the actual
numbers.
+ /// </summary>
+ [Theory]
+ [InlineData(StructBehavior.JsonString)]
+ [InlineData(StructBehavior.Strict)]
+ public void VariantNonFiniteValues(StructBehavior structBehavior)
+ {
+ VariantValue obj = VariantValue.FromObject(new Dictionary<string,
VariantValue>
+ {
+ { "d", VariantValue.FromDouble(double.NaN) },
+ { "f", VariantValue.FromFloat(float.PositiveInfinity) },
+ { "values",
VariantValue.FromArray(VariantValue.FromDouble(double.NegativeInfinity)) },
+ });
+ VariantArray array = new VariantArray.Builder()
+ .Append(obj)
+ .Append(VariantValue.FromDouble(double.NaN))
+ .Build();
+
+ using AdbcDataReader reader = GetReader(VariantField(array,
fromStorage: true), array.Storage, structBehavior);
+
+ Assert.True(reader.Read());
+ if (structBehavior == StructBehavior.JsonString)
+ {
+
Assert.Equal("{\"d\":\"NaN\",\"f\":\"Infinity\",\"values\":[\"-Infinity\"]}",
reader.GetString(0));
+ Assert.True(reader.Read());
+ Assert.Equal("\"NaN\"", reader.GetString(0));
+ }
+ else
+ {
+ Dictionary<string, object?> value =
Assert.IsType<Dictionary<string, object?>>(reader.GetValue(0));
+ Assert.True(double.IsNaN(Assert.IsType<double>(value["d"])));
+ Assert.Equal(float.PositiveInfinity, value["f"]);
+ Assert.Equal(new List<object?> { double.NegativeInfinity },
value["values"]);
+ Assert.True(reader.Read());
+
Assert.True(double.IsNaN(Assert.IsType<double>(reader.GetValue(0))));
+ }
+ }
+
[Fact]
public void VariantAsObject()
{