Skip to content

additional leading space when using formatters on object column #26002

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

Open
simonjayhawkins opened this issue Apr 5, 2019 · 0 comments
Open
Labels
Bug Output-Formatting __repr__ of pandas objects, to_string

Comments

@simonjayhawkins
Copy link
Member

Code Sample, a copy-pastable example if possible

code sample adapted from test_to_string_with_formatters in pandas\tests\io\formats\test_format.py

from pandas import DataFrame

df = DataFrame({'int': [1, 2, 3],
                'float': [1.0, 2.0, 3.0],
                'object': [(1, 2), True, False]},
               columns=['int', 'float', 'object'])

formatters = [('int', lambda x: '0x{x:x}'.format(x=x)),
              ('float', lambda x: '[{x: 4.1f}]'.format(x=x)),
              ('object', lambda x: '-{x!s}-'.format(x=x))]
print(df.to_string(formatters=dict(formatters)))
  int  float    object
0 0x1 [ 1.0]  -(1, 2)-
1 0x2 [ 2.0]    -True-
2 0x3 [ 3.0]   -False-

Problem description

2 spaces between float and object columns, only 1 between int and float

Expected Output

even spacing

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.7.2.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 58 Stepping 9, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.25.0.dev0+376.gfc5f29237
pytest: 4.3.0
pip: 19.0.3
setuptools: 40.6.3
Cython: 0.29.5
numpy: 1.16.2
scipy: 1.2.1
pyarrow: 0.11.1
xarray: 0.11.3
IPython: 7.3.0
sphinx: 1.8.4
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2018.9
blosc: None
bottleneck: 1.2.1
tables: 3.4.4
numexpr: 2.6.9
feather: None
matplotlib: 3.0.2
openpyxl: 2.6.0
xlrd: 1.2.0
xlwt: 1.3.0
xlsxwriter: 1.1.5
lxml.etree: 4.3.1
bs4: 4.7.1
html5lib: 1.0.1
sqlalchemy: 1.2.18
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: 0.2.0
fastparquet: 0.2.1
pandas_gbq: None
pandas_datareader: None
gcsfs: None

simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Apr 5, 2019
@jreback jreback added the Output-Formatting __repr__ of pandas objects, to_string label Apr 6, 2019
@jreback jreback added this to the 0.25.0 milestone Apr 6, 2019
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Apr 6, 2019
@jreback jreback modified the milestones: 0.25.0, Contributions Welcome Apr 20, 2019
@mroeschke mroeschke added the Bug label May 16, 2020
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
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
Projects
None yet
Development

No branches or pull requests

3 participants