Skip to content

BUG: na_rep not respected in to_* methods with pd.NA #54872

Open
@mroeschke

Description

@mroeschke

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

In [13]: import pandas as pd

In [14]: df = pd.DataFrame([1, pd.NA], dtype="Int64")

In [15]: df.to_string(na_rep="foo")
Out[15]: '      0\n0     1\n1  <NA>'

In [16]: df.to_xml(na_rep="foo")
--> 283 raise TypeError(f"Invalid value '{str(value)}' for dtype {self.dtype}")

TypeError: Invalid value 'foo' for dtype Int64

Issue Description

Since these should output textual representations of the data, I would expect pd.NA to be replaced with a string na_rep

Expected Behavior

Since these should output textual representations of the data, I would expect pd.NA to be replaced with a string na_rep

Installed Versions

Replace this line with the output of pd.show_versions()

Metadata

Metadata

Assignees

Labels

BugMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolateOutput-Formatting__repr__ of pandas objects, to_string

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions