Skip to content

Commit 17b5d3e

Browse files
committed
allow int timedelta to micro
1 parent a0a2e56 commit 17b5d3e

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

bigframes/core/compile/sqlglot/sqlglot_ir.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,6 @@ def _literal(value: typing.Any, dtype: dtypes.Dtype) -> sge.Expression:
633633
elif dtype == dtypes.JSON_DTYPE:
634634
return sge.ParseJSON(this=sge.convert(str(value)))
635635
elif dtype == dtypes.TIMEDELTA_DTYPE:
636-
if isinstance(value, int):
637-
return sge.convert(value)
638636
return sge.convert(utils.timedelta_to_micros(value))
639637
elif dtypes.is_struct_like(dtype):
640638
items = [

bigframes/core/utils.py

Lines changed: 4 additions & 1 deletion
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]
237+
timedelta: typing.Union[pd.Timedelta, datetime.timedelta, np.timedelta64, int]
238238
) -> int:
239239
if isinstance(timedelta, pd.Timedelta):
240240
# pd.Timedelta.value returns total nanoseconds.
@@ -248,4 +248,7 @@ 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+
251254
raise TypeError(f"Unrecognized input type: {type(timedelta)}")

0 commit comments

Comments
 (0)