From f6ccbbc1ee852754a268c46454803bc9a3f9aebf Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Thu, 1 Oct 2020 04:08:04 +0700 Subject: [PATCH 1/3] TST: adjust expected gap between # and Column --- pandas/tests/io/formats/test_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/formats/test_info.py b/pandas/tests/io/formats/test_info.py index 7000daeb9b575..15ffaac10338b 100644 --- a/pandas/tests/io/formats/test_info.py +++ b/pandas/tests/io/formats/test_info.py @@ -87,7 +87,7 @@ def test_info_verbose(): frame.info(verbose=True, buf=buf) res = buf.getvalue() - header = " # Column Dtype \n--- ------ ----- " + header = " # Column Dtype \n--- ------ ----- " assert header in res frame.info(verbose=True, buf=buf) From 23d8a449401519c6dd7782764199436d0cb5a638 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Thu, 1 Oct 2020 14:50:04 +0700 Subject: [PATCH 2/3] FIX: make two-spaces gap between # and Column --- pandas/io/formats/info.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/io/formats/info.py b/pandas/io/formats/info.py index e8e41d4325103..9812ca39e2656 100644 --- a/pandas/io/formats/info.py +++ b/pandas/io/formats/info.py @@ -288,7 +288,11 @@ def _verbose_repr( len_column = len(pprint_thing(column_head)) space = max(max_col, len_column) + col_space - max_id = len(pprint_thing(col_count)) + # GH #36765 + # add one space in max_id because there is a one-space padding + # in front of the number + # this allows maintain two spaces gap between columns + max_id = len(pprint_thing(col_count)) + 1 len_id = len(pprint_thing(id_head)) space_num = max(max_id, len_id) + col_space From 489bcd47479ab2bee619aa45468364032e3981a0 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Wed, 7 Oct 2020 16:31:16 +0700 Subject: [PATCH 3/3] TST: check spacing for various num of columns --- pandas/tests/io/formats/test_info.py | 58 ++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/pandas/tests/io/formats/test_info.py b/pandas/tests/io/formats/test_info.py index 15ffaac10338b..d98530b5435e7 100644 --- a/pandas/tests/io/formats/test_info.py +++ b/pandas/tests/io/formats/test_info.py @@ -101,6 +101,64 @@ def test_info_verbose(): assert line.startswith(line_nr) +@pytest.mark.parametrize( + "size, header_exp, separator_exp, first_line_exp, last_line_exp", + [ + ( + 4, + " # Column Non-Null Count Dtype ", + "--- ------ -------------- ----- ", + " 0 0 3 non-null float64", + " 3 3 3 non-null float64", + ), + ( + 11, + " # Column Non-Null Count Dtype ", + "--- ------ -------------- ----- ", + " 0 0 3 non-null float64", + " 10 10 3 non-null float64", + ), + ( + 101, + " # Column Non-Null Count Dtype ", + "--- ------ -------------- ----- ", + " 0 0 3 non-null float64", + " 100 100 3 non-null float64", + ), + ( + 1001, + " # Column Non-Null Count Dtype ", + "--- ------ -------------- ----- ", + " 0 0 3 non-null float64", + " 1000 1000 3 non-null float64", + ), + ( + 10001, + " # Column Non-Null Count Dtype ", + "--- ------ -------------- ----- ", + " 0 0 3 non-null float64", + " 10000 10000 3 non-null float64", + ), + ], +) +def test_info_verbose_with_counts_spacing( + size, header_exp, separator_exp, first_line_exp, last_line_exp +): + """Test header column, spacer, first line and last line in verbose mode.""" + frame = DataFrame(np.random.randn(3, size)) + buf = StringIO() + frame.info(verbose=True, null_counts=True, buf=buf) + all_lines = buf.getvalue().splitlines() + # Here table would contain only header, separator and table lines + # dframe repr, index summary, memory usage and dtypes are excluded + table = all_lines[3:-2] + header, separator, first_line, *rest, last_line = table + assert header == header_exp + assert separator == separator_exp + assert first_line == first_line_exp + assert last_line == last_line_exp + + def test_info_memory(): # https://github.com/pandas-dev/pandas/issues/21056 df = DataFrame({"a": Series([1, 2], dtype="i8")})