From 3c51e962eb9b52ba1af0b93a15c9c2f75bfd129e Mon Sep 17 00:00:00 2001 From: lorenzophys Date: Mon, 30 Aug 2021 12:11:42 +0200 Subject: [PATCH 1/2] TST: added test for to_string when max_rows is zero (GH35394) --- pandas/tests/io/formats/test_to_string.py | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pandas/tests/io/formats/test_to_string.py b/pandas/tests/io/formats/test_to_string.py index 1d3804a955433..46cdc5fdf6e3a 100644 --- a/pandas/tests/io/formats/test_to_string.py +++ b/pandas/tests/io/formats/test_to_string.py @@ -315,3 +315,31 @@ def test_to_string_na_rep_and_float_format(na_rep): 1 A {na_rep}""" ) assert result == expected + + +@pytest.mark.parametrize( + "data,expected", + [ + ( + {"col1": [1, 2], "col2": [3, 4]}, + " col1 col2\n0 1 3\n1 2 4", + ), + ( + {"col1": [0, 2, 4], "col2": [3, 4, 5]}, + " col1 col2\n0 0 3\n1 2 4\n2 4 5", + ), + ( + {"col1": ["Abc", 0.756], "col2": [np.nan, 4.5435]}, + " col1 col2\n0 Abc NaN\n1 0.756 4.5435", + ), + ( + {"col1": [np.nan, "a"], "col2": [0.009, 3.543], "col3": ["Abc", 23]}, + " col1 col2 col3\n0 NaN 0.009 Abc\n1 a 3.543 23", + ), + ], +) +def test_to_string_max_rows_zero(data, expected): + # GH35394 + result = DataFrame(data=data).to_string(max_rows=0) + + assert result == expected From 26e7fcdb18e53419a85f3f590cbd15a746bdbccf Mon Sep 17 00:00:00 2001 From: lorenzophys Date: Wed, 1 Sep 2021 08:47:50 +0200 Subject: [PATCH 2/2] TST: code review fixes, removed redundant test and empty line --- pandas/tests/io/formats/test_to_string.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pandas/tests/io/formats/test_to_string.py b/pandas/tests/io/formats/test_to_string.py index 46cdc5fdf6e3a..5e7aeb7f226de 100644 --- a/pandas/tests/io/formats/test_to_string.py +++ b/pandas/tests/io/formats/test_to_string.py @@ -324,10 +324,6 @@ def test_to_string_na_rep_and_float_format(na_rep): {"col1": [1, 2], "col2": [3, 4]}, " col1 col2\n0 1 3\n1 2 4", ), - ( - {"col1": [0, 2, 4], "col2": [3, 4, 5]}, - " col1 col2\n0 0 3\n1 2 4\n2 4 5", - ), ( {"col1": ["Abc", 0.756], "col2": [np.nan, 4.5435]}, " col1 col2\n0 Abc NaN\n1 0.756 4.5435", @@ -341,5 +337,4 @@ def test_to_string_na_rep_and_float_format(na_rep): def test_to_string_max_rows_zero(data, expected): # GH35394 result = DataFrame(data=data).to_string(max_rows=0) - assert result == expected