8000 TST: centralize and standardize pandas imports by tacaswell · Pull Request #10124 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 3 commits into from
Jan 6, 2018

Conversation

tacaswell
Copy link
Member

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

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant

@tacaswell tacaswell added this to the v2.2 milestone Dec 29, 2017
@QuLogic
Copy link
Member
QuLogic commented Dec 29, 2017

A more pytest-y way would be with a fixture instead of a decorator, I think.

Copy link
Member
@dstansby dstansby left a 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

from pandas.tseries import converter
converter.register()
def _pandas_wrapper(func):
import functools
Copy link
Member

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
@tacaswell tacaswell force-pushed the tst_supress_pandas_warnings branch from e26dbf1 to e5f7982 Compare December 31, 2017 23:12
@tacaswell
Copy link
Member Author

Both comments addressed.

def test_pandas_pcolormesh():
@pytest.fixture
def pd(request):
'''fixuture to import and configure pandas'''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixture

register_matplotlib_converters as register)
except ImportError:
from pandas.tseries.converter import register
register()
Copy link
Member

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?

Copy link
Member Author

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.

from pandas.tseries import converter
converter.register()
def test_pandas_errorbar_indexing(pd):
import pandas as pd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra import.

from pandas.tseries import converter
converter.register()
def test_pandas_indexing_hist(pd):
import pandas as pd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra import.

pd = pytest.importorskip('pandas')
from pandas.tseries import converter
converter.register()
import pandas as pd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra import.

@tacaswell tacaswell force-pushed the tst_supress_pandas_warnings branch from 602d082 to 34ad36c Compare December 31, 2017 23:45
@tacaswell
Copy link
Member Author

Third times the charm?

try:
from pandas.plotting import (
deregister_matplotlib_converters as deregister)
request.addfinalizer(deregister)
Copy link
Contributor

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).

Copy link
Contributor

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

Copy link
Member Author

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.

@anntzer anntzer merged commit c5ed696 into matplotlib:master Jan 6, 2018
@tacaswell tacaswell deleted the tst_supress_pandas_warnings branch January 6, 2018 04:00
@anntzer anntzer mentioned this pull request Jan 6, 2018
6 tasks
@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0