Skip to content

Commit d540f71

Browse files
committed
Fix bug with smaller change
1 parent 11b09d7 commit d540f71

File tree

4 files changed

+3
-8
lines changed

4 files changed

+3
-8
lines changed

doc/source/whatsnew/v2.0.2.rst

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ Other
4848
~~~~~
4949
- Raised a better error message when calling :func:`Series.dt.to_pydatetime` with :class:`ArrowDtype` with ``pyarrow.date32`` or ``pyarrow.date64`` type (:issue:`52812`)
5050

51-
5251
.. ---------------------------------------------------------------------------
5352
.. _whatsnew_202.contributors:
5453

doc/source/whatsnew/v2.0.3.rst

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ including other versions of pandas.
1414
Fixed regressions
1515
~~~~~~~~~~~~~~~~~
1616
- Fixed performance regression in merging on datetime-like columns (:issue:`53231`)
17+
- Fixed regression when :meth:`DataFrame.to_string` creates extra space for string dtypes (:issue:`52690`)
1718
- For external ExtensionArray implementations, restored the default use of ``_values_for_factorize`` for hashing arrays (:issue:`53475`)
1819
-
1920

pandas/io/formats/format.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1391,11 +1391,8 @@ def _format(x):
13911391

13921392
fmt_values = []
13931393
for i, v in enumerate(vals):
1394-
if not is_float_type[i] and leading_space or self.formatter is not None:
1395-
if leading_space:
1396-
fmt_values.append(f" {_format(v)}")
1397-
else:
1398-
fmt_values.append(f"{_format(v)}")
1394+
if (not is_float_type[i] or self.formatter is not None) and leading_space:
1395+
fmt_values.append(f" {_format(v)}")
13991396
elif is_float_type[i]:
14001397
fmt_values.append(float_format(v))
14011398
else:

pandas/tests/io/formats/test_format.py

-2
Original file line numberDiff line numberDiff line change
@@ -2208,12 +2208,10 @@ def test_max_rows_fitted(self, length, min_rows, max_rows, expected):
22082208

22092209
def test_no_extra_space(self):
22102210
# GH 52690: Check that no extra space is given
2211-
# Expected Output
22122211
col1 = "TEST"
22132212
col2 = "PANDAS"
22142213
col3 = "to_string"
22152214
expected = f"{col1:<6s} {col2:<7s} {col3:<10s}"
2216-
# Testing
22172215
df = DataFrame([{"col1": "TEST", "col2": "PANDAS", "col3": "to_string"}])
22182216
d = {"col1": "{:<6s}".format, "col2": "{:<7s}".format, "col3": "{:<10s}".format}
22192217
result = df.to_string(index=False, header=False, formatters=d)

0 commit comments

Comments
 (0)