Skip to content

Commit 383c122

Browse files
committed
TST: Add a test to check order invariance
Check the label ordering does not cause any issues
1 parent 51dcc83 commit 383c122

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pandas/tests/io/test_stata.py

+14
Original file line numberDiff line numberDiff line change
@@ -1969,3 +1969,17 @@ def test_iterator_errors(dirpath):
19691969
with pytest.raises(ValueError, match="chunksize must be set to a positive"):
19701970
with StataReader(dta_file) as reader:
19711971
reader.__next__()
1972+
1973+
1974+
def test_iterator_value_labels():
1975+
# GH 31544
1976+
values = ["c_label", "b_label"] + ["a_label"] * 500
1977+
df = DataFrame({f"col{k}": pd.Categorical(values, ordered=True) for k in range(2)})
1978+
with tm.ensure_clean() as path:
1979+
df.to_stata(path, write_index=False)
1980+
reader = pd.read_stata(path, chunksize=100)
1981+
expected = pd.Index(["a_label", "b_label", "c_label"], dtype="object")
1982+
for j, chunk in enumerate(reader):
1983+
for i in range(2):
1984+
tm.assert_index_equal(chunk.dtypes[i].categories, expected)
1985+
tm.assert_frame_equal(chunk, df.iloc[j * 100 : (j + 1) * 100])

0 commit comments

Comments
 (0)