@@ -291,8 +291,10 @@ def _check_update_trace_data(
291291 s_res : pd .Series = downsampler .aggregate (
292292 hf_series , hf_trace_data ["max_n_samples" ]
293293 )
294- trace ["x" ] = s_res .index
295- trace ["y" ] = s_res .values
294+ # Also parse the data types to an orjson compatible format
295+ # Note this can be removed once orjson supports f16
296+ trace ["x" ] = self ._parse_dtype_orjson (s_res .index )
297+ trace ["y" ] = self ._parse_dtype_orjson (s_res .values )
296298 # todo -> first draft & not MP safe
297299
298300 agg_prefix , agg_suffix = ' <i style="color:#fc9944">~' , "</i>"
@@ -700,10 +702,6 @@ def _parse_get_trace_props(
700702 except ValueError :
701703 hf_y = hf_y .astype ("str" )
702704
703- # orjson encoding doesn't like to encode with uint8 & uint16 dtype
704- if str (hf_y .dtype ) in ["uint8" , "uint16" ]:
705- hf_y = hf_y .astype ("uint32" )
706-
707705 assert len (hf_x ) == len (hf_y ), "x and y have different length!"
708706 else :
709707 self ._print (f"trace { trace ['type' ]} is not a high-frequency trace" )
@@ -1283,6 +1281,17 @@ def construct_update_data(
12831281 layout_traces_list .append (trace_reduced )
12841282 return layout_traces_list
12851283
1284+ @staticmethod
1285+ def _parse_dtype_orjson (series : np .ndarray ) -> np .ndarray :
1286+ """Verify the orjson compatibility of the series and convert it if needed."""
1287+ # NOTE:
1288+ # * float16 and float128 aren't supported with latest orjson versions (3.8.1)
1289+ # * this method assumes that the it will not get a float128 series
1290+ # -> this method can be removed if orjson supports float16
1291+ if series .dtype in [np .float16 ]:
1292+ return series .astype (np .float32 )
1293+ return series
1294+
12861295 @staticmethod
12871296 def _re_matches (regex : re .Pattern , strings : Iterable [str ]) -> List [str ]:
12881297 """Returns all the items in ``strings`` which regex.match(es) ``regex``."""
0 commit comments