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

[REVIEW] Fix data corruption in string columns #7746

Merged
merged 4 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 5 additions & 8 deletions python/cudf/cudf/core/column/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@
is_space as cpp_isspace,
is_upper as cpp_is_upper,
)
from cudf._lib.strings.convert.convert_integers import (
is_integer as cpp_is_integer,
)
from cudf._lib.strings.convert.convert_floats import is_float as cpp_is_float
from cudf._lib.strings.combine import (
concatenate as cpp_concatenate,
join as cpp_join,
Expand All @@ -91,6 +87,10 @@
from cudf._lib.strings.convert.convert_fixed_point import (
to_decimal as cpp_to_decimal,
)
from cudf._lib.strings.convert.convert_floats import is_float as cpp_is_float
from cudf._lib.strings.convert.convert_integers import (
is_integer as cpp_is_integer,
)
from cudf._lib.strings.convert.convert_urls import (
url_decode as cpp_url_decode,
url_encode as cpp_url_encode,
Expand Down Expand Up @@ -4760,10 +4760,7 @@ def base_size(self) -> int:
if len(self.base_children) == 0:
return 0
else:
return int(
(self.base_children[0].size - 1)
/ self.base_children[0].dtype.itemsize
)
return self.base_children[0].size - 1

@property
def data_array_view(self) -> cuda.devicearray.DeviceNDArray:
Expand Down
21 changes: 21 additions & 0 deletions python/cudf/cudf/tests/test_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,24 @@ def test_deserialize_cudf_0_16(datadir):
actual = pickle.load(open(fname, "rb"))

assert_eq(expected, actual)


def test_serialize_sliced_string():
# https://github.com/rapidsai/cudf/issues/7735
data = ["hi", "hello", None]
pd_series = pd.Series(data, dtype=pd.StringDtype())
gd_series = cudf.Series(data, dtype="str")
sliced = gd_series[0:3]
serialized_gd_series = gd_series.serialize()
serialized_sliced = sliced.serialize()

# validate frames are equal or not
# because both should be identical
for i in range(3):
assert_eq(
serialized_gd_series[1][i].to_host_array(),
serialized_sliced[1][i].to_host_array(),
)

recreated = cudf.Series.deserialize(*sliced.serialize())
assert_eq(recreated.to_pandas(nullable=True), pd_series)
11 changes: 11 additions & 0 deletions python/cudf/cudf/tests/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -2922,3 +2922,14 @@ def test_string_std():
assert_exceptions_equal(
lfunc=psr.std, rfunc=sr.std, compare_error_message=False
)


def test_string_slice_with_mask():
actual = cudf.Series(["hi", "hello", None])
expected = actual[0:3]

assert actual._column.base_size == 3
assert_eq(actual._column.base_size, expected._column.base_size)
assert_eq(actual._column.null_count, expected._column.null_count)

assert_eq(actual, expected)
14 changes: 12 additions & 2 deletions python/dask_cudf/dask_cudf/tests/test_distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from dask.distributed import Client
from distributed.utils_test import loop # noqa: F401

import dask_cudf

import cudf
from cudf.tests.utils import assert_eq

import dask_cudf

dask_cuda = pytest.importorskip("dask_cuda")


Expand Down Expand Up @@ -65,3 +65,13 @@ def test_ucx_seriesgroupby():
dask_df_g = dask_df.groupby(["a"]).b.sum().compute()

assert dask_df_g.name == "b"


def test_str_series_roundtrip():
with dask_cuda.LocalCUDACluster(n_workers=1) as cluster:
with Client(cluster):
expected = cudf.Series(["hi", "hello", None])
dask_series = dask_cudf.from_cudf(expected, npartitions=2)

actual = dask_series.compute()
assert_eq(actual, expected)