pandas-dev / pandas-dev/pandas

DOC: `.to_string` `float_format` behavior inconsistent with documentation and different for extension types

Open
#53,675 11 comments 0 reactions 1 assignee View on GitHub

@cucuwang is already working on this.

Since Sep 9, 2026.

Bug Docs ExtensionArray Output-Formatting
Dominant language
Python
Stars
49.8k
Forks
20.4k
Avg merge
1d 16h
Merged PRs (30d)
322

Description

Pandas version checks
  • I have checked that the issue still exists on the latest versions of the docs on main here
Location of the documentation

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_string.html

Documentation problem

DataFrame.to_string docstring says float_format should be "one-parameter function, optional, default None", but passing a format string (e.g. '%.3e') works too, like in .to_csv, for NumPy float type columns/series.

However, unlike .to_csv, .to_string with float_format string fails with TypeError: 'str' object is not callable for float extension type columns/series.

s = pd.Series([1.1, 2.2, 3.3])

# works
s.to_csv(float_format="%.3e")
s.convert_dtypes().to_csv(float_format="%.3e")
s.to_string(float_format="%.3e")

# fails
s.convert_dtypes().to_string(float_format="%.3e")

xref: #9448 https://github.com/pandas-dev/pandas-stubs/issues/730

Suggested fix for documentation

It would be nice for the documentation to reflect that a format string can be used, but probably the issue with extension types should be fixed first.

Note also that FloatFormatType, used in the internal typing of DataFrame.to_string,

https://github.com/pandas-dev/pandas/blob/abcd440e11d061171b0a4eeb058748629a288568/pandas/core/frame.py#L1149

does include str as an option.

https://github.com/pandas-dev/pandas/blob/abcd440e11d061171b0a4eeb058748629a288568/pandas/_typing.py#L303

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.