Skip to content

Commit

Permalink
Merge pull request #8 from mroeschke/bug/tz/attrs
Browse files Browse the repository at this point in the history
Make tz-aware attributes reflect local time
  • Loading branch information
shwina authored Oct 4, 2023
2 parents ffa3bbe + 6f0aeac commit 4c8e97a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/cudf/cudf/core/column/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions python/cudf/cudf/tests/series/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 4c8e97a

Please sign in to comment.