Skip to content

Commit 665621c

Browse files
committed
MAINT: Clarify supported Stata dta versions
Test against old Stata versions and remove text indicating support for versions which do not work reliably closes #26667
1 parent 9a741d3 commit 665621c

File tree

9 files changed

+15
-4
lines changed

9 files changed

+15
-4
lines changed

doc/source/whatsnew/v1.1.0.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ Other enhancements
226226
- :meth:`~pandas.core.resample.Resampler.interpolate` now supports SciPy interpolation method :class:`scipy.interpolate.CubicSpline` as method ``cubicspline`` (:issue:`33670`)
227227
- The ``ExtensionArray`` class has now an :meth:`~pandas.arrays.ExtensionArray.equals`
228228
method, similarly to :meth:`Series.equals` (:issue:`27081`).
229-
-
229+
- The minimum suppported dta version has increased to 105 in :meth:`~pandas.io.stata.read_stata` and :class:`~pandas.io.stata.StataReader` (:issue:`26667`).
230+
230231

231232
.. ---------------------------------------------------------------------------
232233

pandas/io/stata.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
_version_error = (
5353
"Version of given Stata file is {version}. pandas supports importing "
54-
"versions 104, 105, 108, 111 (Stata 7SE), 113 (Stata 8/9), "
54+
"versions 105, 108, 111 (Stata 7SE), 113 (Stata 8/9), "
5555
"114 (Stata 10/11), 115 (Stata 12), 117 (Stata 13), 118 (Stata 14/15/16),"
5656
"and 119 (Stata 15/16, over 32,767 variables)."
5757
)
@@ -888,8 +888,8 @@ def __init__(self):
888888
98: 251, # byte
889889
105: 252, # int
890890
108: 253, # long
891-
102: 254 # float
892-
# don't know old code for double
891+
102: 254, # float
892+
100: 255, # double
893893
}
894894

895895
# These missing values are the generic '.' in Stata, and are used
771 Bytes
Binary file not shown.
Binary file not shown.
1.48 KB
Binary file not shown.
1.48 KB
Binary file not shown.
1.77 KB
Binary file not shown.
5.66 KB
Binary file not shown.

pandas/tests/io/test_stata.py

+10
Original file line numberDiff line numberDiff line change
@@ -1853,3 +1853,13 @@ def test_writer_118_exceptions(self):
18531853
with tm.ensure_clean() as path:
18541854
with pytest.raises(ValueError, match="You must use version 119"):
18551855
StataWriterUTF8(path, df, version=118)
1856+
1857+
1858+
@pytest.mark.parametrize("version", [105, 108, 111, 113, 114])
1859+
def test_backward_compat(version, datapath):
1860+
data_base = datapath("io", "data", "stata")
1861+
ref = os.path.join(data_base, f"stata-compat-118.dta")
1862+
old = os.path.join(data_base, f"stata-compat-{version}.dta")
1863+
expected = pd.read_stata(ref)
1864+
old_dta = pd.read_stata(old)
1865+
tm.assert_frame_equal(old_dta, expected, check_dtype=False)

0 commit comments

Comments
 (0)