Skip to content

Commit 3a57310

Browse files
committed
CLN: Restructure to_stata in frame
Restructure to get mypy to like it
1 parent 478a65f commit 3a57310

File tree

1 file changed

+44
-27
lines changed

1 file changed

+44
-27
lines changed

pandas/core/frame.py

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,35 +1948,52 @@ def to_stata(
19481948
"""
19491949
if version not in (114, 117, 118, 119, None):
19501950
raise ValueError("Only formats 114, 117, 118 and 119 are supported.")
1951+
if version == 114 and convert_strl is not None:
1952+
raise ValueError("strl is not supported in format 114")
1953+
1954+
# TODO: There must be a better way?
19511955
if version == 114:
1952-
if convert_strl is not None:
1953-
raise ValueError("strl is not supported in format 114")
1954-
from pandas.io.stata import StataWriter as statawriter
1956+
from pandas.io.stata import StataWriter
1957+
1958+
StataWriter(
1959+
path,
1960+
self,
1961+
convert_dates=convert_dates,
1962+
byteorder=byteorder,
1963+
time_stamp=time_stamp,
1964+
data_label=data_label,
1965+
write_index=write_index,
1966+
variable_labels=variable_labels,
1967+
).write_file()
19551968
elif version == 117:
1956-
from pandas.io.stata import StataWriter117 as statawriter
1957-
else: # versions 118 and 119
1958-
from pandas.io.stata import StataWriterUTF8 as statawriter
1959-
1960-
kwargs = {}
1961-
if version is None or version >= 117:
1962-
# strl conversion is only supported >= 117
1963-
kwargs["convert_strl"] = convert_strl
1964-
if version is None or version >= 118:
1965-
# Specifying the version is only supported for UTF8 (118 or 119)
1966-
kwargs["version"] = version
1967-
1968-
writer = statawriter(
1969-
path,
1970-
self,
1971-
convert_dates=convert_dates,
1972-
byteorder=byteorder,
1973-
time_stamp=time_stamp,
1974-
data_label=data_label,
1975-
write_index=write_index,
1976-
variable_labels=variable_labels,
1977-
**kwargs,
1978-
)
1979-
writer.write_file()
1969+
from pandas.io.stata import StataWriter117
1970+
1971+
StataWriter117(
1972+
path,
1973+
self,
1974+
convert_dates=convert_dates,
1975+
byteorder=byteorder,
1976+
time_stamp=time_stamp,
1977+
data_label=data_label,
1978+
write_index=write_index,
1979+
variable_labels=variable_labels,
1980+
convert_strl=convert_strl,
1981+
).write_file()
1982+
else:
1983+
from pandas.io.stata import StataWriterUTF8
1984+
1985+
StataWriterUTF8(
1986+
path,
1987+
self,
1988+
convert_dates=convert_dates,
1989+
byteorder=byteorder,
1990+
time_stamp=time_stamp,
1991+
data_label=data_label,
1992+
write_index=write_index,
1993+
variable_labels=variable_labels,
1994+
convert_strl=convert_strl,
1995+
version=version,
1996+
).write_file()
19801997

19811998
@deprecate_kwarg(old_arg_name="fname", new_arg_name="path")
19821999
def to_feather(self, path) -> None:

0 commit comments

Comments
 (0)