bito-code-review[bot] commented on code in PR #44695:
URL: https://github.com/apache/superset/pull/44695#discussion_r4129931310
##########
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:
<!-- Bito Reply -->
The suggestion provided by the reviewer is correct and addresses a real
issue where `np.timedelta64` loses nanosecond precision when converted via
`.item()`, resulting in incorrect JSON serialization. Applying this suggestion
improves the code by ensuring consistent handling of timedelta values, similar
to how `np.datetime64` is handled. You should proceed with this change as it
ensures data integrity for duration values.
**superset/db_engine_specs/gsheets.py**
```
elif isinstance(value, np.generic):
# e.g. ``np.timedelta64.item()`` returns a ``timedelta``.
value = value.item()
```
--
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]