Skip to content

Commit 2348896

Browse files
committed
address comments
1 parent d5f12e5 commit 2348896

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

bigframes/core/compile/sqlglot/aggregations/unary_compiler.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import typing
1818

19+
import pandas as pd
1920
import sqlglot.expressions as sge
2021

2122
from bigframes import dtypes
@@ -82,6 +83,9 @@ def _(
8283
expr = column.expr
8384
if column.dtype == dtypes.BOOL_DTYPE:
8485
expr = sge.Cast(this=column.expr, to="INT64")
85-
# Will be null if all inputs are null. Pandas defaults to zero sum though.
86+
8687
expr = apply_window_if_present(sge.func("SUM", expr), window)
87-
return sge.func("IFNULL", expr, ir._literal(0, column.dtype))
88+
89+
# Will be null if all inputs are null. Pandas defaults to zero sum though.
90+
zero = pd.to_timedelta(0) if column.dtype == dtypes.TIMEDELTA_DTYPE else 0
91+
return sge.func("IFNULL", expr, ir._literal(zero, column.dtype))

bigframes/core/utils.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def wrapper(*args, **kwargs):
234234

235235

236236
def timedelta_to_micros(
237-
timedelta: typing.Union[pd.Timedelta, datetime.timedelta, np.timedelta64, int]
237+
timedelta: typing.Union[pd.Timedelta, datetime.timedelta, np.timedelta64]
238238
) -> int:
239239
if isinstance(timedelta, pd.Timedelta):
240240
# pd.Timedelta.value returns total nanoseconds.
@@ -248,7 +248,4 @@ def timedelta_to_micros(
248248
(timedelta.days * 3600 * 24) + timedelta.seconds
249249
) * 1_000_000 + timedelta.microseconds
250250

251-
if isinstance(timedelta, int):
252-
return timedelta
253-
254251
raise TypeError(f"Unrecognized input type: {type(timedelta)}")

0 commit comments

Comments
 (0)