Skip to content

Commit

Permalink
BUG: Remove incorrect check on value label length
Browse files Browse the repository at this point in the history
Remove 32,000 limit on value limit check since this applies
to the number of variable, not the length of the value labels

closes pandas-dev#60107
  • Loading branch information
bashtage committed Oct 31, 2024
1 parent 4bbb3ce commit c7282a0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ I/O
- Bug in :meth:`DataFrame.to_dict` raises unnecessary ``UserWarning`` when columns are not unique and ``orient='tight'``. (:issue:`58281`)
- Bug in :meth:`DataFrame.to_excel` when writing empty :class:`DataFrame` with :class:`MultiIndex` on both axes (:issue:`57696`)
- Bug in :meth:`DataFrame.to_stata` when writing :class:`DataFrame` and ``byteorder=`big```. (:issue:`58969`)
- Bug in :meth:`DataFrame.to_stata` when writing more than 32,000 value labels. (:issue:`60107`)
- Bug in :meth:`DataFrame.to_string` that raised ``StopIteration`` with nested DataFrames. (:issue:`16098`)
- Bug in :meth:`HDFStore.get` was failing to save data of dtype datetime64[s] correctly (:issue:`59004`)
- Bug in :meth:`read_csv` causing segmentation fault when ``encoding_errors`` is not a string. (:issue:`59059`)
Expand Down
6 changes: 0 additions & 6 deletions pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,12 +691,6 @@ def _prepare_value_labels(self) -> None:
self.txt.append(category)
self.n += 1

if self.text_len > 32000:
raise ValueError(
"Stata value labels for a single variable must "
"have a combined length less than 32,000 characters."
)

# Ensure int32
self.off = np.array(offsets, dtype=np.int32)
self.val = np.array(values, dtype=np.int32)
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/io/test_stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from datetime import datetime
import gzip
import io
import itertools
import os
import string
import struct
import tarfile
import zipfile
Expand Down Expand Up @@ -2592,3 +2594,12 @@ def test_empty_frame(temp_file):
df3 = read_stata(path, columns=["a"])
assert "b" not in df3
tm.assert_series_equal(df3.dtypes, dtypes.loc[["a"]])


@pytest.mark.parametrize("version", [114, 117, 118, 119, None])
def test_many_strl(temp_file, version):
n = 65534
df = DataFrame(np.arange(n), columns=["col"])
lbls = ["".join(v) for v in itertools.product(*([string.ascii_letters] * 3))]
value_labels = {"col": {i: lbls[i] for i in range(n)}}
df.to_stata(temp_file, value_labels=value_labels, version=version)

0 comments on commit c7282a0

Please sign in to comment.