Skip to content

ENH: Add support for reading value labels from 108-format and prior Stata dta files #58155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1580,13 +1580,13 @@ def _read_value_labels(self) -> None:
# Don't read twice
return

self._value_labels_read = True
self._value_label_dict: dict[str, dict[int, str]] = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps one last one. Should this be moved to the __init__? I prefer to declare all attributes there since it avoids late addition of attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now moved this up as suggested. I put it in the # State variables for the file section as this seemed the closest fit, but can shift it around it you like.


if self._format_version >= 108:
self._read_new_value_labels()
else:
self._read_old_value_labels()
self._value_labels_read = True

def _read_strls(self) -> None:
self._path_or_buf.seek(self._seek_strls)
Expand Down