bito-code-review[bot] commented on code in PR #44695: URL: https://github.com/apache/superset/pull/44695#discussion_r4113982283
########## superset/db_engine_specs/gsheets.py: ########## @@ -64,6 +66,43 @@ ma_plugin = MarshmallowPlugin() +def _to_python_value(value: Any) -> Any: + """ + Convert numpy and pandas scalars into their Python equivalents. + """ + if isinstance(value, np.datetime64): + # ``.item()`` returns an int for nanosecond precision; go through pandas. + value = pd.Timestamp(value) + elif isinstance(value, np.generic): + # e.g. ``np.timedelta64.item()`` returns a ``timedelta``. + value = value.item() Review Comment: <div> <div id="suggestion"> <div id="issue"><b>ns timedelta64 becomes int</b></div> <div id="fix"> `_to_python_value` routes `np.datetime64` through pandas because `.item()` loses nanosecond precision (line 74), but `np.timedelta64` falls into the generic `.item()` branch: for ns precision (pandas' default timedelta unit) it returns a bare int, so `to_json_value` emits 5 instead of a duration string. Verified: `np.timedelta64(5,'ns').item()` → 5 on numpy 2.4.6. Route timedelta64 through `pd.Timedelta` like datetime64. </div> </div> <small><i>Code Review Run #99088b</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
