Replace float("nan") in a list with the string "NaN" Parameters ---------- items : List List to update Returns ------- List[Any] Updated list
(items: List)
| 81 | |
| 82 | |
| 83 | def list_replace_nans(items: List) -> List[Any]: |
| 84 | """Replace float("nan") in a list with the string "NaN" |
| 85 | |
| 86 | Parameters |
| 87 | ---------- |
| 88 | items : List |
| 89 | List to update |
| 90 | |
| 91 | Returns |
| 92 | ------- |
| 93 | List[Any] |
| 94 | Updated list |
| 95 | """ |
| 96 | result = [] |
| 97 | for item in items: |
| 98 | if isinstance(item, list): |
| 99 | result.append(list_replace_nans(item)) |
| 100 | elif isinstance(item, dict): |
| 101 | result.append(dict_replace_nans(item)) |
| 102 | elif isinstance(item, float) and math.isnan(item): |
| 103 | result.append(betterproto.NAN) |
| 104 | return result |
| 105 | |
| 106 | |
| 107 | def dict_replace_nans(input_dict: Dict[Any, Any]) -> Dict[Any, Any]: |
no test coverage detected