(value, local_type_id: int)
| 326 | |
| 327 | |
| 328 | def _numeric_value(value, local_type_id: int): |
| 329 | if type(value) is str: |
| 330 | if local_type_id in _FLOAT_TYPE_IDS and value.startswith("-"): |
| 331 | decimal_value = _decimal_from_text(value) |
| 332 | if decimal_value.is_zero(): |
| 333 | return _to_float_domain(-0.0, local_type_id) |
| 334 | value = _decimal_from_text(value) |
| 335 | elif type(value) is bool: |
| 336 | value = 1 if value else 0 |
| 337 | if local_type_id in _INT_RANGES_BY_TYPE_ID: |
| 338 | return _int_value(value, local_type_id) |
| 339 | if local_type_id in _FLOAT_TYPE_IDS: |
| 340 | return _float_value(value, local_type_id) |
| 341 | if local_type_id == TypeId.DECIMAL: |
| 342 | if type(value) is int: |
| 343 | return decimal.Decimal(value) |
| 344 | if type(value) is float: |
| 345 | if not math.isfinite(value): |
| 346 | raise ValueError("non-finite float cannot convert to decimal") |
| 347 | return _decimal_from_float_value(value) |
| 348 | if isinstance(value, decimal.Decimal): |
| 349 | return _canonical_decimal(value) |
| 350 | raise ValueError(f"type id {local_type_id} is not a numeric scalar") |
| 351 | |
| 352 | |
| 353 | def compatible_scalar_convert(value, remote_type_id: int, local_type_id: int): |
no test coverage detected