fix: coerce datetime conversion errors (#32683)

This commit is contained in:
Beto Dealmeida
2025-03-18 13:09:23 -04:00
committed by Michael S. Molina
parent 4a189945d8
commit 8ba265ca2b
3 changed files with 204 additions and 8 deletions

View File

@@ -1680,18 +1680,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,
)
else:
df[_col.col_label] = pd.to_datetime(
df[_col.col_label],
utc=False,
format=_col.timestamp_format,
errors="raise",
errors="coerce",
exact=False,
)
if _col.offset: