MCPcopy Index your code
hub / github.com/danielgtaylor/python-betterproto / list_replace_nans

Function list_replace_nans

tests/test_inputs.py:83–104  ·  view source on GitHub ↗

Replace float("nan") in a list with the string "NaN" Parameters ---------- items : List List to update Returns ------- List[Any] Updated list

(items: List)

Source from the content-addressed store, hash-verified

81
82
83def 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
107def dict_replace_nans(input_dict: Dict[Any, Any]) -> Dict[Any, Any]:

Callers 1

dict_replace_nansFunction · 0.85

Calls 1

dict_replace_nansFunction · 0.85

Tested by

no test coverage detected