Skip to content

Commit dca8c7e

Browse files
committed
fix(test): return Series (not ndarray) from _parse_expected_datetime_column
pandas 2.x's Series.dt.to_pydatetime() returns an ndarray, tripping mypy's return-type check against the pd.Series annotation and (without dtype='object') letting pandas coerce the datetime.datetime objects back to pd.Timestamp when Series wraps them — which reintroduces the nanosecond overflow this helper exists to avoid. Wrap with dtype='object' and preserve the source index. Signed-off-by: mokashang <shangmengjiajiajia@gmail.com>
1 parent 3e8ea6c commit dca8c7e

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎sqlmesh/core/test/definition.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,11 @@ def _parse_expected_datetime_column(series: pd.Series, target_type: type) -> pd.
10321032
return parsed.dt.date
10331033
if target_type is datetime.time:
10341034
return parsed.dt.time
1035-
return parsed.dt.to_pydatetime()
1035+
# `Series.dt.to_pydatetime()` returns an `ndarray` in pandas 2.x. Wrap it in a
1036+
# Series with ``dtype=object`` so pandas does not coerce the values back to
1037+
# ``pd.Timestamp`` (which would reintroduce the nanosecond overflow this
1038+
# function exists to avoid).
1039+
return pd.Series(parsed.dt.to_pydatetime(), index=parsed.index, dtype="object")
10361040

10371041

10381042
def _normalize_df_value(value: t.Any) -> t.Any:

0 commit comments

Comments
 (0)