Skip to content

Commit

Permalink
ENH: Add StataWriter 118 for unicode support
Browse files Browse the repository at this point in the history
Add StataWriter with unicode support
  • Loading branch information
bashtage committed Dec 16, 2019
1 parent 37dfcc1 commit e1d47c4
Show file tree
Hide file tree
Showing 4 changed files with 330 additions and 169 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ Other enhancements
(:meth:`~DataFrame.to_parquet` / :func:`read_parquet`) using the `'pyarrow'` engine
now preserve those data types with pyarrow >= 1.0.0 (:issue:`20612`).
- The ``partition_cols`` argument in :meth:`DataFrame.to_parquet` now accepts a string (:issue:`27117`)
- Added new writer for exporting Stata dta files in version 118, ``StataWriter118``. This format supports exporting strings containing Unicode characters (:issue:`23573`)

Build Changes
^^^^^^^^^^^^^
Expand Down
11 changes: 7 additions & 4 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1915,14 +1915,17 @@ def to_stata(
>>> df.to_stata('animals.dta') # doctest: +SKIP
"""
kwargs = {}
if version not in (114, 117):
raise ValueError("Only formats 114 and 117 supported.")
if version not in (114, 117, 118):
raise ValueError("Only formats 114, 117 and 118 are supported.")
if version == 114:
if convert_strl is not None:
raise ValueError("strl support is only available when using format 117")
raise ValueError("strl is not supported in format 114")
from pandas.io.stata import StataWriter as statawriter
else:
from pandas.io.stata import StataWriter117 as statawriter
if version == 117:
from pandas.io.stata import StataWriter117 as statawriter
else:
from pandas.io.stata import StataWriter118 as statawriter

kwargs["convert_strl"] = convert_strl

Expand Down
Loading

0 comments on commit e1d47c4

Please sign in to comment.