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: pandas df.to_markdown() with period at end of field - is not displayed. #57953

Closed
3 tasks done
dwgillies opened this issue Mar 21, 2024 · 2 comments
Closed
3 tasks done
Labels
Bug Closing Candidate May be closeable, needs more eyeballs IO Data IO issues that don't fit into a more specific label Usage Question

Comments

@dwgillies
Copy link

dwgillies commented Mar 21, 2024

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

>>> df = pd.DataFrame({'a': ['1234.']})
>>> df
       a
0  1234.
>>> df.to_markdown()
'|    |    a |\n|---:|-----:|\n|  0 | 1234 |'

^^ notice the 1234 above is lacking the '.' at the end of the string.  When I print the dataframe 
cell, the period appears:

>>> print(df['a'][0])
1234.

Issue Description

When printing a string field that ends in a period, to_markdown() fails to print the period at the end of the string.

Expected Behavior

>>> df.to_markdown()
'|    |    a |\n|---:|-----:|\n|  0 | 1234. |'

Installed Versions

>>> pd.show_versions()
/usr/lib/python3.9/site-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils.
  warnings.warn("Setuptools is replacing distutils.")

INSTALLED VERSIONS
------------------
commit                : fd3f57170aa1af588ba877e8e28c158a20a4886d
python                : 3.9.16.final.0
python-bits           : 64
OS                    : CYGWIN_NT-10.0-19045
OS-release            : 3.5.0-1.x86_64
Version               : 2024-02-01 11:02 UTC
machine               : x86_64
processor             :
byteorder             : little
LC_ALL                : None
LANG                  : None
LOCALE                : en_US.UTF-8

pandas                : 2.2.0
numpy                 : 1.26.4
pytz                  : 2023.3
dateutil              : 2.8.2
setuptools            : 69.0.2
pip                   : 24.0
Cython                : 0.29.33
pytest                : None
hypothesis            : None
sphinx                : 4.4.0
blosc                 : None
feather               : None
xlsxwriter            : None
lxml.etree            : None
html5lib              : None
pymysql               : None
psycopg2              : None
jinja2                : 3.1.2
IPython               : None
pandas_datareader     : None
adbc-driver-postgresql: None
adbc-driver-sqlite    : None
bs4                   : None
bottleneck            : None
dataframe-api-compat  : None
fastparquet           : None
fsspec                : None
gcsfs                 : None
matplotlib            : None
numba                 : None
numexpr               : None
odfpy                 : None
openpyxl              : None
pandas_gbq            : None
pyarrow               : None
pyreadstat            : None
python-calamine       : None
pyxlsb                : None
s3fs                  : None
scipy                 : None
sqlalchemy            : None
tables                : None
tabulate              : 0.9.0
xarray                : None
xlrd                  : None
zstandard             : None
tzdata                : 2024.1
qtpy                  : None
pyqt5                 : None

DEVELOPMENT VERSIONS

ALSO the bug appears on the latest development versions:

>>> pd.show_versions()
/usr/lib/python3.9/site-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils.
  warnings.warn("Setuptools is replacing distutils.")

commit                : d17723c6d447d37c0cb753a517df74705806f4a2
python                : 3.9.16.final.0
python-bits           : 64
OS                    : CYGWIN_NT-10.0-19045
OS-release            : 3.5.0-1.x86_64
Version               : 2024-02-01 11:02 UTC
machine               : x86_64
processor             :
byteorder             : little
LC_ALL                : None
LANG                  : None
LOCALE                : en_US.UTF-8

pandas                : 3.0.0.dev0+578.gd17723c6d4
numpy                 : 1.26.4
pytz                  : 2023.3
dateutil              : 2.8.2
setuptools            : 69.0.2
pip                   : 24.0
Cython                : 0.29.33
pytest                : None
hypothesis            : None
sphinx                : 4.4.0
blosc                 : None
feather               : None
xlsxwriter            : None
lxml.etree            : None
html5lib              : None
pymysql               : None
psycopg2              : None
jinja2                : 3.1.2
IPython               : None
pandas_datareader     : None
adbc-driver-postgresql: None
adbc-driver-sqlite    : None
bs4                   : None
bottleneck            : None
fastparquet           : None
fsspec                : None
gcsfs                 : None
matplotlib            : None
numba                 : None
numexpr               : None
odfpy                 : None
openpyxl              : None
pyarrow               : None
pyreadstat            : None
python-calamine       : None
pyxlsb                : None
s3fs                  : None
scipy                 : None
sqlalchemy            : None
tables                : None
tabulate              : 0.9.0
xarray                : None
xlrd                  : None
zstandard             : None
tzdata                : 2024.1
qtpy                  : None
pyqt5                 : None
@dwgillies dwgillies added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 21, 2024
@Aloqeely
Copy link
Member

Aloqeely commented Mar 21, 2024

Explanation from python-tabulate/README.md:

For tabulate, anything which can be parsed as a number is a number. Even numbers represented as strings are aligned properly. This feature comes in handy when reading a mixed table of text and numbers from a file
To disable this feature use disable_numparse=True.

So to achieve your desired output:

>>> df.to_markdown(disable_numparse=True)
'|    | a     |\n|:---|:------|\n| 0  | 1234. |'

@lithomas1 lithomas1 added IO Data IO issues that don't fit into a more specific label Needs Info Clarification about behavior needed to assess issue Usage Question Closing Candidate May be closeable, needs more eyeballs and removed Needs Triage Issue that has not been reviewed by a pandas team member Needs Info Clarification about behavior needed to assess issue labels Mar 21, 2024
@phofl
Copy link
Member

phofl commented Mar 24, 2024

thanks @Aloqeely, closing here

@phofl phofl closed this as completed Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Closing Candidate May be closeable, needs more eyeballs IO Data IO issues that don't fit into a more specific label Usage Question
Projects
None yet
Development

No branches or pull requests

4 participants