xxgreg opened a new issue, #40563:
URL: https://github.com/apache/arrow/issues/40563

   ### Describe the bug, including details regarding any error messages, 
version, and platform.
   
   `array.Float64.MarshallJSON()` returns the following error for the example 
code below:
   
   ```
   json: unsupported value: NaN
   ```
   
   ```go
   package main
   
   import (
        "fmt"
        "math"
   
        "github.com/apache/arrow/go/v16/arrow/array"
        "github.com/apache/arrow/go/v16/arrow/memory"
   )
   
   func main() {
   
        builder := array.NewFloat64Builder(memory.DefaultAllocator)
        builder.Append(math.NaN())
   
        array_ := builder.NewArray()
   
        bs, err := array_.MarshalJSON()
        if err != nil {
                fmt.Println("error:", err)
        }
   
        fmt.Println(string(bs))
   }
   ```
   
   Consider updating the marshalling code for Float64 and other floating point 
array types with something like:
   
   ```
   func (a *array.Float64) MarshalJSON() ([]byte, error) {
        vals := make([]any, a.Len())
        for i := 0; i < a.Len(); i++ {
                if !a.IsValid(i) {
                        vals[i] = nil
                        continue
                }
   
                f := a.Value(i)
                switch {
                case math.IsNaN(f):
                        vals[i] = "NaN"
                case math.IsInf(f, 1):
                        vals[i] = "+Inf"
                case math.IsInf(f, -1):
                        vals[i] = "-Inf"
                default:
                        vals[i] = f
                }
        }
   
        return json.Marshal(vals)
   }
   ```
   
   ### Component(s)
   
   Go


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to