-
Notifications
You must be signed in to change notification settings - Fork 26
BUG A file-like object as arg to df.to_csv must have the method getvalue #259
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
BUG A file-like object as arg to df.to_csv must have the method getvalue #259
Conversation
We need a file-like object with the `getvalue` method (yes for StringIO, no for TextIOWrapper). Otherwise when passing a file-like obj to pandas v0.23.1 df.to_csv, the lack of the getvalue method raises an error.
AppVeyor has been turned on, but obviously there's no AppVeyor configuration yet (upcoming from #258) and hence the relevant build "failure", which should be ignored for this PR. |
@@ -173,7 +173,7 @@ def test_stash_local_data_from_dataframe_csv(mock_file): | |||
assert _model._stash_dataframe_as_csv(df, mock.Mock()) == -11 | |||
mock_file.assert_called_once_with(mock.ANY, name='modelpipeline_data.csv', | |||
client=mock.ANY) | |||
assert isinstance(mock_file.call_args[0][0], BytesIO) | |||
assert isinstance(mock_file.call_args[0][0], StringIO) |
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.
Shouldn't this fail in the Python27 tests? That is, won't this be a BytesIO
object for Python27?
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.
Good question! Behold --
Python 2.7, six 1.11.0:
In [2]: from six import StringIO, BytesIO
In [3]: s = StringIO()
In [4]: b = BytesIO()
In [5]: isinstance(s, StringIO)
Out[5]: True
In [6]: isinstance(s, BytesIO)
Out[6]: True
In [7]: isinstance(b, StringIO) # This is why we didn't get the expected failure?
Out[7]: True
In [8]: isinstance(b, BytesIO)
Out[8]: True
Python 3.6, six 1.11.0 (where everything makes sense to me):
In [1]: from six import StringIO, BytesIO
In [2]: s = StringIO()
In [3]: b = BytesIO()
In [4]: isinstance(s, StringIO)
Out[4]: True
In [5]: isinstance(s, BytesIO)
Out[5]: False
In [6]: isinstance(b, StringIO)
Out[6]: False
In [7]: isinstance(b, BytesIO)
Out[7]: True
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.
Huh. Thanks for looking into that.
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.
I think the test passes because of https://github.com/benjaminp/six/blob/1.11.0/six.py#L664 . Given that equality, do we need the if six.PY3
conditional?
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.
Good point! Although I don't have a problem merging as is, either.
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.
LGTM except the single question.
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.
LGTM! Thank you for catching this error and fixing it!
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.
LGTM
Since
pandas
v0.23.1 (specifically from pandas-dev/pandas#21300), if a file-like object is passed intodf.to_csv
, the object must have the methodgetvalue
, or else anAttributeError
is raised (which is what we have observed from #258). Anio.TextIOWrapper
object doesn't have the methodgetvalue
, which caused the latest build failures in #258. This PR switches toio.StringIO
instead.