Skip to content

Clarified error in read_sas method when buffer object provided withou… #14947

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

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ Performance Improvements
- Improved performance of ``pd.wide_to_long()`` (:issue:`14779`)
- Increased performance of ``pd.factorize()`` by releasing the GIL with ``object`` dtype when inferred as strings (:issue:`14859`)

- When reading buffer object in ``read_sas()`` method without specified format, filepath string is inferred rather than buffer object.
Copy link
Contributor

@jreback jreback Dec 31, 2016

Choose a reason for hiding this comment

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

Bug when reading a buffer object in pd.read_sas(), without a specified format, a filepath string was inferred rather than buffer object.

move to Bug Fix section, add the issue number (this PR) at the end



.. _whatsnew_0200.bug_fixes:
Expand Down
5 changes: 4 additions & 1 deletion pandas/io/sas/sasreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ def read_sas(filepath_or_buffer, format=None, index=None, encoding=None,
DataFrame if iterator=False and chunksize=None, else SAS7BDATReader
or XportReader
"""

from pandas import compat
Copy link
Contributor

Choose a reason for hiding this comment

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

import should be at the top of the file (if might be there already)

if format is None:
buffErr = "Format unrecognized. If buffer object, specify format"
Copy link
Contributor

Choose a reason for hiding this comment

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

use buffer_error_msg.

If this is a buffer object, rather than a string name, you must specify a format string.

if not isinstance(filepath_or_buffer,compat.string_types):
Copy link
Member

Choose a reason for hiding this comment

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

You have some PEP8 errors (we check for them in the travis build, that is the reason travis failed). For example, here there should be a space after the comma.

Here is the full list (you can find it at the bottom of the failing test (third travis build), but I also recommend setting up your IDE to check for this):

pandas/io/sas/sasreader.py:6:1: E302 expected 2 blank lines, found 1
pandas/io/sas/sasreader.py:35:45: E231 missing whitespace after ','
pandas/io/tests/sas/test_sas.py:5:1: E302 expected 2 blank lines, found 1

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 think I got this covered. I'll reread the Pandas submission info for how to ensure PEP8 compliance tonight.

raise TypeError(buffErr)
try:
fname = filepath_or_buffer.lower()
if fname.endswith(".xpt"):
Expand Down
9 changes: 9 additions & 0 deletions pandas/io/tests/sas/test_sas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pandas.util.testing as tm

class TestSasBuff(tm.TestCase):
Copy link
Member

Choose a reason for hiding this comment

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

You can call this just TestSas (and there needs to be a blank line after this one)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

def test_sas_buffer_format(self):
import StringIO
Copy link
Contributor

Choose a reason for hiding this comment

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

imports go at the top

from pandas.io.sas.sasreader import read_sas
b = StringIO.StringIO("")
Copy link
Contributor

Choose a reason for hiding this comment

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

from pandas import read_sas

Copy link
Contributor

Choose a reason for hiding this comment

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

from pandas.compat import StringIO

with self.assertRaises(TypeError):
read_sas(b)