Skip to content
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

WIP: Cleanup pandas tests #741

Closed
wants to merge 15 commits into from
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ install:
- pip install coveralls

script:
# if we haven't installed pandas, don't use pytest to run tests
- if [[ $PANDAS == '0' ]]; then python -bb -m coverage run -p --source=pint --omit="*test*","*compat*" setup.py test; fi
# if we're doing the pandas tests and hence have pytest available, we can
# simply use it to run all the tests
# simply use pytest to run all the tests
- if [[ $PANDAS == '1' ]]; then python -bb -m coverage run -p --source=pint --omit="*test*","*compat*" -m py.test -rfsxEX; fi
# test notebooks too if pandas available
- if [[ $PANDAS == '1' ]]; then pip install -e .; pytest --nbval notebooks/*; fi
- if [[ $PANDAS == '0' ]]; then python -bb -m coverage run -p --source=pint --omit="*test*","*compat*","*pandas*" setup.py test; fi
- if [[ $PANDAS == '1' ]]; then pip install -e .; pytest --nbval notebooks/*.ipynb; fi
- coverage combine
- coverage report -m

Expand Down
4 changes: 4 additions & 0 deletions pint/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,14 @@ def _to_magnitude(value, force_ndarray=False):
# pin Pandas version for now
HAS_PROPER_PANDAS = pd.__version__.startswith("0.24.0.dev0+625.gbdb7a16")
except ImportError:

pd = None

HAS_PROPER_PANDAS = HAS_PANDAS = False

try:
import pytest
HAS_PYTEST = True
except ImportError:
pytest = None
HAS_PYTEST = False
4 changes: 2 additions & 2 deletions pint/pandas_interface/pint_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
:license: BSD, see LICENSE for more details.
"""

from pint.compat import HAS_PROPER_PANDAS
if not HAS_PROPER_PANDAS:
from pint.compat import pd
if pd is None:
error_msg = (
"The installed version of Pandas is not compatible with Pint, please check "
"the docs."
Expand Down
14 changes: 13 additions & 1 deletion pint/testsuite/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import re
import unittest

from pint.compat import HAS_NUMPY, HAS_PROPER_BABEL, HAS_UNCERTAINTIES, NUMPY_VER, PYTHON3
from pint.compat import HAS_NUMPY, HAS_PROPER_BABEL, HAS_UNCERTAINTIES, NUMPY_VER, PYTHON3, HAS_PROPER_PANDAS, HAS_PYTEST


def requires_numpy18():
Expand All @@ -31,6 +31,18 @@ def requires_not_numpy():
return unittest.skipIf(HAS_NUMPY, 'Requires NumPy is not installed.')


def requires_pandas():
return unittest.skipUnless(HAS_PROPER_PANDAS, 'Requires compatible Pandas')


def requires_not_pandas():
return unittest.skipIf(HAS_PROPER_PANDAS, 'Requires compatible Pandas is not installed')


def requires_pytest():
return unittest.skipUnless(HAS_PYTEST, 'Requires pytest')


def requires_proper_babel():
return unittest.skipUnless(HAS_PROPER_BABEL, 'Requires Babel with units support')

Expand Down
19 changes: 19 additions & 0 deletions pint/testsuite/pandas_interface/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import unittest

from pint.compat import pd, pytest

def setUpModule():
print("Hit setupmodule")
try:
import pint.pandas_interface as ppi
except:
if (pytest is None) and (pd is None):
missing_msg = (
"pytest and the right pandas version are not available, check the docs"
)
elif pytest is None:
missing_msg = "pytest is not available"
elif pd is None:
missing_msg = "the right pandas version is not available, check the docs"

raise unittest.SkipTest(missing_msg)
Loading