-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
allow path to be an StringIO object and skip extension check for that case #5992
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
Closed
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0fa3264
allow path to be an StringIO object and skip extension check for that…
00a2e16
add testcase for writing to a StringIO instance
fb57b12
s/ot/not
fd6e56c
correct patch as suggested
0cf194d
trying with byteio instead of stringio
1af3779
TST: fix test that repr returns str
dsm054 9b90af7
BUG: less false positives with SettingWithCopy (GH6025)
jreback b4968c2
Merge pull request #6040 from dsm054/fix-test-that-repr-returns-str
jreback 6044e92
Merge pull request #6044 from jreback/ix_list
jreback fcfaa7d
Merge pull request #6042 from jreback/setting_with_copy
jreback 6084109
allow path to be an file-like object
865be99
Merge branch 'master' of github.com:fennnec/pandas
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
import pandas.compat as compat | ||
import pandas.core.common as com | ||
from warnings import warn | ||
from StringIO import StringIO | ||
|
||
__all__ = ["read_excel", "ExcelWriter", "ExcelFile"] | ||
|
||
|
@@ -431,8 +432,9 @@ def save(self): | |
|
||
def __init__(self, path, engine=None, **engine_kwargs): | ||
# validate that this engine can handle the extnesion | ||
ext = os.path.splitext(path)[-1] | ||
self.check_extension(ext) | ||
if not isinstance(path, StringIO): | ||
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. thius should be |
||
ext = os.path.splitext(path)[-1] | ||
self.check_extension(ext) | ||
|
||
self.path = path | ||
self.sheets = {} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
) | ||
from pandas.util.testing import ensure_clean | ||
from pandas.core.config import set_option, get_option | ||
from StringIO import StringIO | ||
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. same here |
||
import pandas.util.testing as tm | ||
import pandas as pd | ||
|
||
|
@@ -410,6 +411,22 @@ def test_excelwriter_contextmanager(self): | |
tm.assert_frame_equal(found_df, self.frame) | ||
tm.assert_frame_equal(found_df2, self.frame2) | ||
|
||
def test_stringio_writer(self): | ||
_skip_if_no_xlsxwriter() | ||
_skip_if_no_xlrd() | ||
|
||
path = StringIO() | ||
with ExcelWriter(path, engine='xlsxwriter', **{'options': {'in-memory': True}}) as ew: | ||
self.frame.to_excel(ew, 'test1', engine='xlsxwriter') | ||
ew.save() | ||
path.seek(0) | ||
ef = ExcelFile(path) | ||
found_df = ef.parse('test1') | ||
tm.assert_frame_equal(self.frame, found_df) | ||
path.close() | ||
|
||
|
||
|
||
def test_roundtrip(self): | ||
_skip_if_no_xlrd() | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
you need to do: from pandas.compat import StringIO in order to pass python3