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

to_string() does not have an "encoding" parameter. #28766

Closed
mohitanand001 opened this issue Oct 3, 2019 · 6 comments · Fixed by #28951
Closed

to_string() does not have an "encoding" parameter. #28766

mohitanand001 opened this issue Oct 3, 2019 · 6 comments · Fixed by #28951
Labels
API Design Enhancement Output-Formatting __repr__ of pandas objects, to_string
Milestone

Comments

@mohitanand001
Copy link
Contributor

mohitanand001 commented Oct 3, 2019

Code Sample, a copy-pastable example if possible

df = pd.DataFrame(data = {'Japanese' : 'こんにちは', 'English' : 'Hello'}, index = [0])
df.to_string()

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS

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

pandas : 0.25.0
numpy : 1.16.2
pytz : 2018.7
dateutil : 2.7.5
pip : 18.1
setuptools : 40.6.3
Cython : 0.29.2
pytest : 4.0.2
hypothesis : None
sphinx : 1.8.2
blosc : None
feather : 0.4.0
xlsxwriter : 1.1.2
lxml.etree : 4.2.5
html5lib : 1.0.1
pymysql : None
psycopg2 : 2.8.3 (dt dec pq3 ext lo64)
jinja2 : 2.10
IPython : 7.2.0
pandas_datareader: None
bs4 : 4.6.3
bottleneck : 1.2.1
fastparquet : None
gcsfs : None
lxml.etree : 4.2.5
matplotlib : 3.0.2
numexpr : 2.6.8
odfpy : None
openpyxl : 2.5.12
pandas_gbq : None
pyarrow : 0.13.0
pytables : None
s3fs : None
scipy : 1.1.0
sqlalchemy : 1.2.15
tables : 3.4.4
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : 1.1.2

@mohitanand001 mohitanand001 changed the title to_string() does not have an encoding parameter. to_string() does not have an "encoding" parameter. Oct 3, 2019
@mroeschke
Copy link
Member

Can you give an example of the expected behavior and API parameters?

@mroeschke mroeschke added API Design Enhancement Strings String extension data type and string data labels Oct 3, 2019
@mohitanand001
Copy link
Contributor Author

mohitanand001 commented Oct 3, 2019

Just like to_csv() and to_excel() have an "encoding" parameters, we can have an encoding parameter in string for consistency.

df.to_string(encoding = "iso-8859-1")

@WillAyd
Copy link
Member

WillAyd commented Oct 3, 2019

Might not be thinking straight today but wouldn't this only make sense if it were a to_bytes method? Not applicable for to_string, no?

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Oct 4, 2019 via email

@mohitanand001
Copy link
Contributor Author

mohitanand001 commented Oct 4, 2019

#28663 (comment)

the to_html method has no encoding. I assume that it is fairly simple to work-around by passing an open buffer with the correct encoding or not passing a filepath, and writing the return unicode string to file using the appropriate encoding?

the buffer handling code is shared with to_latex and to_string. to_latex already has an encoding parameter and the shared code can handle encoding. so it should be straightforward to add encoding to to_html ( and to_string) for consistency.
#15008 (comment) "Textual payloads should support the encoding argument"

@TomAugspurger
Copy link
Contributor

Forgot about the buf argument accepting a string path.

In that case, accepting an encoding makes sense, for specifying the encoding for the newly created file. We should raise when encoding is specified and it's buf isn't a string path.

@simonjayhawkins simonjayhawkins added IO Data IO issues that don't fit into a more specific label and removed Strings String extension data type and string data labels Oct 4, 2019
@simonjayhawkins simonjayhawkins added Output-Formatting __repr__ of pandas objects, to_string and removed IO Data IO issues that don't fit into a more specific label labels Oct 13, 2019
@jreback jreback added this to the 1.0 milestone Oct 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Enhancement Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants