Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG FIX] TimedeltaIndex constructor raises an AttributeError. #9884

Merged
merged 14 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
16 changes: 15 additions & 1 deletion python/cudf/cudf/core/column/timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)
from cudf.api.types import is_scalar
from cudf.core.buffer import Buffer
from cudf.core.column import ColumnBase, column, string
from cudf.core.column import ColumnBase, column, column_empty_like, string
from cudf.core.column.datetime import _numpy_to_pandas_conversion
from cudf.utils.dtypes import np_to_pa_dtype
from cudf.utils.utils import _fillna_natwise
Expand Down Expand Up @@ -227,6 +227,20 @@ def _binary_op_truediv(

return lhs, rhs, out_dtype

def _make_copy_with_na_as_null(self):
skirui-source marked this conversation as resolved.
Show resolved Hide resolved
"""Return a copy with NaN values replaced with nulls."""
skirui-source marked this conversation as resolved.
Show resolved Hide resolved
null = column_empty_like(self, masked=True, newsize=1)
na_value = np.timedelta64("nat", self.time_unit)
skirui-source marked this conversation as resolved.
Show resolved Hide resolved
out_col = cudf._lib.replace.replace(
self,
column.build_column(
Buffer(np.array([na_value], dtype=self.dtype).view("|u1")),
dtype=self.dtype,
),
null,
)
return out_col

def binary_operator(
self, op: str, rhs: BinaryOperand, reflect: bool = False
) -> "column.ColumnBase":
Expand Down
20 changes: 20 additions & 0 deletions python/cudf/cudf/tests/test_timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -1406,3 +1406,23 @@ def test_error_values():
match="TimeDelta Arrays is not yet implemented in cudf",
):
s.values


@pytest.mark.parametrize("dtype", utils.TIMEDELTA_TYPES)
def test_create_TimedeltaIndex(dtype):
gdi = cudf.TimedeltaIndex(
[1132223, 2023232, 342234324, 4234324], dtype=dtype
)
pdi = gdi.to_pandas()

assert_eq(pdi, gdi)


@pytest.mark.parametrize("dtype", utils.TIMEDELTA_TYPES)
def test_create_TimedeltaIndex_with_name(dtype):
gdi = cudf.TimedeltaIndex(
[1132223, 2023232, 342234324, 4234324], dtype=dtype, name="delta-index"
)
pdi = gdi.to_pandas()

assert_eq(pdi, gdi)
skirui-source marked this conversation as resolved.
Show resolved Hide resolved