Skip to content

Commit

Permalink
ARROW-75: Fix handling of empty strings
Browse files Browse the repository at this point in the history
Fixes [ARROW-75](https://issues.apache.org/jira/browse/ARROW-75) (and changes Python tests to verify that behavior).

Author: Dan Robinson <danrobinson010@gmail.com>

Closes #32 from danrobinson/ARROW-75 and squashes the following commits:

cb8e527 [Dan Robinson] ARROW-75: remove whitespace
9604a21 [Dan Robinson] ARROW-75: Changed tests
722df19 [Dan Robinson] ARROW-75: Fixed braces
1ef3b75 [Dan Robinson] ARROW-75: Fix handling of empty strings
  • Loading branch information
danrobinson authored and wesm committed Mar 22, 2016
1 parent 4ec034b commit 093f9bd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion cpp/src/arrow/types/primitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ class PrimitiveBuilder : public ArrayBuilder {
int32_t new_capacity = util::next_power2(length_ + length);
RETURN_NOT_OK(Resize(new_capacity));
}
memcpy(raw_buffer() + length_, values, length * elsize_);
if (length > 0) {
memcpy(raw_buffer() + length_, values, length * elsize_);
}

if (null_bytes != nullptr) {
AppendNulls(null_bytes, length);
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/types/string-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class TestStringBuilder : public TestBuilder {
};

TEST_F(TestStringBuilder, TestScalarAppend) {
std::vector<std::string> strings = {"a", "bb", "", "", "ccc"};
std::vector<std::string> strings = {"", "bb", "a", "", "ccc"};
std::vector<uint8_t> is_null = {0, 0, 0, 1, 0};

int N = strings.size();
Expand Down
6 changes: 3 additions & 3 deletions python/pyarrow/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ def test_list_format(self):
assert result == expected

def test_string_format(self):
arr = pyarrow.from_pylist(['foo', None, 'bar'])
arr = pyarrow.from_pylist(['', None, 'foo'])
result = fmt.array_format(arr)
expected = """\
[
'foo',
'',
NA,
'bar'
'foo'
]"""
assert result == expected

Expand Down

0 comments on commit 093f9bd

Please sign in to comment.