Skip to content

NaN value in JSON output #1509

Closed
Closed

Description

@victorskl

Description of bug

There seem to be NaN as value when choose to dump in JSON format i.e. --data-format json. This is of course invalid as JSON value. Please see attached screenshot. And error condition for use case such as when trying to insert MultiQC data straight into MySQL table as JSON data type. Report itself render no issue. I can also report that this happen on SnpEff toolbox / plot data.

I also note that, in Python json.dumps allowed NaN by default. For better, it should allow_nan=False to conform with JSON format, I suppose.

We have post-processing step for MultiQC data ingestion. Do you recommend setting NaN to null if we handle during processing?

Our MultiQC version is 1.10.dev0.

Thanks

image

File that triggers the error

No response

MultiQC Error log

No response

Activity

  1. cmatKhan commented on Sep 5, 2021

    @cmatKhan
    library(TidyMultiqc)
    library(here)
    
    df = load_multiqc(here("data/multiqc_output.json"))
    Error in parse_con(txt, bigint_as_char) : 
      lexical error: invalid char in json text.
                      "mapped_failed_pct": NaN,                 "paired in
                         (right here) ------^

    What did you do? replace NaN with some known nonsense number in the JSON?

  2. brainstorm commented on Sep 8, 2021

    @brainstorm
    Contributor

    I wonder if we could somehow lure @pcingola (main dev of snpEff AFAICT) to drop the use of NaN in snpEff and instead use a very large number to stay within the designated schema type:

    https://github.com/pcingola/SnpEff/search?p=1&q=NaN

    That'd solve the issue(s) we are seeing here with Python's JSON serialization where the data type for several fields flips from Double to something that JSON parsers do not accept as Double (because NaN isn't Double anymore).

    Please note that turning NaN into a string is not a good solution either for the aforementioned reasons... also two different NaNs are not even equal between each other, which is semantically even worse ;)

    /cc @reisingerf @ohofmann @andrewpatto

  3. ewels commented on Jan 27, 2022

    @ewels
    Member

    Do you recommend setting NaN to null if we handle during processing?

    I guess that this is the best solution.. The Stack Overflow post you linked to has a comment saying that the simplejson package can do this conversion, instead of just falling over with a ValueError.

    If it's only a limited number of modules doing this (just SnpEff?) then the easiest solution would probably be to get the module code to replace NaN with None, which will then be serialised to null in the JSON.

  4. multimeric commented on Jun 7, 2022

    @multimeric

    It's not just SnpEff. I'm getting error reports (multimeric/TidyMultiqc#9 and multimeric/TidyMultiqc#6), which suggest that the following fields are often NaN:

    • mapped_failed_pct
    • properly paired_failed_pct
    • properly paired_passed_pct
    • singletons_failed_pct
    • singletons_passed_pct

    I think these are all from the samtools module.

    I'd like to +1 the suggestion of changing these to null. I think there's always going to be a risk that modules output NaN (intentionally or otherwise), but we never want invalid JSON to be output.

  5. ewels commented on Jun 7, 2022

    @ewels
    Member

    Ok, thanks @multimeric. This is best done within the general function that saves JSON outputs then I think. Then it will apply for all modules.

  6. loukesio commented on Oct 11, 2022

    @loukesio

    Hello all,
    Have you found a solution in the meantime, running the

    library(TidyMultiqc)
    library(here)
    
    df = load_multiqc(here("data/multiqc_output.json"))
    

    i am still getting the same error as @ewels

  7. multimeric commented on Oct 11, 2022

    @multimeric

    If your issue is with TidyMultiqc, refer to the issue here: multimeric/TidyMultiqc#9. I have one proposed solution, but it hasn't been confirmed to work.

  8. edmundmiller commented on Nov 21, 2023

    @edmundmiller
    Contributor
  9. vladsavelyev commented on Mar 8, 2024

    @vladsavelyev
    Contributor

    Too bad the standard JSON module doesn't take a custom handler for that :( I didn't want to add simplejson, so just went with a hack: #2432

  10. ewels commented on Mar 14, 2024

    @ewels
    Member

    Thank you everyone for your patience! Hopefully this is now finally fixed..

    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions