Skip to content

Commit 0ad881b

Browse files
authored
chore: Remap '1q' to '3mo' in IbisExpr.dt.truncate (#2567)
chore: Remap '1q' to '3mo' in IbisExpr.dt.truncate
1 parent 80c28ff commit 0ad881b

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

narwhals/_ibis/expr_dt.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ def fn(_input: ir.TimestampValue) -> ir.TimestampValue:
7474

7575
def truncate(self, every: str) -> IbisExpr:
7676
multiple, unit = parse_interval_string(every)
77+
if unit == "q":
78+
multiple, unit = 3 * multiple, "mo"
7779
if multiple != 1:
7880
if self._compliant_expr._backend_version < (7, 1): # pragma: no cover
7981
msg = "Truncating datetimes with multiples of the unit is only supported in Ibis >= 7.1."

tests/expr_and_series/dt/truncate_test.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -191,32 +191,20 @@ def test_truncate_multiples(
191191
every: str,
192192
expected: list[datetime],
193193
) -> None:
194-
if any(x in str(constructor) for x in ("sqlframe",)):
195-
request.applymarker(
196-
pytest.mark.xfail(reason="https://github.com/eakmanrq/sqlframe/issues/383")
197-
)
194+
if any(x in str(constructor) for x in ("sqlframe", "cudf", "pyspark")):
195+
# Reasons:
196+
# - sqlframe: https://github.com/eakmanrq/sqlframe/issues/383
197+
# - cudf: https://github.com/rapidsai/cudf/issues/18654
198+
# - pyspark: Only multiple 1 is currently supported
199+
request.applymarker(pytest.mark.xfail())
198200
if every.endswith("ns") and any(
199201
x in str(constructor) for x in ("polars", "duckdb", "ibis")
200202
):
201203
request.applymarker(pytest.mark.xfail())
202-
if "cudf" in str(constructor):
203-
# https://github.com/rapidsai/cudf/issues/18654
204-
request.applymarker(pytest.mark.xfail(reason="Not implemented"))
205204
if any(every.endswith(x) for x in ("mo", "q", "y")) and any(
206205
x in str(constructor) for x in ("dask",)
207206
):
208207
request.applymarker(pytest.mark.xfail(reason="Not implemented"))
209-
if any(every.endswith(x) for x in ("q",)) and any(
210-
x in str(constructor) for x in ("ibis",)
211-
):
212-
request.applymarker(pytest.mark.xfail(reason="Not implemented"))
213-
request.applymarker(
214-
pytest.mark.xfail(
215-
"pyspark" in str(constructor),
216-
raises=ValueError,
217-
reason="Only multiple 1 is currently supported",
218-
)
219-
)
220208
df = nw.from_native(constructor(data))
221209
result = df.select(nw.col("a").dt.truncate(every))
222210
assert_equal_data(result, {"a": expected})

0 commit comments

Comments
 (0)