Skip to content

Commit 303ba16

Browse files
committed
ENH: Add StataWriter 118 for unicode support
Add StataWriter with unicode support
1 parent e66a2c7 commit 303ba16

File tree

4 files changed

+330
-170
lines changed

4 files changed

+330
-170
lines changed

doc/source/whatsnew/v1.0.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ Other enhancements
207207
- The ``partition_cols`` argument in :meth:`DataFrame.to_parquet` now accepts a string (:issue:`27117`)
208208
- :func:`to_parquet` now appropriately handles the ``schema`` argument for user defined schemas in the pyarrow engine. (:issue: `30270`)
209209
- DataFrame constructor preserve `ExtensionArray` dtype with `ExtensionArray` (:issue:`11363`)
210-
210+
- Added new writer for exporting Stata dta files in version 118, ``StataWriter118``. This format supports exporting strings containing Unicode characters (:issue:`23573`)
211211

212212
Build Changes
213213
^^^^^^^^^^^^^

pandas/core/frame.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,14 +1926,17 @@ def to_stata(
19261926
>>> df.to_stata('animals.dta') # doctest: +SKIP
19271927
"""
19281928
kwargs = {}
1929-
if version not in (114, 117):
1930-
raise ValueError("Only formats 114 and 117 supported.")
1929+
if version not in (114, 117, 118):
1930+
raise ValueError("Only formats 114, 117 and 118 are supported.")
19311931
if version == 114:
19321932
if convert_strl is not None:
1933-
raise ValueError("strl support is only available when using format 117")
1933+
raise ValueError("strl is not supported in format 114")
19341934
from pandas.io.stata import StataWriter as statawriter
19351935
else:
1936-
from pandas.io.stata import StataWriter117 as statawriter
1936+
if version == 117:
1937+
from pandas.io.stata import StataWriter117 as statawriter
1938+
else:
1939+
from pandas.io.stata import StataWriter118 as statawriter
19371940

19381941
kwargs["convert_strl"] = convert_strl
19391942

0 commit comments

Comments
 (0)