Skip to content

Commit 8043174

Browse files
committed
CLN: Restructure to_stata in frame
Restructure to get mypy to like it
1 parent 335a3e4 commit 8043174

File tree

1 file changed

+44
-27
lines changed

1 file changed

+44
-27
lines changed

pandas/core/frame.py

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

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

0 commit comments

Comments
 (0)