-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
TST: Decoupled more xlrd reading tests from openpyxl #27114
Conversation
func = partial(pd.ExcelFile, engine=request.param) | ||
monkeypatch.chdir(datapath("io", "data")) | ||
monkeypatch.setattr(pd, 'ExcelFile', func) | ||
|
||
def test_excel_passes_na(self, read_ext): | ||
|
||
excel = ExcelFile('test4' + read_ext) | ||
excel = pd.ExcelFile('test4' + read_ext) |
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.
We were monkeypatching pd.ExcelFile
but used ExcelFile
imported directly in tests which was causing this to run exclusive of the specified engine. Figured easiest just to stick with the pd namespace
|
||
parsed = pd.read_excel(excel, 'Sheet1', keep_default_na=False, | ||
na_values=['apple']) | ||
expected = DataFrame([['NA'], [1], ['NA'], [np.nan], ['rabbit']], | ||
columns=['Test']) | ||
tm.assert_frame_equal(parsed, expected) | ||
|
||
excel = pd.ExcelFile('test4' + read_ext) |
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.
openpyxl seems to exhaust a pd.ExcelFile
after reading whereas xlrd does not. I don't think we really have a preference here and I can't imagine that the xlrd behavior is necessarily required so just created a new pd.ExcelFile after each use
pytest.param(None, marks=pytest.mark.skipif( | ||
not td.safe_import("xlrd"), reason="no xlrd")), | ||
]) | ||
def test_conflicting_excel_engines(read_ext, excel_engine, datapath): |
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.
This didn't really follow the same rules for parametrization as the rest of the items in TestExcelFileRead
so figured clearest to remove from class
@@ -778,7 +782,7 @@ def test_excel_passes_na(self, read_ext): | |||
@pytest.mark.parametrize('arg', ['sheet', 'sheetname', 'parse_cols']) | |||
def test_unexpected_kwargs_raises(self, read_ext, arg): | |||
# gh-17964 | |||
excel = ExcelFile('test1' + read_ext) | |||
excel = pd.ExcelFile('test1' + read_ext) |
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.
do we normally need to close the file? use in a context manager?
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.
It looks like it depends on what type of object ExcelFile is interacting with but ultimately converted usage to a context manager to be safe
@@ -250,6 +250,7 @@ class and any subclasses, on account of the `autouse=True` | |||
set_option(option_name, prev_engine) # Roll back option change | |||
|
|||
|
|||
@td.skip_if_no('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.
The writer tests still assume xlrd to be there. Will fix up in a follow up to address proper parametrization here (have focused more on readers given recent PRs)
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.
Tests pass now locally without having xlrd installed!
This PR results in an additional 2 warnings. although 8 of the same were introduced in #25092.
|
@simonjayhawkins that should be solved by #27122 |
git diff upstream/master -u -- "*.py" | flake8 --diff
@simonjayhawkins