Skip to content

Commit

Permalink
Fix bug with smaller change
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanx749 committed Jun 26, 2023
1 parent 11b09d7 commit d540f71
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 8 deletions.
1 change: 0 additions & 1 deletion doc/source/whatsnew/v2.0.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Other
~~~~~
- Raised a better error message when calling :func:`Series.dt.to_pydatetime` with :class:`ArrowDtype` with ``pyarrow.date32`` or ``pyarrow.date64`` type (:issue:`52812`)


.. ---------------------------------------------------------------------------
.. _whatsnew_202.contributors:

Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.0.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ including other versions of pandas.
Fixed regressions
~~~~~~~~~~~~~~~~~
- Fixed performance regression in merging on datetime-like columns (:issue:`53231`)
- Fixed regression when :meth:`DataFrame.to_string` creates extra space for string dtypes (:issue:`52690`)
- For external ExtensionArray implementations, restored the default use of ``_values_for_factorize`` for hashing arrays (:issue:`53475`)
-

Expand Down
7 changes: 2 additions & 5 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1391,11 +1391,8 @@ def _format(x):

fmt_values = []
for i, v in enumerate(vals):
if not is_float_type[i] and leading_space or self.formatter is not None:
if leading_space:
fmt_values.append(f" {_format(v)}")
else:
fmt_values.append(f"{_format(v)}")
if (not is_float_type[i] or self.formatter is not None) and leading_space:
fmt_values.append(f" {_format(v)}")
elif is_float_type[i]:
fmt_values.append(float_format(v))
else:
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/io/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -2208,12 +2208,10 @@ def test_max_rows_fitted(self, length, min_rows, max_rows, expected):

def test_no_extra_space(self):
# GH 52690: Check that no extra space is given
# Expected Output
col1 = "TEST"
col2 = "PANDAS"
col3 = "to_string"
expected = f"{col1:<6s} {col2:<7s} {col3:<10s}"
# Testing
df = DataFrame([{"col1": "TEST", "col2": "PANDAS", "col3": "to_string"}])
d = {"col1": "{:<6s}".format, "col2": "{:<7s}".format, "col3": "{:<10s}".format}
result = df.to_string(index=False, header=False, formatters=d)
Expand Down

0 comments on commit d540f71

Please sign in to comment.