Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: DataFrame.to_string() creates extra space for string dtypes in pandas >=2.0 #52690

Closed
3 tasks done
samuelchodur opened this issue Apr 16, 2023 · 2 comments · Fixed by #53855
Closed
3 tasks done
Assignees
Labels
Bug Output-Formatting __repr__ of pandas objects, to_string Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@samuelchodur
Copy link

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd

print(pd.__version__)

# Expected Output
col1 = 'TEST'
col2 = 'PANDAS'
col3 = 'to_string'
print(f'{col1:<6s} {col2:<7s} {col3:<10s}')

# to_string output
df = pd.DataFrame([{'col1': 'TEST', 'col2': 'PANDAS',
                    'col3': 'to_string'}])
d = {'col1': '{:<6s}'.format,
     'col2': '{:<7s}'.format,
     'col3': '{:<10s}'.format}
print(df.to_string(index=False, header=False,
                   formatters=d))

Issue Description

Extra spaces get added when using to_string() in pandas 2.0 and the main branch.

image

Possibly related:
#4158
#4668

Was advised in Slack to create a new issue, as those bug reports are quite old.

Expected Behavior

Issue not present in pandas 1.5.3.

image

Installed Versions

INSTALLED VERSIONS (non-working)

commit : b661313
python : 3.8.16.final.0
python-bits : 64
OS : Linux
OS-release : 6.1.23-1-MANJARO
Version : #1 SMP PREEMPT_DYNAMIC Thu Apr 6 19:47:04 UTC 2023
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.utf8
LOCALE : en_US.UTF-8

pandas : 2.1.0.dev0+527.gb661313cf5.dirty
numpy : 1.23.5
pytz : 2023.3
dateutil : 2.8.2
setuptools : 67.6.1
pip : 23.1
Cython : 0.29.33
pytest : 7.3.1
hypothesis : 6.71.0
sphinx : 4.5.0
blosc : None
feather : None
xlsxwriter : 3.0.9
lxml.etree : 4.9.2
html5lib : 1.1
pymysql : 1.0.3
psycopg2 : 2.9.3
jinja2 : 3.1.2
IPython : 8.12.0
pandas_datareader: None
bs4 : 4.12.2
bottleneck : 1.3.7
brotli :
fastparquet : 2023.2.0
fsspec : 2023.4.0
gcsfs : 2023.4.0
matplotlib : 3.6.3
numba : 0.56.4
numexpr : 2.8.4
odfpy : None
openpyxl : 3.1.0
pandas_gbq : None
pyarrow : 11.0.0
pyreadstat : 1.2.1
pyxlsb : 1.0.10
s3fs : 2023.4.0
scipy : 1.10.1
snappy :
sqlalchemy : 2.0.9
tables : 3.8.0
tabulate : 0.9.0
xarray : 2023.1.0
xlrd : 2.0.1
zstandard : 0.19.0
tzdata : 2023.3
qtpy : None
pyqt5 : None

@samuelchodur samuelchodur added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 16, 2023
@samuelchodur samuelchodur changed the title BUG: DataFrame.to_string() creates extra space for string dtypes in pandas 2.0 BUG: DataFrame.to_string() creates extra space for string dtypes in pandas >=2.0 Apr 16, 2023
@phofl
Copy link
Member

phofl commented Apr 17, 2023

Author: Patrick Hoefler <61934744+phofl@users.noreply.github.com>
Date:   Mon Dec 19 19:51:08 2022 +0100

    BUG: to_string ignoring formatter for FloatingArray (#50333)

#50333

@phofl phofl added this to the 2.0.1 milestone Apr 17, 2023
@phofl phofl added Output-Formatting __repr__ of pandas objects, to_string Regression Functionality that used to work in a prior pandas version and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 17, 2023
@reddyrg1
Copy link
Contributor

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Output-Formatting __repr__ of pandas objects, to_string Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants