Skip to content

Commit 61bca25

Browse files
fix: Fix pd.timedelta handling in polars comipler with polars 1.36
1 parent d993831 commit 61bca25

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

bigframes/core/compile/polars/compiler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ def _(
152152
value = None
153153
if expression.dtype is None:
154154
return pl.lit(None)
155+
156+
# Polars lit does not handle pandas timedelta well at v1.36
157+
if isinstance(value, pd.Timedelta):
158+
value = value.to_pytimedelta()
159+
155160
return pl.lit(value, _bigframes_dtype_to_polars_dtype(expression.dtype))
156161

157162
@compile_expression.register

tests/unit/test_series_polars.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5109,3 +5109,18 @@ def test_series_item_with_empty(session):
51095109

51105110
with pytest.raises(ValueError, match=re.escape(expected_message)):
51115111
bf_s_empty.item()
5112+
5113+
5114+
def test_series_dt_total_seconds(scalars_df_index, scalars_pandas_df_index):
5115+
bf_result = scalars_df_index["duration_col"].dt.total_seconds().to_pandas()
5116+
5117+
pd_result = scalars_pandas_df_index["duration_col"].dt.total_seconds()
5118+
5119+
# Index will be object type in pandas, string type in bigframes, but same values
5120+
pd.testing.assert_series_equal(
5121+
bf_result,
5122+
pd_result,
5123+
check_index_type=False,
5124+
# bigframes uses Float64, newer pandas may use double[pyarrow]
5125+
check_dtype=False,
5126+
)

0 commit comments

Comments
 (0)