Skip to content

Commit

Permalink
fixed merge conflict in decimal.py
Browse files Browse the repository at this point in the history
  • Loading branch information
skirui-source committed Jun 29, 2021
2 parents c69ab3f + ea82bf4 commit 62ad755
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 17 deletions.
6 changes: 3 additions & 3 deletions python/cudf/cudf/core/column/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
from cudf.core.dtypes import CategoricalDtype
from cudf.utils.dtypes import (
is_categorical_dtype,
is_interval_dtype,
is_mixed_with_object_dtype,
min_signed_type,
min_unsigned_type,
is_interval_dtype,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -1388,10 +1388,10 @@ def as_categorical_column(
new_categories=dtype.categories, ordered=dtype.ordered
)

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

def as_string_column(self, dtype, format=None) -> StringColumn:
def as_string_column(self, dtype, format=None, **kwargs) -> StringColumn:
return self._get_decategorized_column().as_string_column(
dtype, format=format
)
Expand Down
8 changes: 4 additions & 4 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ def can_cast_safely(self, to_dtype: Dtype) -> bool:

def astype(self, dtype: Dtype, **kwargs) -> ColumnBase:
if _is_non_decimal_numeric_dtype(dtype):
return self.as_numerical_column(dtype)
return self.as_numerical_column(dtype, **kwargs)
elif is_categorical_dtype(dtype):
return self.as_categorical_column(dtype, **kwargs)
elif pandas_dtype(dtype).type in {
Expand All @@ -903,7 +903,7 @@ def astype(self, dtype: Dtype, **kwargs) -> ColumnBase:
elif np.issubdtype(dtype, np.timedelta64):
return self.as_timedelta_column(dtype, **kwargs)
else:
return self.as_numerical_column(dtype)
return self.as_numerical_column(dtype, **kwargs)

def as_categorical_column(self, dtype, **kwargs) -> ColumnBase:
if "ordered" in kwargs:
Expand Down Expand Up @@ -949,7 +949,7 @@ def as_categorical_column(self, dtype, **kwargs) -> ColumnBase:
)

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

Expand All @@ -969,7 +969,7 @@ def as_timedelta_column(
raise NotImplementedError

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

Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/column/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,14 @@ def as_timedelta_column(
)

def as_numerical_column(
self, dtype: Dtype
self, dtype: Dtype, **kwargs
) -> "cudf.core.column.NumericalColumn":
return cast(
"cudf.core.column.NumericalColumn", self.as_numerical.astype(dtype)
)

def as_string_column(
self, dtype: Dtype, format=None
self, dtype: Dtype, format=None, **kwargs
) -> "cudf.core.column.StringColumn":
if format is None:
format = _dtype_to_format_conversion.get(
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/column/decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,12 @@ def as_decimal_column(
return libcudf.unary.cast(self, dtype)

def as_numerical_column(
self, dtype: Dtype
self, dtype: Dtype, **kwargs
) -> "cudf.core.column.NumericalColumn":
return libcudf.unary.cast(self, dtype)

def as_string_column(
self, dtype: Dtype, format=None
self, dtype: Dtype, format=None, **kwargs
) -> "cudf.core.column.StringColumn":
if len(self) > 0:
return cpp_from_decimal(self)
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/column/numerical.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def int2ip(self) -> "cudf.core.column.StringColumn":
return libcudf.string_casting.int2ip(self)

def as_string_column(
self, dtype: Dtype, format=None
self, dtype: Dtype, format=None, **kwargs
) -> "cudf.core.column.StringColumn":
if len(self) > 0:
return string._numeric_to_str_typecast_functions[
Expand Down Expand Up @@ -252,7 +252,7 @@ def as_decimal_column(
) -> "cudf.core.column.Decimal64Column":
return libcudf.unary.cast(self, dtype)

def as_numerical_column(self, dtype: Dtype) -> NumericalColumn:
def as_numerical_column(self, dtype: Dtype, **kwargs) -> NumericalColumn:
dtype = np.dtype(dtype)
if dtype == self.dtype:
return self
Expand Down
6 changes: 4 additions & 2 deletions python/cudf/cudf/core/column/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -5118,7 +5118,7 @@ def str(self, parent: ParentType = None) -> StringMethods:
return StringMethods(self, parent=parent)

def as_numerical_column(
self, dtype: Dtype
self, dtype: Dtype, **kwargs
) -> "cudf.core.column.NumericalColumn":
out_dtype = np.dtype(dtype)

Expand Down Expand Up @@ -5195,7 +5195,9 @@ def as_decimal_column(
) -> "cudf.core.column.Decimal64Column":
return cpp_to_decimal(self, dtype)

def as_string_column(self, dtype: Dtype, format=None) -> StringColumn:
def as_string_column(
self, dtype: Dtype, format=None, **kwargs
) -> StringColumn:
return self

@property
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/column/timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def fillna(
return super().fillna(method=method)

def as_numerical_column(
self, dtype: Dtype
self, dtype: Dtype, **kwargs
) -> "cudf.core.column.NumericalColumn":
return cast(
"cudf.core.column.NumericalColumn", self.as_numerical.astype(dtype)
Expand All @@ -336,7 +336,7 @@ def as_datetime_column(
)

def as_string_column(
self, dtype: Dtype, format=None
self, dtype: Dtype, format=None, **kwargs
) -> "cudf.core.column.StringColumn":
if format is None:
format = _dtype_to_format_conversion.get(
Expand Down
11 changes: 11 additions & 0 deletions python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,17 @@ def test_dataframe_astype(nelem):
np.testing.assert_equal(df["a"].to_array(), df["b"].to_array())


def test_astype_dict():
gdf = cudf.DataFrame({"a": [1, 2, 3], "b": ["1", "2", "3"]})
pdf = gdf.to_pandas()

assert_eq(pdf.astype({"a": "str"}), gdf.astype({"a": "str"}))
assert_eq(
pdf.astype({"a": "str", "b": np.int64}),
gdf.astype({"a": "str", "b": np.int64}),
)


@pytest.mark.parametrize("nelem", [0, 100])
def test_index_astype(nelem):
df = cudf.DataFrame()
Expand Down

0 comments on commit 62ad755

Please sign in to comment.