Repository: pandas-dev/pandas
Pull request: TST: Add tests for reading Stata dta files saved in big-endian format
- [x] closes #58194
- [x] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature
- [x] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).
- [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions.
- [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.


Problem statement:
TST: Extend Stata test data to include big-endian versions
Stata dta files can be saved with the data in either little or big endian format (with the apparent exception of the 102 format). All of the current test data included with Pandas is saved in little-endian format. While all systems currently supported by Stata will save little-endian data there are a number of historic data files saved in big-endian, so it feels like it would be useful to test that these can read correctly.

Hints from issue discussion:

Commit message: TST: Add tests for reading Stata dta files saved in big-endian format

Patch to review:
diff --git a/pandas/tests/io/data/stata/stata-compat-be-105.dta b/pandas/tests/io/data/stata/stata-compat-be-105.dta
new file mode 100644
index 0000000000000..af75548c840d4
Binary files /dev/null and b/pandas/tests/io/data/stata/stata-compat-be-105.dta differ
diff --git a/pandas/tests/io/data/stata/stata-compat-be-108.dta b/pandas/tests/io/data/stata/stata-compat-be-108.dta
new file mode 100644
index 0000000000000..e3e5d85fca4ad
Binary files /dev/null and b/pandas/tests/io/data/stata/stata-compat-be-108.dta differ
diff --git a/pandas/tests/io/data/stata/stata-compat-be-111.dta b/pandas/tests/io/data/stata/stata-compat-be-111.dta
new file mode 100644
index 0000000000000..197decdcf0c2d
Binary files /dev/null and b/pandas/tests/io/data/stata/stata-compat-be-111.dta differ
diff --git a/pandas/tests/io/data/stata/stata-compat-be-113.dta b/pandas/tests/io/data/stata/stata-compat-be-113.dta
new file mode 100644
index 0000000000000..c69c32106114f
Binary files /dev/null and b/pandas/tests/io/data/stata/stata-compat-be-113.dta differ
diff --git a/pandas/tests/io/data/stata/stata-compat-be-114.dta b/pandas/tests/io/data/stata/stata-compat-be-114.dta
new file mode 100644
index 0000000000000..222bdb2b62784
Binary files /dev/null and b/pandas/tests/io/data/stata/stata-compat-be-114.dta differ
diff --git a/pandas/tests/io/data/stata/stata-compat-be-118.dta b/pandas/tests/io/data/stata/stata-compat-be-118.dta
new file mode 100644
index 0000000000000..0a5df1b321c2d
Binary files /dev/null and b/pandas/tests/io/data/stata/stata-compat-be-118.dta differ
diff --git a/pandas/tests/io/test_stata.py b/pandas/tests/io/test_stata.py
index 1bd71768d226e..1f7fe2399a4bc 100644
--- a/pandas/tests/io/test_stata.py
+++ b/pandas/tests/io/test_stata.py
@@ -1958,6 +1958,16 @@ def test_backward_compat(version, datapath):
     tm.assert_frame_equal(old_dta, expected, check_dtype=False)
 
 
+@pytest.mark.parametrize("version", [105, 108, 111, 113, 114, 118])
+def test_bigendian(version, datapath):
+    data_base = datapath("io", "data", "stata")
+    ref = os.path.join(data_base, f"stata-compat-{version}.dta")
+    big = os.path.join(data_base, f"stata-compat-be-{version}.dta")
+    expected = read_stata(ref)
+    big_dta = read_stata(big)
+    tm.assert_frame_equal(big_dta, expected)
+
+
 def test_direct_read(datapath, monkeypatch):
     file_path = datapath("io", "data", "stata", "stata-compat-118.dta")
 


Code review comments:
diff_hunk: @@ -1958,6 +1958,16 @@ def test_backward_compat(version, datapath):
     tm.assert_frame_equal(old_dta, expected, check_dtype=False)
 
 
+@pytest.mark.parametrize("version", [105, 108, 111, 113, 114, 118])
+def test_bigendian(version, datapath):
+    data_base = datapath("io", "data", "stata")
+    ref = os.path.join(data_base, f"stata-compat-{version}.dta")
+    big = os.path.join(data_base, f"stata-compat-be-{version}.dta")
path: pandas/tests/io/test_stata.py
text: @user1:
```suggestion
    ref = datapath("io", "data", "stata", f"stata-compat-{version}.dta")
    big = datapath("io", "data", "stata", f"stata-compat-be-{version}.dta")
```

@author:
I originally modelled the test function on `test_backward_compat`, but am happy with this suggested change.