You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@superset.apache.org by GitBox <gi...@apache.org> on 2018/04/30 15:43:55 UTC

[GitHub] betodealmeida opened a new pull request #4908: Replace NaN/Infinity with null

betodealmeida opened a new pull request #4908: Replace NaN/Infinity with null
URL: https://github.com/apache/incubator-superset/pull/4908
 
 
   The Python `json` module will happily encode `NaN` and `±Infinity`:
   
   ```python
   >>> import json
   >>> json.dumps([float('nan'), float('inf'), float('-inf')])
   '[NaN, Infinity, -Infinity]'
   ```
   
   The problem is that **this is not valid JSON**, and the browser will choke on the payload when running `JSON.parse` on it:
   
   ```
   > JSON.parse('[NaN, Infinity, -Infinity]');
   Uncaught SyntaxError: Unexpected token N in JSON at position 1
       at JSON.parse (<anonymous>)
       at <anonymous>:1:6
   ```
   
   To fix this, I used the `simplejson` module instead, since it provides an argument `ignore_nan` for converting these values to `null` as recommended by the JSON spec:
   
   ```python
   >>> import simplejson as json
   >>> json.dumps([float('nan'), float('inf'), float('-inf')], ignore_nan=True)
   '[null, null, null]'
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services