Skip to content

Commit

Permalink
feat(pandas,dask): support quarter truncation
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Jul 29, 2024
1 parent 000c0fd commit 9982bcd
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 19 deletions.
18 changes: 0 additions & 18 deletions ibis/backends/dask/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import dask.dataframe as dd
import numpy as np
import pandas as pd
from packaging.version import parse as vparse

import ibis.backends.dask.kernels as dask_kernels
import ibis.expr.operations as ops
Expand Down Expand Up @@ -97,23 +96,6 @@ def mapper(df, cases, results, default):

return cls.partitionwise(mapper, kwargs, name=op.name, dtype=dtype)

@classmethod
def visit(cls, op: ops.TimestampTruncate | ops.DateTruncate, arg, unit):
# TODO(kszucs): should use serieswise()
if vparse(pd.__version__) >= vparse("2.2"):
units = {"m": "min"}
else:
units = {"m": "Min", "ms": "L"}

unit = units.get(unit.short, unit.short)

if unit in "YMWD":
return arg.dt.to_period(unit).dt.to_timestamp()
try:
return arg.dt.floor(unit)
except ValueError:
return arg.dt.to_period(unit).dt.to_timestamp()

@classmethod
def visit(cls, op: ops.IntervalFromInteger, unit, **kwargs):
if unit.short in {"Y", "Q", "M", "W"}:
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/pandas/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def visit(cls, op: ops.TimestampTruncate | ops.DateTruncate, arg, unit):

unit = units.get(unit.short, unit.short)

if unit in "YMWD":
if unit in "YQMWD":
return arg.dt.to_period(unit).dt.to_timestamp()
try:
return arg.dt.floor(unit)
Expand Down

0 comments on commit 9982bcd

Please sign in to comment.