-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
DOC: .to_string
float_format
behavior inconsistent with documentation and different for extension types
#53675
Comments
This does accept formatting string, so the docs could need some updating here and the type hint for This failure you're showing looks like a bug, e.g. if we do A PR for both doc update and bug are welcome. |
@topper-123 for the bug, are we trying to add this functionality for |
Yes, |
take |
hey @otitoU how is it going? Would you mind if I take a look as well? |
Hey @rsm-23 . it is going good! Sorry, i have already spent some time on it, I hope you don't mind I would like to finish this. |
Hey @phofl just to give you a bit of context. what is the cause of the bugSo the Error stack shows the problem arises at file pandas/core/series.py line 1765 when the The are two potential fixes are
Then get a return which would be a formatted value My proposed solution is to Edit the GenericArrayFormatter |
Pandas version checks
main
hereLocation of the documentation
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_string.html
Documentation problem
DataFrame.to_string
docstring saysfloat_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
withfloat_format
string fails withTypeError: 'str' object is not callable
for float extension type columns/series.xref: #9448 pandas-dev/pandas-stubs#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 ofData.Frame.to_string
,pandas/pandas/core/frame.py
Line 1149 in abcd440
does include
str
as an option.pandas/pandas/_typing.py
Line 303 in abcd440
The text was updated successfully, but these errors were encountered: