Skip to content

Commit a3ffa9c

Browse files
bashtageTomAugspurgerjbrockmendel
authored andcommitted
ENH: Add StataWriter 118 for unicode support (pandas-dev#30285)
Add StataWriter with unicode support Co-authored-by: Tom Augspurger <[email protected]> Co-authored-by: jbrockmendel <[email protected]>
1 parent ed58bbd commit a3ffa9c

File tree

4 files changed

+371
-182
lines changed

4 files changed

+371
-182
lines changed

doc/source/whatsnew/v1.0.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ Other enhancements
213213
- DataFrame constructor preserve `ExtensionArray` dtype with `ExtensionArray` (:issue:`11363`)
214214
- :meth:`DataFrame.sort_values` and :meth:`Series.sort_values` have gained ``ignore_index`` keyword to be able to reset index after sorting (:issue:`30114`)
215215
- :meth:`DataFrame.to_markdown` and :meth:`Series.to_markdown` added (:issue:`11052`)
216-
217216
- :meth:`DataFrame.drop_duplicates` has gained ``ignore_index`` keyword to reset index (:issue:`30114`)
217+
- Added new writer for exporting Stata dta files in version 118, ``StataWriter118``. This format supports exporting strings containing Unicode characters (:issue:`23573`)
218218

219219
Build Changes
220220
^^^^^^^^^^^^^

pandas/core/frame.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -1929,14 +1929,17 @@ def to_stata(
19291929
>>> df.to_stata('animals.dta') # doctest: +SKIP
19301930
"""
19311931
kwargs = {}
1932-
if version not in (114, 117):
1933-
raise ValueError("Only formats 114 and 117 supported.")
1932+
if version not in (114, 117, 118):
1933+
raise ValueError("Only formats 114, 117 and 118 are supported.")
19341934
if version == 114:
19351935
if convert_strl is not None:
1936-
raise ValueError("strl support is only available when using format 117")
1936+
raise ValueError("strl is not supported in format 114")
19371937
from pandas.io.stata import StataWriter as statawriter
19381938
else:
1939-
from pandas.io.stata import StataWriter117 as statawriter
1939+
if version == 117:
1940+
from pandas.io.stata import StataWriter117 as statawriter
1941+
else:
1942+
from pandas.io.stata import StataWriter118 as statawriter
19401943

19411944
kwargs["convert_strl"] = convert_strl
19421945

0 commit comments

Comments
 (0)