Skip to content

Commit

Permalink
Remove unnecessary **kwargs in function signatures (#14635)
Browse files Browse the repository at this point in the history
Helps makes function signatures stricter to avoid typo inputs being accepted into signatures

Authors:
  - Matthew Roeschke (https://github.com/mroeschke)

Approvers:
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #14635
  • Loading branch information
mroeschke authored Jan 12, 2024
1 parent e50fa00 commit 9937c7f
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 107 deletions.
4 changes: 2 additions & 2 deletions python/cudf/cudf/_lib/groupby.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2023, NVIDIA CORPORATION.
# Copyright (c) 2020-2024, NVIDIA CORPORATION.

from pandas.core.groupby.groupby import DataError

Expand Down Expand Up @@ -104,7 +104,7 @@ cdef class GroupBy:
cdef unique_ptr[libcudf_groupby.groupby] c_obj
cdef dict __dict__

def __cinit__(self, list keys, bool dropna=True, *args, **kwargs):
def __cinit__(self, list keys, bool dropna=True):
cdef libcudf_types.null_policy c_null_handling
cdef table_view keys_view

Expand Down
36 changes: 15 additions & 21 deletions python/cudf/cudf/_lib/string_casting.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2023, NVIDIA CORPORATION.
# Copyright (c) 2020-2024, NVIDIA CORPORATION.

from cudf._lib.column cimport Column

Expand Down Expand Up @@ -95,7 +95,7 @@ def dtos(Column input_col):
return floating_to_string(input_col)


def stod(Column input_col, **kwargs):
def stod(Column input_col):
"""
Converting/Casting input column of type string to double
Expand Down Expand Up @@ -127,7 +127,7 @@ def ftos(Column input_col):
return floating_to_string(input_col)


def stof(Column input_col, **kwargs):
def stof(Column input_col):
"""
Converting/Casting input column of type string to float
Expand Down Expand Up @@ -188,7 +188,7 @@ def i8tos(Column input_col):
return integer_to_string(input_col)


def stoi8(Column input_col, **kwargs):
def stoi8(Column input_col):
"""
Converting/Casting input column of type string to int8
Expand Down Expand Up @@ -284,7 +284,7 @@ def ltos(Column input_col):
return integer_to_string(input_col)


def stol(Column input_col, **kwargs):
def stol(Column input_col):
"""
Converting/Casting input column of type string to int64
Expand Down Expand Up @@ -316,7 +316,7 @@ def ui8tos(Column input_col):
return integer_to_string(input_col)


def stoui8(Column input_col, **kwargs):
def stoui8(Column input_col):
"""
Converting/Casting input column of type string to uint8
Expand Down Expand Up @@ -348,7 +348,7 @@ def ui16tos(Column input_col):
return integer_to_string(input_col)


def stoui16(Column input_col, **kwargs):
def stoui16(Column input_col):
"""
Converting/Casting input column of type string to uint16
Expand Down Expand Up @@ -380,7 +380,7 @@ def uitos(Column input_col):
return integer_to_string(input_col)


def stoui(Column input_col, **kwargs):
def stoui(Column input_col):
"""
Converting/Casting input column of type string to uint32
Expand Down Expand Up @@ -412,7 +412,7 @@ def ultos(Column input_col):
return integer_to_string(input_col)


def stoul(Column input_col, **kwargs):
def stoul(Column input_col):
"""
Converting/Casting input column of type string to uint64
Expand Down Expand Up @@ -456,7 +456,7 @@ def _to_booleans(Column input_col, object string_true="True"):
return Column.from_unique_ptr(move(c_result))


def to_booleans(Column input_col, **kwargs):
def to_booleans(Column input_col):

return _to_booleans(input_col)

Expand Down Expand Up @@ -631,9 +631,7 @@ def timedelta2int(Column input_col, dtype, format):
return Column.from_unique_ptr(move(c_result))


def int2timedelta(
Column input_col,
**kwargs):
def int2timedelta(Column input_col, str format):
"""
Converting/Casting input Timedelta column to string
column with specified format
Expand All @@ -649,8 +647,7 @@ def int2timedelta(
"""

cdef column_view input_column_view = input_col.view()
cdef string c_duration_format = kwargs.get(
'format', "%D days %H:%M:%S").encode('UTF-8')
cdef string c_duration_format = format.encode('UTF-8')
cdef unique_ptr[column] c_result
with nogil:
c_result = move(
Expand All @@ -661,7 +658,7 @@ def int2timedelta(
return Column.from_unique_ptr(move(c_result))


def int2ip(Column input_col, **kwargs):
def int2ip(Column input_col):
"""
Converting/Casting integer column to string column in ipv4 format
Expand All @@ -684,7 +681,7 @@ def int2ip(Column input_col, **kwargs):
return Column.from_unique_ptr(move(c_result))


def ip2int(Column input_col, **kwargs):
def ip2int(Column input_col):
"""
Converting string ipv4 column to integer column
Expand Down Expand Up @@ -732,7 +729,6 @@ def htoi(Column input_col, **kwargs):
Parameters
----------
input_col : input column of type string
out_type : The type of integer column expected
Returns
-------
Expand All @@ -742,9 +738,7 @@ def htoi(Column input_col, **kwargs):
cdef column_view input_column_view = input_col.view()
cdef type_id tid = <type_id> (
<underlying_type_t_type_id> (
SUPPORTED_NUMPY_TO_LIBCUDF_TYPES[
kwargs.get('dtype', cudf.dtype("int64"))
]
SUPPORTED_NUMPY_TO_LIBCUDF_TYPES[cudf.dtype("int64")]
)
)
cdef data_type c_out_type = data_type(tid)
Expand Down
18 changes: 12 additions & 6 deletions python/cudf/cudf/core/column/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1310,22 +1310,28 @@ def as_categorical_column(self, dtype: Dtype) -> CategoricalColumn:
new_categories=dtype.categories, ordered=bool(dtype.ordered)
)

def as_numerical_column(self, dtype: Dtype, **kwargs) -> NumericalColumn:
def as_numerical_column(self, dtype: Dtype) -> NumericalColumn:
return self._get_decategorized_column().as_numerical_column(dtype)

def as_string_column(self, dtype, format=None, **kwargs) -> StringColumn:
def as_string_column(
self, dtype, format: str | None = None
) -> StringColumn:
return self._get_decategorized_column().as_string_column(
dtype, format=format
)

def as_datetime_column(self, dtype, **kwargs) -> DatetimeColumn:
def as_datetime_column(
self, dtype, format: str | None = None
) -> DatetimeColumn:
return self._get_decategorized_column().as_datetime_column(
dtype, **kwargs
dtype, format
)

def as_timedelta_column(self, dtype, **kwargs) -> TimeDeltaColumn:
def as_timedelta_column(
self, dtype, format: str | None = None
) -> TimeDeltaColumn:
return self._get_decategorized_column().as_timedelta_column(
dtype, **kwargs
dtype, format
)

def _get_decategorized_column(self) -> ColumnBase:
Expand Down
59 changes: 25 additions & 34 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,11 +978,17 @@ def distinct_count(self, dropna: bool = True) -> int:
def can_cast_safely(self, to_dtype: Dtype) -> bool:
raise NotImplementedError()

def astype(self, dtype: Dtype, **kwargs) -> ColumnBase:
def astype(
self, dtype: Dtype, copy: bool = False, format: str | None = None
) -> ColumnBase:
if copy:
col = self.copy()
else:
col = self
if self.dtype == dtype:
return self
return col
if is_categorical_dtype(dtype):
return self.as_categorical_column(dtype)
return col.as_categorical_column(dtype)

if (
isinstance(dtype, str)
Expand All @@ -999,9 +1005,9 @@ def astype(self, dtype: Dtype, **kwargs) -> ColumnBase:
else:
dtype = pandas_dtypes_to_np_dtypes.get(dtype, dtype)
if _is_non_decimal_numeric_dtype(dtype):
return self.as_numerical_column(dtype, **kwargs)
return col.as_numerical_column(dtype)
elif is_categorical_dtype(dtype):
return self.as_categorical_column(dtype)
return col.as_categorical_column(dtype)
elif cudf.dtype(dtype).type in {
np.str_,
np.object_,
Expand All @@ -1014,23 +1020,23 @@ def astype(self, dtype: Dtype, **kwargs) -> ColumnBase:
f"Casting to {dtype} is not supported, use "
"`.astype('str')` instead."
)
return self.as_string_column(dtype, **kwargs)
return col.as_string_column(dtype, format=format)
elif isinstance(dtype, (ListDtype, StructDtype)):
if not self.dtype == dtype:
if not col.dtype == dtype:
raise NotImplementedError(
f"Casting {self.dtype} columns not currently supported"
)
return self
return col
elif isinstance(dtype, IntervalDtype):
return self.as_interval_column(dtype, **kwargs)
return col.as_interval_column(dtype)
elif isinstance(dtype, cudf.core.dtypes.DecimalDtype):
return self.as_decimal_column(dtype, **kwargs)
return col.as_decimal_column(dtype)
elif np.issubdtype(cast(Any, dtype), np.datetime64):
return self.as_datetime_column(dtype, **kwargs)
return col.as_datetime_column(dtype, format=format)
elif np.issubdtype(cast(Any, dtype), np.timedelta64):
return self.as_timedelta_column(dtype, **kwargs)
return col.as_timedelta_column(dtype, format=format)
else:
return self.as_numerical_column(dtype, **kwargs)
return col.as_numerical_column(dtype)

def as_categorical_column(self, dtype) -> ColumnBase:
if isinstance(dtype, (cudf.CategoricalDtype, pd.CategoricalDtype)):
Expand Down Expand Up @@ -1076,50 +1082,35 @@ def as_categorical_column(self, dtype) -> ColumnBase:
)

def as_numerical_column(
self, dtype: Dtype, **kwargs
self, dtype: Dtype
) -> "cudf.core.column.NumericalColumn":
raise NotImplementedError

def as_datetime_column(
self, dtype: Dtype, **kwargs
self, dtype: Dtype, format: str | None = None
) -> "cudf.core.column.DatetimeColumn":
raise NotImplementedError

def as_interval_column(
self, dtype: Dtype, **kwargs
self, dtype: Dtype
) -> "cudf.core.column.IntervalColumn":
raise NotImplementedError

def as_timedelta_column(
self, dtype: Dtype, **kwargs
self, dtype: Dtype, format: str | None = None
) -> "cudf.core.column.TimeDeltaColumn":
raise NotImplementedError

def as_string_column(
self, dtype: Dtype, format=None, **kwargs
self, dtype: Dtype, format: str | None = None
) -> "cudf.core.column.StringColumn":
raise NotImplementedError

def as_decimal_column(
self, dtype: Dtype, **kwargs
self, dtype: Dtype
) -> Union["cudf.core.column.decimal.DecimalBaseColumn"]:
raise NotImplementedError

def as_decimal128_column(
self, dtype: Dtype, **kwargs
) -> "cudf.core.column.Decimal128Column":
raise NotImplementedError

def as_decimal64_column(
self, dtype: Dtype, **kwargs
) -> "cudf.core.column.Decimal64Column":
raise NotImplementedError

def as_decimal32_column(
self, dtype: Dtype, **kwargs
) -> "cudf.core.column.Decimal32Column":
raise NotImplementedError

def apply_boolean_mask(self, mask) -> ColumnBase:
mask = as_column(mask)
if not is_bool_dtype(mask.dtype):
Expand Down
14 changes: 8 additions & 6 deletions python/cudf/cudf/core/column/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,21 +422,23 @@ def __cuda_array_interface__(self) -> Mapping[str, Any]:
)
return output

def as_datetime_column(self, dtype: Dtype, **kwargs) -> DatetimeColumn:
def as_datetime_column(
self, dtype: Dtype, format: str | None = None
) -> DatetimeColumn:
dtype = cudf.dtype(dtype)
if dtype == self.dtype:
return self
return libcudf.unary.cast(self, dtype=dtype)

def as_timedelta_column(
self, dtype: Dtype, **kwargs
self, dtype: Dtype, format: str | None = None
) -> "cudf.core.column.TimeDeltaColumn":
raise TypeError(
f"cannot astype a datetimelike from {self.dtype} to {dtype}"
)

def as_numerical_column(
self, dtype: Dtype, **kwargs
self, dtype: Dtype
) -> "cudf.core.column.NumericalColumn":
col = column.build_column(
data=self.base_data,
Expand All @@ -448,7 +450,7 @@ def as_numerical_column(
return cast("cudf.core.column.NumericalColumn", col.astype(dtype))

def as_string_column(
self, dtype: Dtype, format=None, **kwargs
self, dtype: Dtype, format: str | None = None
) -> "cudf.core.column.StringColumn":
if format is None:
format = _dtype_to_format_conversion.get(
Expand Down Expand Up @@ -725,9 +727,9 @@ def _local_time(self):
return utc_to_local(self, str(self.dtype.tz))

def as_string_column(
self, dtype: Dtype, format=None, **kwargs
self, dtype: Dtype, format: str | None = None
) -> "cudf.core.column.StringColumn":
return self._local_time.as_string_column(dtype, format, **kwargs)
return self._local_time.as_string_column(dtype, format)

def get_dt_field(self, field: str) -> ColumnBase:
return libcudf.datetime.extract_datetime_component(
Expand Down
Loading

0 comments on commit 9937c7f

Please sign in to comment.