Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NaN, Infinity, and -Infinity for numbers #603

Closed
ralfhandl opened this issue Mar 18, 2016 · 9 comments
Closed

NaN, Infinity, and -Infinity for numbers #603

ralfhandl opened this issue Mar 18, 2016 · 9 comments

Comments

@ralfhandl
Copy link
Contributor

Somehow the authors of the JSON specification forgot the special number values NaN, Infinity, and -Infinity. As a workaround we represent these double values as JSON string values, and declare the corresponding properties as
"type": ["number","string"],
"format":"double"

Is there a best practice to deal with this, and could that become part of the OpenAPI specification or an accompanying document?

@ePaul
Copy link
Contributor

ePaul commented Mar 18, 2016

Can you tell us some more about the use cases where you actually need those values? In my uses I either needed (relatively small) integers or money values, and never a NaN or an infinity would make any sense. Of course I can guess that you have uses for them, but I would like to know some examples.

@ralfhandl
Copy link
Contributor Author

These values can occur when requesting computed results, e.g. during Data Aggregation. Failing a request just because some properties have "funny" values wouldn't be acceptable, and mapping these special values to null would also mean loss of information.

@DavidBiesack
Copy link

In statistics and data analysis an IoT, missing values are quite common. For example, in a data vector contains values for each of N sources, a NaN indicates no data from that source i, while there may be data from other items in the vector. (This is different from a named value in a JSON object not being present.)

@ralfhandl
Copy link
Contributor Author

@DavidBiesack would it be sufficient for you to represent "unknown", "NaN", "-Infinity", and "Infinity" all as null, or would it make sense to differentiate between these four special values?

@DavidBiesack
Copy link

NaN, -Infinitity and Infinity all have different meaning, so we should not coalesce them into one canonical value.

SAS analytics and data representations actually support 28 different missing values which can encode different reasons why a value is missing. (See MISSING! - Understanding and Making the Most of Missing Data for an explanation.) A period . corresponds to NaN but we also support distinct ._ and .A through .Z values, and SAS data analysis compensates for these when doing summary statistics such as min, max, mean, standard deviation, covariance, etc.

Note: I'm not asking that we account specifically for SAS-specific representations in OAS. I'm just voicing that it is important (to us) to allow for string representations for numerics, whether as in the OP or in some other way.

@whitlockjc
Copy link
Member

Wouldn't this be more of a JSON Schema addition? I realize that OAI specifications are not fully JSON Schema compliant but when it comes to formats and types, they pretty much are. That being said, most JSON Schema validators allow custom formats and you could easily achieve this using a custom format.

I'm not -1 on this but having a little context never hurt.

@ralfhandl
Copy link
Contributor Author

@whitlockjc From a JSON Schema perspective double and float are Swagger-specific "custom" formats, so the OpenAPI specification seems to be the right place to potentially extend the definition and validation rules of these "custom" formats.

This extension could be as weak as "double and float are IEEE 754 binary64 resp. binary32 floating point numbers which MAY include non-numeric special values represented as JSON strings, e.g. NaN, in which case the type array MUST include string".

@webron
Copy link
Member

webron commented Jul 21, 2016

Tackling PR: #741

@ralfhandl
Copy link
Contributor Author

Format decimal128 now states

String representation allows expressing the special values NaN, -INF, and INF that cannot be expressed as JSON numbers.

Another alternative is defining and referencing reuse types such as https://github.com/oasis-tcs/odata-openapi/blob/028cf1aeadd054077b23141c500e05ec2c2537fa/examples/odata-definitions.json#L48-L62, so no need to extend the core OpenAPI specification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants