Skip to content

Commit 35ba6b0

Browse files
bashtageTomAugspurgerjbrockmendel
committed
ENH: Add StataWriter 118 for unicode support (#30285)
Add StataWriter with unicode support Co-authored-by: Tom Augspurger <[email protected]> Co-authored-by: jbrockmendel <[email protected]>
1 parent 6322b8f commit 35ba6b0

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
@@ -221,8 +221,8 @@ Other enhancements
221221
- DataFrame constructor preserve `ExtensionArray` dtype with `ExtensionArray` (:issue:`11363`)
222222
- :meth:`DataFrame.sort_values` and :meth:`Series.sort_values` have gained ``ignore_index`` keyword to be able to reset index after sorting (:issue:`30114`)
223223
- :meth:`DataFrame.to_markdown` and :meth:`Series.to_markdown` added (:issue:`11052`)
224-
225224
- :meth:`DataFrame.drop_duplicates` has gained ``ignore_index`` keyword to reset index (:issue:`30114`)
225+
- Added new writer for exporting Stata dta files in version 118, ``StataWriter118``. This format supports exporting strings containing Unicode characters (:issue:`23573`)
226226

227227
Build Changes
228228
^^^^^^^^^^^^^

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)