korbit-ai[bot] commented on code in PR #32683:
URL: https://github.com/apache/superset/pull/32683#discussion_r1996442323
##########
superset/utils/core.py:
##########
@@ -1682,18 +1682,26 @@ def normalize_dttm_col(
utc=False,
unit=unit,
origin="unix",
- errors="raise",
+ errors="coerce",
exact=False,
)
else:
# Column has already been formatted as a timestamp.
- df[_col.col_label] = dttm_series.apply(pd.Timestamp)
+ try:
+ df[_col.col_label] = dttm_series.apply(
+ lambda x: pd.Timestamp(x) if pd.notna(x) else pd.NaT
+ )
+ except ValueError:
+ logger.warning(
+ "Unable to convert column %s to datetime, ignoring",
+ _col.col_label,
+ )
Review Comment:
### Silent datetime conversion error <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
The error handling silently ignores ValueError without preserving the
original data or providing recovery options.
###### Why this matters
If datetime conversion fails, the column data is left in an undefined state
which could cause downstream issues. The warning message also lacks details
about the actual error.
###### Suggested change ∙ *Feature Preview*
Add error details and preserve original data:
```python
try:
df[_col.col_label] = dttm_series.apply(
lambda x: pd.Timestamp(x) if pd.notna(x) else pd.NaT
)
except ValueError as ex:
logger.warning(
"Unable to convert column %s to datetime (Error: %s). Preserving
original data.",
_col.col_label,
str(ex)
)
```
</details>
<sub>
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/e7a43be7-86bb-407d-a7b1-eb264bab97de?suggestedFixEnabled=true)
💬 Looking for more details? Reply to this comment to chat with Korbit.
</sub>
<!--- korbi internal id:e68fb890-4299-411b-a26e-7e43b6f8db29 -->
--
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]