-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
TST: centralize and standardize pandas imports #10124
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: centralize and standardize pandas imports #10124
Conversation
A more pytest-y way would be with a fixture instead of a decorator, I think. |
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.
👍 apart from a small comment
lib/matplotlib/tests/test_axes.py
Outdated
from pandas.tseries import converter | ||
converter.register() | ||
def _pandas_wrapper(func): | ||
import functools |
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.
Could this get a one line comment along the lines of "Decorator for tests that use pandas"?
Added a decorator to handle: - importorskip - using the correct unit-handler registration function to deal with: - pandas not auto-registering - pandas moving an renaming the registration function
e26dbf1
to
e5f7982
Compare
Both comments addressed. |
lib/matplotlib/tests/test_axes.py
Outdated
def test_pandas_pcolormesh(): | ||
@pytest.fixture | ||
def pd(request): | ||
'''fixuture to import and configure pandas''' |
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.
fixture
lib/matplotlib/tests/test_axes.py
Outdated
register_matplotlib_converters as register) | ||
except ImportError: | ||
from pandas.tseries.converter import register | ||
register() |
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 you unregister after the test is run? Is that even possible? Or is it covered by the general reset fixture?
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.
For newer versions of pandas we can. Update coming.
lib/matplotlib/tests/test_axes.py
Outdated
from pandas.tseries import converter | ||
converter.register() | ||
def test_pandas_errorbar_indexing(pd): | ||
import pandas as pd |
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.
Extra import.
lib/matplotlib/tests/test_axes.py
Outdated
from pandas.tseries import converter | ||
converter.register() | ||
def test_pandas_indexing_hist(pd): | ||
import pandas as pd |
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.
Extra import.
lib/matplotlib/tests/test_axes.py
Outdated
pd = pytest.importorskip('pandas') | ||
from pandas.tseries import converter | ||
converter.register() | ||
import pandas as pd |
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.
Extra import.
602d082
to
34ad36c
Compare
Third times the charm? |
try: | ||
from pandas.plotting import ( | ||
deregister_matplotlib_converters as deregister) | ||
request.addfinalizer(deregister) |
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.
a yield fixture (in the style of a context manager) seems mildly more pythonic (https://docs.pytest.org/en/latest/fixture.html#fixture-finalization-executing-teardown-code).
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.
@tacaswell let us know if you want to make the change or I can make it in a separate pr 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.
@anntzer sorry, been traveling, feel free to push to this branch.
Added a decorator to handle:
PR Summary
PR Checklist