From c0044ae43c459d0f15361f864a86cc0d5366c3c7 Mon Sep 17 00:00:00 2001 From: jeszyb Date: Mon, 14 Feb 2022 15:24:36 +0100 Subject: [PATCH 1/2] ARROW-15475: [C++][Python] Add a space after commas in pretty-print output --- cpp/src/arrow/pretty_print.cc | 8 +++++++- cpp/src/arrow/pretty_print_test.cc | 12 ++++++------ python/pyarrow/tests/test_table.py | 14 +++++++------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/cpp/src/arrow/pretty_print.cc b/cpp/src/arrow/pretty_print.cc index 37135ed3ee8..1baf94009fc 100644 --- a/cpp/src/arrow/pretty_print.cc +++ b/cpp/src/arrow/pretty_print.cc @@ -143,7 +143,7 @@ class ArrayPrinter : public PrettyPrinter { IndentAfterNewline(); (*sink_) << "..."; if (!is_last && options_.skip_new_lines) { - (*sink_) << ","; + (*sink_) << ", "; } i = array.length() - options_.window - 1; } else if (array.IsNull(i)) { @@ -151,6 +151,9 @@ class ArrayPrinter : public PrettyPrinter { (*sink_) << options_.null_rep; if (!is_last) { (*sink_) << ","; + if (options_.skip_new_lines) { + (*sink_) << " "; + } } } else { if (indent_non_null_values) { @@ -159,6 +162,9 @@ class ArrayPrinter : public PrettyPrinter { RETURN_NOT_OK(func(i)); if (!is_last) { (*sink_) << ","; + if (options_.skip_new_lines) { + (*sink_) << " "; + } } } Newline(); diff --git a/cpp/src/arrow/pretty_print_test.cc b/cpp/src/arrow/pretty_print_test.cc index 7b47a05630c..5203d533515 100644 --- a/cpp/src/arrow/pretty_print_test.cc +++ b/cpp/src/arrow/pretty_print_test.cc @@ -179,7 +179,7 @@ TEST_F(TestPrettyPrint, PrimitiveTypeNoNewlines) { options.skip_new_lines = true; options.window = 4; - const char* expected = "[0,1,null,3,null]"; + const char* expected = "[0, 1, null, 3, null]"; CheckPrimitive(options, is_valid, values, expected, false); // With ellipsis @@ -188,7 +188,7 @@ TEST_F(TestPrettyPrint, PrimitiveTypeNoNewlines) { values.insert(values.end(), 20, 99); values.insert(values.end(), {44, 43, 42}); - expected = "[0,1,null,3,...,99,44,null,42]"; + expected = "[0, 1, null, 3, ..., 99, 44, null, 42]"; CheckPrimitive(options, is_valid, values, expected, false); } @@ -661,12 +661,12 @@ TEST_F(TestPrettyPrint, BinaryNoNewlines) { PrettyPrintOptions options{}; options.skip_new_lines = true; - const char* expected = "[666F6F,626172,null,62617A,,FF]"; + const char* expected = "[666F6F, 626172, null, 62617A, , FF]"; CheckPrimitive(options, is_valid, values, expected, false); // With ellipsis options.window = 2; - expected = "[666F6F,626172,...,,FF]"; + expected = "[666F6F, 626172, ..., , FF]"; CheckPrimitive(options, is_valid, values, expected, false); } @@ -737,11 +737,11 @@ TEST_F(TestPrettyPrint, ListTypeNoNewlines) { options.skip_new_lines = true; options.null_rep = "NA"; CheckArray(*empty_array, options, "[]", false); - CheckArray(*array, options, "[[NA],[],NA,[4,5,6,7,8],[2,3]]", false); + CheckArray(*array, options, "[[NA], [], NA, [4, 5, 6, 7, 8], [2, 3]]", false); options.window = 2; CheckArray(*empty_array, options, "[]", false); - CheckArray(*array, options, "[[NA],[],...,[4,5,...,7,8],[2,3]]", false); + CheckArray(*array, options, "[[NA], [], ..., [4, 5, ..., 7, 8], [2, 3]]", false); } TEST_F(TestPrettyPrint, MapType) { diff --git a/python/pyarrow/tests/test_table.py b/python/pyarrow/tests/test_table.py index 4555bed9739..75ba6fdbe3c 100644 --- a/python/pyarrow/tests/test_table.py +++ b/python/pyarrow/tests/test_table.py @@ -1758,8 +1758,8 @@ def test_table_repr_to_string(): c0: int16 c1: int32 ---- -c0: [[1,2,3,4]] -c1: [[10,20,30,40]]""" +c0: [[1, 2, 3, 4]] +c1: [[10, 20, 30, 40]]""" assert tab.to_string(show_metadata=True) == """\ pyarrow.Table @@ -1775,15 +1775,15 @@ def test_table_repr_to_string(): c0: int16 c1: int32 ---- -c0: [[1,2,3,4]] -c1: [[10,20,30,40]]""" +c0: [[1, 2, 3, 4]] +c1: [[10, 20, 30, 40]]""" assert tab.to_string(preview_cols=1) == """\ pyarrow.Table c0: int16 c1: int32 ---- -c0: [[1,2,3,4]] +c0: [[1, 2, 3, 4]] ...""" @@ -1801,8 +1801,8 @@ def test_table_repr_to_string_ellipsis(): c0: int16 c1: int32 ---- -c0: [[1,2,3,4,1,2,3,4,1,2,...,3,4,1,2,3,4,1,2,3,4]] -c1: [[10,20,30,40,10,20,30,40,10,20,...,30,40,10,20,30,40,10,20,30,40]]""" +c0: [[1, 2, 3, 4, 1, 2, 3, 4, 1, 2, ..., 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]] +c1: [[10, 20, 30, 40, 10, 20, 30, 40, 10, 20, ..., 30, 40, 10, 20, 30, 40, 10, 20, 30, 40]]""" def test_table_function_unicode_schema(): From 6e44627d70683a62c40e43f23c4d29f38f198599 Mon Sep 17 00:00:00 2001 From: jeszyb Date: Mon, 14 Feb 2022 15:47:23 +0100 Subject: [PATCH 2/2] fix lint --- python/pyarrow/tests/test_table.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/pyarrow/tests/test_table.py b/python/pyarrow/tests/test_table.py index 75ba6fdbe3c..08b62cbd854 100644 --- a/python/pyarrow/tests/test_table.py +++ b/python/pyarrow/tests/test_table.py @@ -1802,7 +1802,8 @@ def test_table_repr_to_string_ellipsis(): c1: int32 ---- c0: [[1, 2, 3, 4, 1, 2, 3, 4, 1, 2, ..., 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]] -c1: [[10, 20, 30, 40, 10, 20, 30, 40, 10, 20, ..., 30, 40, 10, 20, 30, 40, 10, 20, 30, 40]]""" +c1: [[10, 20, 30, 40, 10, 20, 30, 40, 10, 20, ..., 30, 40, 10, 20, 30, 40,\ + 10, 20, 30, 40]]""" def test_table_function_unicode_schema():