Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion python/cudf/cudf/core/column/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,17 @@ def _get_dt_field(
self, field: plc.datetime.DatetimeComponent
) -> ColumnBase:
with self.access(mode="read", scope="internal"):
return type(self).from_pylibcudf(
result = type(self).from_pylibcudf(
plc.datetime.extract_datetime_component(
self.plc_column,
field,
)
)
if cudf.get_option(
"mode.pandas_compatible"
) and result.dtype == np.dtype("int16"):
result = result.astype(np.dtype("int32"))
return result

def _get_field_names(
self,
Expand Down
34 changes: 33 additions & 1 deletion python/cudf/cudf/tests/series/accessors/test_dt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION.
# SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION.
# SPDX-License-Identifier: Apache-2.0
import datetime
import zoneinfo
Expand Down Expand Up @@ -733,3 +733,35 @@ def test_convert_edge_cases(data, original_timezone, target_timezone):
expect = ps.dt.tz_convert(target_timezone)
got = gs.dt.tz_convert(target_timezone)
assert_eq(expect, got)


@pytest.mark.parametrize(
"data",
[
pd.date_range("2020-01-01", periods=10, freq="D"),
pd.date_range("1990-01-01", periods=100, freq="ME"),
pd.to_datetime(["2023-12-25", "2024-01-01", "2024-06-15", None]),
],
)
@pytest.mark.parametrize(
"component",
[
"year",
"month",
"day",
"hour",
"minute",
"second",
"microsecond",
"nanosecond",
"weekday",
],
)
def test_dt_component_dtype_pandas_compat(data, component):
ps = pd.Series(data)
gs = cudf.Series(data)

with cudf.option_context("mode.pandas_compatible", True):
expect = getattr(ps.dt, component)
got = getattr(gs.dt, component)
assert_eq(expect, got, check_dtype=True)
Loading