Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
galipremsagar committed Jan 11, 2023
1 parent 64052f8 commit 678e33e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
16 changes: 15 additions & 1 deletion python/cudf/cudf/core/frame.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2022, NVIDIA CORPORATION.
# Copyright (c) 2020-2023, NVIDIA CORPORATION.

from __future__ import annotations

Expand Down Expand Up @@ -484,6 +484,20 @@ def get_column_values_na(col):
)

if dtype is None:
dtypes = [col.dtype for col in self._data.values()]
for dtype in dtypes:
if isinstance(
dtype,
(
cudf.ListDtype,
cudf.core.dtypes.DecimalDtype,
cudf.StructDtype,
),
):
raise NotImplementedError(
f"{dtype} are not yet supported via "
"`__cuda_array_interface__`"
)
dtype = find_common_type(
[col.dtype for col in self._data.values()]
)
Expand Down
14 changes: 14 additions & 0 deletions python/cudf/cudf/tests/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1869,3 +1869,17 @@ def test_concat_invalid_axis(axis):
s = gd.Series([1, 2, 3])
with pytest.raises(ValueError):
gd.concat([s], axis=axis)


@pytest.mark.parametrize(
"s1,s2,expected",
[
([1, 2], [[1, 2], [3, 4]], ["1", "2", "[1, 2]", "[3, 4]"]),
],
)
def test_concat_mixed_list_types(s1, s2, expected):
s1, s2 = gd.Series(s1), gd.Series(s2)
expected = pd.Series(expected)
actual = gd.concat([s1, s2], ignore_index=True)

assert_eq(expected, actual, check_dtype=False)
21 changes: 12 additions & 9 deletions python/cudf/cudf/utils/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,21 +572,24 @@ def find_common_type(dtypes):
)
else:
return cudf.dtype("O")
if any(
cudf.api.types.is_list_dtype(dtype)
or cudf.api.types.is_struct_dtype(dtype)
for dtype in dtypes
):
if any(cudf.api.types.is_list_dtype(dtype) for dtype in dtypes):
if len(dtypes) == 1:
return dtypes[0]
return dtypes.get(0)
else:
# TODO: As list & struct dtypes allow casting
# TODO: As list dtypes allow casting
# to identical types, improve this logic of returning a
# common dtype, for example:
# ListDtype(int64) & ListDtype(int32) common
# dtype could be ListDtype(int64). Same holds
# for StructDtype too.
# dtype could be ListDtype(int64).
return cudf.dtype("O")
if any(cudf.api.types.is_struct_dtype(dtype) for dtype in dtypes):
if len(dtypes) == 1:
return dtypes.get(0)
else:
raise NotImplementedError(
"Finding a common type for `StructDtype` is currently "
"not supported"
)

# Corner case 1:
# Resort to np.result_type to handle "M" and "m" types separately
Expand Down

0 comments on commit 678e33e

Please sign in to comment.