Skip to content

Commit 8dde917

Browse files
committed
ENH: Add StataWriter 118 for unicode support
Add StataWriter with unicode support
1 parent 37dfcc1 commit 8dde917

File tree

4 files changed

+330
-169
lines changed

4 files changed

+330
-169
lines changed

doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ Other enhancements
205205
(:meth:`~DataFrame.to_parquet` / :func:`read_parquet`) using the `'pyarrow'` engine
206206
now preserve those data types with pyarrow >= 1.0.0 (:issue:`20612`).
207207
- The ``partition_cols`` argument in :meth:`DataFrame.to_parquet` now accepts a string (:issue:`27117`)
208+
- Added new writer for exporting Stata dta files in version 118, ``StataWriter118``. This format supports exporting strings containing Unicode characters (:issue:`23573`)
208209

209210
Build Changes
210211
^^^^^^^^^^^^^

pandas/core/frame.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -1915,14 +1915,17 @@ def to_stata(
19151915
>>> df.to_stata('animals.dta') # doctest: +SKIP
19161916
"""
19171917
kwargs = {}
1918-
if version not in (114, 117):
1919-
raise ValueError("Only formats 114 and 117 supported.")
1918+
if version not in (114, 117, 118):
1919+
raise ValueError("Only formats 114, 117 and 118 are supported.")
19201920
if version == 114:
19211921
if convert_strl is not None:
1922-
raise ValueError("strl support is only available when using format 117")
1922+
raise ValueError("strl is not supported in format 114")
19231923
from pandas.io.stata import StataWriter as statawriter
19241924
else:
1925-
from pandas.io.stata import StataWriter117 as statawriter
1925+
if version == 117:
1926+
from pandas.io.stata import StataWriter117 as statawriter
1927+
else:
1928+
from pandas.io.stata import StataWriter118 as statawriter
19261929

19271930
kwargs["convert_strl"] = convert_strl
19281931

0 commit comments

Comments
 (0)