-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH Change ExcelFile to accept a workbook for the path_or_buf argument. #4962
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
Conversation
It might make sense to add an |
with ensure_clean(pth) as pth: | ||
df.to_excel(pth, "SheetA") | ||
book = xlrd.open_workbook(pth) | ||
xl = ExcelFile(book) |
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.
maybe add a couple of lines using the sweet new context managing version of ExcelFile
too :)
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.
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.
with ExcelFile(book) as reader:
result = reader.parse("SheetA")
tm.assert_frame_equal(df, result)
# add a test that shows whether or not ExcelFile should be close the book or not
Also, I suggest doing this test twice, once with ExcelFile
and once with read_excel
(which won't work as a contextmanager)
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.
@jtratner Sure, will do. How do I use the contextmanager?
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.
all a contextmanager means is something you use in a with
statement.
@jtratner It seems to make sense to add the engine argument, et. al. in another PR. Thoughts? |
@cancan101 I was thinking that we would require passing an engine argument with a book, so that, if we were to add other engines going forward, we wouldn't have to try isinstance checks for determining which backend to use. So in other words you have |
@jtratner @cpcloud I pushed a change to test |
@cancan101 As different excel reading backends might have slightly different APIs for excel workbooks, then passing an |
yep, that's exactly what I mean (even though for right now it's all xlrd). Thanks for laying that out! |
I'll take a look soon. On Wed, Sep 25, 2013 at 7:33 PM, Alex Rothberg [email protected]:
|
ping! |
@cancan101 thanks for the ping. Apparently you need to rebase this too. (so sayeth github) |
@@ -254,6 +254,37 @@ def test_excel_read_buffer(self): | |||
f = open(pth, 'rb') | |||
xl = ExcelFile(f) | |||
xl.parse('Sheet1', index_col=0, parse_dates=True) | |||
|
|||
def test_excel_read_worksheet_excelfile(self): |
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.
Please change the name of this test to test_read_xlrd_Book(self)
- that's what your testing (and it makes it clearer that it only applies to xlrd).
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.
Should the next test, test_excel_read_worksheet_read_excel
be renamed to test_read_excel_xlrd_Book
?
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.
and as for test_read_xlrd_Book
, what about test_excel_file_xlrd_Book
?
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.
oh, can you just combine the two tests together? They aren't actually that different. (so you can just add two extra lines after 270 that have a call to read_excel
and another assert_frame_equal
call.
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.
Okay.
(formerly path_or_buf) argument; this requires engine to be set. (GH4961)
@jtratner Pushed. |
after this passes Travis I'll merge. |
ENH Change ExcelFile to accept a workbook for the path_or_buf argument.
That will also mean that read_excel accepts workbooks too. (closes #4961 and #4959)