|
19 | 19 | from cudf.core.column.temporal_base import TemporalBaseColumn |
20 | 20 | from cudf.errors import MixedTypeError |
21 | 21 | from cudf.utils.dtypes import ( |
| 22 | + CUDF_STRING_DTYPE, |
22 | 23 | cudf_dtype_from_pa_type, |
23 | 24 | cudf_dtype_to_pa_type, |
24 | 25 | find_common_type, |
@@ -248,27 +249,29 @@ def as_datetime_column(self, dtype: np.dtype) -> None: # type: ignore[override] |
248 | 249 | f"cannot astype a timedelta from {self.dtype} to {dtype}" |
249 | 250 | ) |
250 | 251 |
|
251 | | - def strftime(self, format: str) -> StringColumn: |
| 252 | + def strftime( |
| 253 | + self, format: str, dtype: DtypeObj = CUDF_STRING_DTYPE |
| 254 | + ) -> StringColumn: |
252 | 255 | if len(self) == 0: |
253 | 256 | return super().strftime(format) |
254 | | - else: |
255 | | - with self.access(mode="read", scope="internal"): |
256 | | - return cast( |
257 | | - cudf.core.column.string.StringColumn, |
258 | | - type(self).from_pylibcudf( |
259 | | - plc.strings.convert.convert_durations.from_durations( |
260 | | - self.plc_column, format |
261 | | - ) |
| 257 | + with self.access(mode="read", scope="internal"): |
| 258 | + return cast( |
| 259 | + cudf.core.column.string.StringColumn, |
| 260 | + ColumnBase.create( |
| 261 | + plc.strings.convert.convert_durations.from_durations( |
| 262 | + self.plc_column, format |
262 | 263 | ), |
263 | | - ) |
| 264 | + dtype, |
| 265 | + ), |
| 266 | + ) |
264 | 267 |
|
265 | 268 | def as_string_column(self, dtype: DtypeObj) -> StringColumn: |
266 | 269 | if cudf.get_option("mode.pandas_compatible"): |
267 | 270 | if isinstance(dtype, np.dtype) and dtype.kind == "O": |
268 | 271 | raise MixedTypeError( |
269 | 272 | f"cannot astype a timedelta like from {self.dtype} to {dtype}" |
270 | 273 | ) |
271 | | - return self.strftime("%D days %H:%M:%S") |
| 274 | + return self.strftime("%D days %H:%M:%S", dtype=dtype) |
272 | 275 |
|
273 | 276 | def as_timedelta_column(self, dtype: np.dtype) -> TimeDeltaColumn: |
274 | 277 | if dtype == self.dtype: |
|
0 commit comments