Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
pd.read_stata('els_02_12_byf3pststu_v1_0.dta')
sr = pd.read_stata('els_02_12_byf3pststu_v1_0.dta', iterator=True)
sr.value_labels()['F3PSLSTART']
Issue Description
I'm getting the following error when reading the dataset, but could not find the corresponding problematic F3PSLSTART
column since sr.value_labels()['F3PSLSTART']
returns a KeyError
.
ValueError:
Value labels for column F3PSLSTART are not unique. These cannot be converted to
pandas categoricals.
Either read the file with `convert_categoricals` set to False or use the
low level interface in `StataReader` to separately read the values and the
value_labels.
The repeated labels are:
--------------------------------------------------------------------------------
Survey component legitimate skip/NA
Ddataset:
ELS_2002-12_PETS_v1_0_Student_Stata_Datasets.zip
The dataset is publicly available for download on this website:
https://nces.ed.gov/datalab/onlinecodebook/session/codebook/1c89f709-7ee6-4367-b0a1-6faca5a0a48b
Expected Behavior
I could find sr.value_labels()['F3PSLSTART']
Installed Versions
/opt/miniconda3/envs/experiment/lib/python3.10/site-packages/_distutils_hack/init.py:33: UserWarning: Setuptools is replacing distutils.
warnings.warn("Setuptools is replacing distutils.")
INSTALLED VERSIONS
commit : 0f43794
python : 3.10.11.final.0
python-bits : 64
OS : Darwin
OS-release : 22.5.0
Version : Darwin Kernel Version 22.5.0: Mon Apr 24 20:52:43 PDT 2023; root:xnu-8796.121.2~5/RELEASE_ARM64_T8112
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8
pandas : 2.0.3
numpy : 1.22.4
pytz : 2023.3
dateutil : 2.8.2
setuptools : 67.7.2
pip : 23.2.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.13.2
pandas_datareader: None
bs4 : 4.12.2
bottleneck : None
brotli :
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.7.1
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 11.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.10.1
snappy : None
sqlalchemy : None
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None