|
5 | 5 |
|
6 | 6 | from narwhals._compliant.any_namespace import DateTimeNamespace
|
7 | 7 | from narwhals._duration import parse_interval_string
|
| 8 | +from narwhals._pandas_like.utils import UNIT_DICT |
8 | 9 | from narwhals._pandas_like.utils import PandasLikeSeriesNamespace
|
9 | 10 | from narwhals._pandas_like.utils import calculate_timestamp_date
|
10 | 11 | from narwhals._pandas_like.utils import calculate_timestamp_datetime
|
@@ -196,6 +197,11 @@ def timestamp(self, time_unit: TimeUnit) -> PandasLikeSeries:
|
196 | 197 | def truncate(self, every: str) -> PandasLikeSeries:
|
197 | 198 | multiple, unit = parse_interval_string(every)
|
198 | 199 | native = self.native
|
| 200 | + if self.implementation.is_cudf(): |
| 201 | + if multiple != 1: |
| 202 | + msg = f"Only multiple `1` is supported for cuDF, got: {multiple}." |
| 203 | + raise NotImplementedError(msg) |
| 204 | + return self.with_native(self.native.dt.floor(UNIT_DICT.get(unit, unit))) |
199 | 205 | dtype_backend = get_dtype_backend(native.dtype, self.compliant._implementation)
|
200 | 206 | if unit in {"mo", "q", "y"}:
|
201 | 207 | if self.implementation.is_cudf():
|
@@ -225,6 +231,6 @@ def truncate(self, every: str) -> PandasLikeSeries:
|
225 | 231 | result_arr, dtype=native.dtype, index=native.index, name=native.name
|
226 | 232 | )
|
227 | 233 | return self.with_native(result_native)
|
228 |
| - if unit == "m": |
229 |
| - every = every.replace("m", "min", 1) |
230 |
| - return self.with_native(self.native.dt.floor(every)) |
| 234 | + return self.with_native( |
| 235 | + self.native.dt.floor(f"{multiple}{UNIT_DICT.get(unit, unit)}") |
| 236 | + ) |
0 commit comments