Changes between Version 84 and Version 85 of pyson


Ignore:
Timestamp:
01/21/25 11:57:46 (7 days ago)
Author:
wouter
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • pyson

    v84 v85  
    8181
    8282{{{#!td style="background: #fee"
    83 Using Decimal may cause rounding errors even before they get to Pyson, because json converts them to float. And floats can not represent all decimals accurately. For example, in python {{{str(0.24745759773026107) == '0.24745759773026108'}}}. Overall, a number string "N" in your json text will converted as {{{Decimal(str(float("N")))}}} . When in doubt, check for your number "N" that str(float(N))==N, if not you have a rounding issue.
    84 }}}
     83in python, the default json.loads() parses all floating point numbers to {{{float}}}. This may result in rounding errors. For example, in python {{{str(0.24745759773026107) == '0.24745759773026108'}}}. Pyson can only take these float numbers and proceed from there.
     84}}}
     85
     86{{{#!td style="background: #efe"
     87To avoid rounding errors on floating point numbers we recommend to use the parse_float option in json: {{{json.loads(yourstring, parse_float=lambda x:Decimal(x)}}}. This parses all floating point numbers as Decimal with unlimited precision. Of course the rest of your code must be able to handle this.
     88}}}
     89 
     90
     91
    8592You can use {{{ Union[X, NoneType] }}} where {{{NoneType=type(None)}}} or {{{Optional[X]}}}if the object can also be None. So for exmple you can use {{{reservationBid:Union[Bid,type(None)] = None}}}. Do not use the mypy.NoneType which is an entirely different class. We do not support {{{ Union[X,Y] }}} where both X and Y are not NoneType.
    8693