diff --git a/bigframes/core/compile/polars/compiler.py b/bigframes/core/compile/polars/compiler.py index 20fdeb5be3..1f0ca592e5 100644 --- a/bigframes/core/compile/polars/compiler.py +++ b/bigframes/core/compile/polars/compiler.py @@ -152,6 +152,11 @@ def _( value = None if expression.dtype is None: return pl.lit(None) + + # Polars lit does not handle pandas timedelta well at v1.36 + if isinstance(value, pd.Timedelta): + value = value.to_pytimedelta() + return pl.lit(value, _bigframes_dtype_to_polars_dtype(expression.dtype)) @compile_expression.register diff --git a/tests/unit/test_series_polars.py b/tests/unit/test_series_polars.py index e98db92b93..cffeedea35 100644 --- a/tests/unit/test_series_polars.py +++ b/tests/unit/test_series_polars.py @@ -5109,3 +5109,18 @@ def test_series_item_with_empty(session): with pytest.raises(ValueError, match=re.escape(expected_message)): bf_s_empty.item() + + +def test_series_dt_total_seconds(scalars_df_index, scalars_pandas_df_index): + bf_result = scalars_df_index["duration_col"].dt.total_seconds().to_pandas() + + pd_result = scalars_pandas_df_index["duration_col"].dt.total_seconds() + + # Index will be object type in pandas, string type in bigframes, but same values + pd.testing.assert_series_equal( + bf_result, + pd_result, + check_index_type=False, + # bigframes uses Float64, newer pandas may use double[pyarrow] + check_dtype=False, + )