Skip to content

TST/CLN: centralize module check funcs #7451

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 1 commit into from
Jun 21, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions pandas/stats/tests/test_moments.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@

N, K = 100, 10

def _skip_if_no_scipy():
try:
import scipy.stats
except ImportError:
raise nose.SkipTest("no scipy.stats")

class TestMoments(tm.TestCase):

Expand Down Expand Up @@ -68,7 +63,7 @@ def test_rolling_mean(self):
self._check_moment_func(mom.rolling_mean, np.mean)

def test_cmov_mean(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
try:
from scikits.timeseries.lib import cmov_mean
except ImportError:
Expand All @@ -86,7 +81,7 @@ def test_cmov_mean(self):
assert_series_equal(xp, rs)

def test_cmov_window(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
try:
from scikits.timeseries.lib import cmov_window
except ImportError:
Expand All @@ -104,7 +99,7 @@ def test_cmov_window(self):
assert_series_equal(xp, rs)

def test_cmov_window_corner(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
try:
from scikits.timeseries.lib import cmov_window
except ImportError:
Expand All @@ -128,7 +123,7 @@ def test_cmov_window_corner(self):
self.assertEqual(len(rs), 5)

def test_cmov_window_frame(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
try:
from scikits.timeseries.lib import cmov_window
except ImportError:
Expand All @@ -141,7 +136,7 @@ def test_cmov_window_frame(self):
assert_frame_equal(DataFrame(xp), rs)

def test_cmov_window_na_min_periods(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
try:
from scikits.timeseries.lib import cmov_window
except ImportError:
Expand All @@ -158,7 +153,7 @@ def test_cmov_window_na_min_periods(self):
assert_series_equal(xp, rs)

def test_cmov_window_regular(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
try:
from scikits.timeseries.lib import cmov_window
except ImportError:
Expand All @@ -174,7 +169,7 @@ def test_cmov_window_regular(self):
assert_series_equal(Series(xp), rs)

def test_cmov_window_special(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
try:
from scikits.timeseries.lib import cmov_window
except ImportError:
Expand Down
16 changes: 2 additions & 14 deletions pandas/tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,6 @@ def skip_if_np_version_under1p7():

raise nose.SkipTest('numpy >= 1.7 required')

def _skip_if_no_pytz():
try:
import pytz
except ImportError:
raise nose.SkipTest("pytz not installed")

def _skip_if_no_dateutil():
try:
import dateutil
except ImportError:
raise nose.SkipTest("dateutil not installed")


class TestDataFrameFormatting(tm.TestCase):
_multiprocess_can_split_ = True
Expand Down Expand Up @@ -2930,7 +2918,7 @@ def test_no_tz(self):
self.assertEqual(str(ts_nanos_micros), "1970-01-01 00:00:00.000001200")

def test_tz_pytz(self):
_skip_if_no_pytz()
tm._skip_if_no_pytz()

import pytz

Expand All @@ -2944,7 +2932,7 @@ def test_tz_pytz(self):
self.assertEqual(str(dt_datetime_us), str(Timestamp(dt_datetime_us)))

def test_tz_dateutil(self):
_skip_if_no_dateutil()
tm._skip_if_no_dateutil()
import dateutil
utc = dateutil.tz.tzutc()

Expand Down
26 changes: 10 additions & 16 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@

from numpy.testing.decorators import slow

def _skip_if_no_scipy():
try:
import scipy.stats
except ImportError:
raise nose.SkipTest("no scipy.stats module")

#---------------------------------------------------------------------
# DataFrame test cases

Expand Down Expand Up @@ -6739,28 +6733,28 @@ def _check_method(self, method='pearson', check_minp=False):
expected.ix['A', 'B'] = expected.ix['B', 'A'] = nan

def test_corr_pearson(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
self.frame['A'][:5] = nan
self.frame['B'][5:10] = nan

self._check_method('pearson')

def test_corr_kendall(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
self.frame['A'][:5] = nan
self.frame['B'][5:10] = nan

self._check_method('kendall')

def test_corr_spearman(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
self.frame['A'][:5] = nan
self.frame['B'][5:10] = nan

self._check_method('spearman')

def test_corr_non_numeric(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
self.frame['A'][:5] = nan
self.frame['B'][5:10] = nan

Expand All @@ -6770,7 +6764,7 @@ def test_corr_non_numeric(self):
assert_frame_equal(result, expected)

def test_corr_nooverlap(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()

# nothing in common
for meth in ['pearson', 'kendall', 'spearman']:
Expand All @@ -6783,7 +6777,7 @@ def test_corr_nooverlap(self):
self.assertEqual(rs.ix['B', 'B'], 1)

def test_corr_constant(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()

# constant --> all NA

Expand Down Expand Up @@ -10957,7 +10951,7 @@ def test_sem(self):
nanops._USE_BOTTLENECK = True

def test_skew(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
from scipy.stats import skew

def alt(x):
Expand All @@ -10968,7 +10962,7 @@ def alt(x):
self._check_stat_op('skew', alt)

def test_kurt(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()

from scipy.stats import kurtosis

Expand Down Expand Up @@ -11320,7 +11314,7 @@ def test_cumprod(self):
df.cumprod(1)

def test_rank(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
from scipy.stats import rankdata

self.frame['A'][::2] = np.nan
Expand Down Expand Up @@ -11412,7 +11406,7 @@ def test_rank2(self):
assert_frame_equal(df.rank(), exp)

def test_rank_na_option(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
from scipy.stats import rankdata

self.frame['A'][::2] = np.nan
Expand Down
40 changes: 15 additions & 25 deletions pandas/tests/test_generic.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
# pylint: disable-msg=E1101,W0612

from datetime import datetime, timedelta
import operator
import nose
import copy
import numpy as np
from numpy import nan
import pandas as pd

from pandas import (Index, Series, DataFrame, Panel,
isnull, notnull,date_range, _np_version_under1p7)
from pandas.core.index import Index, MultiIndex
from pandas.tseries.index import Timestamp, DatetimeIndex

import pandas.core.common as com

Expand All @@ -25,13 +22,6 @@
import pandas.util.testing as tm


def _skip_if_no_scipy():
try:
import scipy.interpolate
except ImportError:
raise nose.SkipTest('scipy.interpolate missing')


def _skip_if_no_pchip():
try:
from scipy.interpolate import pchip_interpolate
Expand Down Expand Up @@ -491,7 +481,7 @@ def test_interpolate(self):
self.assertRaises(ValueError, non_ts.interpolate, method='time')

def test_interp_regression(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
_skip_if_no_pchip()

ser = Series(np.sort(np.random.uniform(size=100)))
Expand All @@ -509,7 +499,7 @@ def test_interpolate_corners(self):
s = Series([]).interpolate()
assert_series_equal(s.interpolate(), s)

_skip_if_no_scipy()
tm._skip_if_no_scipy()
s = Series([np.nan, np.nan])
assert_series_equal(s.interpolate(method='polynomial', order=1), s)

Expand Down Expand Up @@ -544,7 +534,7 @@ def test_nan_interpolate(self):
expected = Series([0., 1., 2., 3.])
assert_series_equal(result, expected)

_skip_if_no_scipy()
tm._skip_if_no_scipy()
result = s.interpolate(method='polynomial', order=1)
assert_series_equal(result, expected)

Expand All @@ -561,14 +551,14 @@ def test_nan_str_index(self):
assert_series_equal(result, expected)

def test_interp_quad(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
sq = Series([1, 4, np.nan, 16], index=[1, 2, 3, 4])
result = sq.interpolate(method='quadratic')
expected = Series([1., 4., 9., 16.], index=[1, 2, 3, 4])
assert_series_equal(result, expected)

def test_interp_scipy_basic(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
s = Series([1, 3, np.nan, 12, np.nan, 25])
# slinear
expected = Series([1., 3., 7.5, 12., 18.5, 25.])
Expand Down Expand Up @@ -611,7 +601,7 @@ def test_interp_limit(self):

def test_interp_all_good(self):
# scipy
_skip_if_no_scipy()
tm._skip_if_no_scipy()
s = Series([1, 2, 3])
result = s.interpolate(method='polynomial', order=1)
assert_series_equal(result, s)
Expand All @@ -629,18 +619,18 @@ def test_interp_multiIndex(self):
result = s.interpolate()
assert_series_equal(result, expected)

_skip_if_no_scipy()
tm._skip_if_no_scipy()
with tm.assertRaises(ValueError):
s.interpolate(method='polynomial', order=1)

def test_interp_nonmono_raise(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
s = Series([1, np.nan, 3], index=[0, 2, 1])
with tm.assertRaises(ValueError):
s.interpolate(method='krogh')

def test_interp_datetime64(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
df = Series([1, np.nan, 3], index=date_range('1/1/2000', periods=3))
result = df.interpolate(method='nearest')
expected = Series([1., 1., 3.], index=date_range('1/1/2000', periods=3))
Expand Down Expand Up @@ -768,7 +758,7 @@ def test_interp_nan_idx(self):
df.interpolate(method='values')

def test_interp_various(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
df = DataFrame({'A': [1, 2, np.nan, 4, 5, np.nan, 7],
'C': [1, 2, 3, 5, 8, 13, 21]})
df = df.set_index('C')
Expand Down Expand Up @@ -810,7 +800,7 @@ def test_interp_various(self):
assert_frame_equal(result, expected)

def test_interp_alt_scipy(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
df = DataFrame({'A': [1, 2, np.nan, 4, 5, np.nan, 7],
'C': [1, 2, 3, 5, 8, 13, 21]})
result = df.interpolate(method='barycentric')
Expand Down Expand Up @@ -850,7 +840,7 @@ def test_interp_rowwise(self):
assert_frame_equal(result, expected)

# scipy route
_skip_if_no_scipy()
tm._skip_if_no_scipy()
result = df.interpolate(axis=1, method='values')
assert_frame_equal(result, expected)

Expand All @@ -871,7 +861,7 @@ def test_interp_leading_nans(self):
expected['B'].loc[3] = -3.75
assert_frame_equal(result, expected)

_skip_if_no_scipy()
tm._skip_if_no_scipy()
result = df.interpolate(method='polynomial', order=1)
assert_frame_equal(result, expected)

Expand Down Expand Up @@ -1022,15 +1012,15 @@ def test_describe_objects(self):
assert_frame_equal(df[['C2', 'C3']].describe(), df[['C3']].describe())

def test_no_order(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
s = Series([0, 1, np.nan, 3])
with tm.assertRaises(ValueError):
s.interpolate(method='polynomial')
with tm.assertRaises(ValueError):
s.interpolate(method='spline')

def test_spline(self):
_skip_if_no_scipy()
tm._skip_if_no_scipy()
s = Series([1, 2, np.nan, 4, 5, np.nan, 7])
result = s.interpolate(method='spline', order=1)
expected = Series([1., 2., 3., 4., 5., 6., 7.])
Expand Down
Loading