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

Function dict_replace_nans

tests/test_inputs.py:107–129  ·  view source on GitHub ↗

Replace float("nan") in a dictionary with the string "NaN" Parameters ---------- input_dict : Dict[Any, Any] Dictionary to update Returns ------- Dict[Any, Any] Updated dictionary

(input_dict: Dict[Any, Any])

Source from the content-addressed store, hash-verified

105
106
107def dict_replace_nans(input_dict: Dict[Any, Any]) -> Dict[Any, Any]:
108 """Replace float("nan") in a dictionary with the string "NaN"
109
110 Parameters
111 ----------
112 input_dict : Dict[Any, Any]
113 Dictionary to update
114
115 Returns
116 -------
117 Dict[Any, Any]
118 Updated dictionary
119 """
120 result = {}
121 for key, value in input_dict.items():
122 if isinstance(value, dict):
123 value = dict_replace_nans(value)
124 elif isinstance(value, list):
125 value = list_replace_nans(value)
126 elif isinstance(value, float) and math.isnan(value):
127 value = betterproto.NAN
128 result[key] = value
129 return result
130
131
132@pytest.fixture

Callers 3

list_replace_nansFunction · 0.85
test_message_jsonFunction · 0.85

Calls 1

list_replace_nansFunction · 0.85

Tested by

no test coverage detected