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

Conversation

galipremsagar
Copy link
Contributor

Fixes: #7735

Minimal repro of the above issue is:

>>> import cudf
>>> s = cudf.Series(['hi', 'hello', None])
>>> s
0       hi
1    hello
2     <NA>
dtype: string
>>> h = s[0:3]
0       hi
1    hello
2     <NA>
dtype: string
>>> s._column.null_count
1
>>> h._column.null_count
1

Incorrect mask calculation in Column.from_column_view because of incorrect base_size calculation in StringColumn:

>>> s._column.mask.to_host_array()
array([3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
      dtype=uint8)
>>> h._column.mask.to_host_array()
array([], dtype=uint8) # Should have a mask similar to above one.

>>> s._column.base_size
0 # Should be 3
>>> h._column.base_size
0 # Should be 3

So in this PR I have fixed the calculation of StringColumn.base_size and introduced tests to have a check for the same.

@galipremsagar galipremsagar added bug Something isn't working 3 - Ready for Review Ready for review by team Python Affects Python cuDF API. 4 - Needs cuDF (Python) Reviewer dask Dask issue strings strings issues (C++ and Python) labels Mar 28, 2021
@galipremsagar galipremsagar requested review from a team as code owners March 28, 2021 20:42
@galipremsagar galipremsagar self-assigned this Mar 28, 2021
@galipremsagar galipremsagar added the non-breaking Non-breaking change label Mar 28, 2021
Comment on lines 2927 to 2938
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._column.mask.to_host_array(),
expected._column.mask.to_host_array(),
)
assert_eq(actual, expected)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we convert this to something that tests user-facing behaviour rather than internal behaviour?

In other words, did this bug manifest in a way that affected end-users? If so, can we test that we fixed that instead?

Copy link
Contributor Author

@galipremsagar galipremsagar Mar 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I had this similar thought initially and thought we could check with isnull public API, but since this goes to libcudf call and that returns the correct result without interacting with Column.mask we cannot validate using Series.isnull.

The closest user-facing behavior where this issue would surface is when we round-trip(when it goes through serialize) a series with string dtype & having nulls like in test_distributed::test_str_series_roundtrip.

Had to add both user-facing & internal test because we don't seem to validate base_size anywhere except for this test where we only test against an empty column:

def test_string_no_children_properties():
empty_col = StringColumn(children=())
assert empty_col.base_children == ()
assert empty_col.base_size == 0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like we should definitely add a test for that then (maybe in test_serialize.py?).

We can keep this test in addition, if you prefer. Personally, I'm not a fan of testing internals, but that could be just me :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a serialization test where we would still have to validate an internal component(i.e., the frames) and removed checking for mask and retained base_size checks in test_string.py

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand -- what internal attribute are we testing in the new serialize test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Serialize returns a dict & Frames as buffers. The internal attribute we are testing here is Frames([index_frame, offset_frame, chars_frame, mask_frame]), to be specific we want to validate the mask_frame at last index which would be the right validation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thanks!

@codecov
Copy link

codecov bot commented Mar 28, 2021

Codecov Report

Merging #7746 (7f279d1) into branch-0.19 (ccc28d5) will increase coverage by 0.40%.
The diff coverage is 100.00%.

Impacted file tree graph

@@               Coverage Diff               @@
##           branch-0.19    #7746      +/-   ##
===============================================
+ Coverage        82.13%   82.54%   +0.40%     
===============================================
  Files              101      101              
  Lines            17096    17461     +365     
===============================================
+ Hits             14042    14413     +371     
+ Misses            3054     3048       -6     
Impacted Files Coverage Δ
python/cudf/cudf/core/column/string.py 86.79% <100.00%> (+0.21%) ⬆️
python/cudf/cudf/io/feather.py 100.00% <0.00%> (ø)
python/cudf/cudf/comm/serialize.py 0.00% <0.00%> (ø)
python/cudf/cudf/_fuzz_testing/io.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/column/struct.py 100.00% <0.00%> (ø)
python/dask_cudf/dask_cudf/_version.py 0.00% <0.00%> (ø)
python/dask_cudf/dask_cudf/io/tests/test_csv.py 100.00% <0.00%> (ø)
python/dask_cudf/dask_cudf/io/tests/test_orc.py 100.00% <0.00%> (ø)
python/dask_cudf/dask_cudf/io/tests/test_json.py 100.00% <0.00%> (ø)
...ython/dask_cudf/dask_cudf/io/tests/test_parquet.py 100.00% <0.00%> (ø)
... and 38 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ccc28d5...7f279d1. Read the comment docs.

@kkraus14
Copy link
Collaborator

@gpucibot merge

@rapids-bot rapids-bot bot merged commit 42c3bf9 into rapidsai:branch-0.19 Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dask Dask issue non-breaking Non-breaking change Python Affects Python cuDF API. strings strings issues (C++ and Python)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] dask_cudf constructors turn None into empty string
3 participants