-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUGFIX - AttributeError raised in StataReader.value_labels() #19510
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1341,12 +1341,14 @@ def _null_terminate(self, s): | |
return s | ||
|
||
def _read_value_labels(self): | ||
if self.format_version <= 108: | ||
# Value labels are not supported in version 108 and earlier. | ||
return | ||
if self._value_labels_read: | ||
# Don't read twice | ||
return | ||
if self.format_version <= 108: | ||
# Value labels are not supported in version 108 and earlier. | ||
self._value_labels_read = True | ||
self.value_label_dict = dict() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was there a preference stated recently to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return | ||
|
||
if self.format_version >= 117: | ||
self.path_or_buf.seek(self.seek_value_labels) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -589,6 +589,15 @@ def test_105(self): | |
df0['psch_dis'] = df0["psch_dis"].astype(np.float32) | ||
tm.assert_frame_equal(df.head(3), df0) | ||
|
||
def test_value_labels_old_format(self): | ||
# GH 19417 | ||
# | ||
# Test that value_labels() returns an empty dict if the file format | ||
# predates supporting value labels. | ||
dpath = os.path.join(self.dirpath, 'S4_EDUC1.dta') | ||
reader = StataReader(dpath) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to close the reader (or do this in a context manager) see other tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
assert reader.value_labels() == {} | ||
|
||
def test_date_export_formats(self): | ||
columns = ['tc', 'td', 'tw', 'tm', 'tq', 'th', 'ty'] | ||
conversions = {c: c for c in columns} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have an entry for
StataReader
in the API docs, but we do haveStataReader.value_labels
. So could you reword this asThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed