diff --git a/python/cudf/cudf/core/column/datetime.py b/python/cudf/cudf/core/column/datetime.py index 97ed34d5697..b03b3c905a4 100644 --- a/python/cudf/cudf/core/column/datetime.py +++ b/python/cudf/cudf/core/column/datetime.py @@ -719,6 +719,11 @@ def as_string_column( ) -> "cudf.core.column.StringColumn": return self._local_time.as_string_column(dtype, format, **kwargs) + def get_dt_field(self, field: str) -> ColumnBase: + return libcudf.datetime.extract_datetime_component( + self._local_time, field + ) + def __repr__(self): # Arrow prints the UTC timestamps, but we want to print the # local timestamps: diff --git a/python/cudf/cudf/tests/series/test_datetimelike.py b/python/cudf/cudf/tests/series/test_datetimelike.py index 80b343c2332..85da985940f 100644 --- a/python/cudf/cudf/tests/series/test_datetimelike.py +++ b/python/cudf/cudf/tests/series/test_datetimelike.py @@ -178,3 +178,15 @@ 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) + + +def test_tz_aware_attributes_local(): + data = [ + "2008-05-12 13:50:00", + "2008-12-12 14:50:35", + "2009-05-12 13:50:32", + ] + dti = cudf.DatetimeIndex(data).tz_localize("UTC").tz_convert("US/Eastern") + result = dti.hour + expected = cudf.Index([9, 9, 9], dtype="int16") + assert_eq(result, expected)