Skip to content

Commit

Permalink
Remove dead code usage from cudf
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke committed Oct 10, 2024
1 parent 91782a0 commit 7394afe
Showing 1 changed file with 1 addition and 95 deletions.
96 changes: 1 addition & 95 deletions python/cudf/cudf/_lib/scalar.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import numpy as np
import pandas as pd
import pyarrow as pa

from libc.stdint cimport int64_t
from libcpp cimport bool
from libcpp.memory cimport unique_ptr
from libcpp.utility cimport move
Expand All @@ -25,25 +24,7 @@ cimport pylibcudf.libcudf.types as libcudf_types
# DeviceScalar is phased out entirely from cuDF Cython (at which point
# cudf.Scalar will be directly backed by pylibcudf.Scalar).
from pylibcudf cimport Scalar as plc_Scalar
from pylibcudf.libcudf.scalar.scalar cimport (
duration_scalar,
list_scalar,
scalar,
struct_scalar,
timestamp_scalar,
)
from pylibcudf.wrappers.durations cimport (
duration_ms,
duration_ns,
duration_s,
duration_us,
)
from pylibcudf.wrappers.timestamps cimport (
timestamp_ms,
timestamp_ns,
timestamp_s,
timestamp_us,
)
from pylibcudf.libcudf.scalar.scalar cimport list_scalar, scalar, struct_scalar

from cudf._lib.types cimport dtype_from_column_view, underlying_type_t_type_id

Expand Down Expand Up @@ -284,62 +265,6 @@ cdef class DeviceScalar:
]


# TODO: Currently the only uses of this function and the one below are in
# _create_proxy_nat_scalar. See if that code path can be simplified to excise
# or at least simplify these implementations.
cdef _set_datetime64_from_np_scalar(unique_ptr[scalar]& s,
object value,
object dtype,
bool valid=True):

value = value if valid else 0

if dtype == "datetime64[s]":
s.reset(
new timestamp_scalar[timestamp_s](<int64_t>np.int64(value), valid)
)
elif dtype == "datetime64[ms]":
s.reset(
new timestamp_scalar[timestamp_ms](<int64_t>np.int64(value), valid)
)
elif dtype == "datetime64[us]":
s.reset(
new timestamp_scalar[timestamp_us](<int64_t>np.int64(value), valid)
)
elif dtype == "datetime64[ns]":
s.reset(
new timestamp_scalar[timestamp_ns](<int64_t>np.int64(value), valid)
)
else:
raise ValueError(f"dtype not supported: {dtype}")

cdef _set_timedelta64_from_np_scalar(unique_ptr[scalar]& s,
object value,
object dtype,
bool valid=True):

value = value if valid else 0

if dtype == "timedelta64[s]":
s.reset(
new duration_scalar[duration_s](<int64_t>np.int64(value), valid)
)
elif dtype == "timedelta64[ms]":
s.reset(
new duration_scalar[duration_ms](<int64_t>np.int64(value), valid)
)
elif dtype == "timedelta64[us]":
s.reset(
new duration_scalar[duration_us](<int64_t>np.int64(value), valid)
)
elif dtype == "timedelta64[ns]":
s.reset(
new duration_scalar[duration_ns](<int64_t>np.int64(value), valid)
)
else:
raise ValueError(f"dtype not supported: {dtype}")


def as_device_scalar(val, dtype=None):
if isinstance(val, (cudf.Scalar, DeviceScalar)):
if dtype == val.dtype or dtype is None:
Expand All @@ -361,22 +286,3 @@ def _is_null_host_scalar(slr):
return True
else:
return False


def _create_proxy_nat_scalar(dtype):
cdef DeviceScalar result = DeviceScalar.__new__(DeviceScalar)

dtype = cudf.dtype(dtype)
if dtype.char in 'mM':
nat = dtype.type('NaT').astype(dtype)
if dtype.type == np.datetime64:
_set_datetime64_from_np_scalar(
(<plc_Scalar> result.c_value).c_obj, nat, dtype, True
)
elif dtype.type == np.timedelta64:
_set_timedelta64_from_np_scalar(
(<plc_Scalar> result.c_value).c_obj, nat, dtype, True
)
return result
else:
raise TypeError('NAT only valid for datetime and timedelta')

0 comments on commit 7394afe

Please sign in to comment.