Skip to content
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

BUGFIX - AttributeError raised in StataReader.value_labels() #19510

Merged
merged 3 commits into from
Feb 6, 2018

Conversation

miker985
Copy link
Contributor

@miker985 miker985 commented Feb 2, 2018

Returns empty dict instead of raising AttributeError for very old Stata files. Includes test against very old Stata file.

@codecov
Copy link

codecov bot commented Feb 2, 2018

Codecov Report

Merging #19510 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #19510   +/-   ##
=======================================
  Coverage    91.6%    91.6%           
=======================================
  Files         150      150           
  Lines       48750    48750           
=======================================
  Hits        44657    44657           
  Misses       4093     4093
Flag Coverage Δ
#multiple 89.97% <ø> (ø) ⬆️
#single 41.75% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 672f5a1...ea8d107. Read the comment docs.

@@ -530,6 +530,8 @@ I/O
- Bug in :func:`DataFrame.to_parquet` where an exception was raised if the write destination is S3 (:issue:`19134`)
- :class:`Interval` now supported in :func:`DataFrame.to_excel` for all Excel file types (:issue:`19242`)
- :class:`Timedelta` now supported in :func:`DataFrame.to_excel` for xls file type (:issue:`19242`, :issue:`9155`)
- Bug in :class:`pandas.io.stata.StataReader` raising ``AttributeError`` when ``value_labels()`` called with very old files. Now returns an empty dict (:issue:`19417`)
Copy link
Contributor

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 have StataReader.value_labels. So could you reword this as

- Bug in :meth:`pandas.io.stata.StataReader.value_labels` raising an ``AttributeError`` when called on very old files. Now returns an empty dict (:issue:`19417`)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

# 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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

close()d

@jreback jreback added Bug IO Stata read_stata, to_stata labels Feb 4, 2018
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()
Copy link
Contributor

Choose a reason for hiding this comment

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

Was there a preference stated recently to use {} rather than dict()?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah can use {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

dict() is internally consistent with the function.

@jreback jreback added this to the 0.23.0 milestone Feb 6, 2018
@jreback
Copy link
Contributor

jreback commented Feb 6, 2018

lgtm. rebasing, ping when green.

@jreback jreback merged commit 93c86aa into pandas-dev:master Feb 6, 2018
@jreback
Copy link
Contributor

jreback commented Feb 6, 2018

thanks!

harisbal pushed a commit to harisbal/pandas that referenced this pull request Feb 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO Stata read_stata, to_stata
Projects
None yet
Development

Successfully merging this pull request may close these issues.

value_labels fails to assign value_label_dict, leads to AttributeError
4 participants