Skip to content

TST: make a couple of tests slow / remove some warnings #11391

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 5 commits into from
Oct 21, 2015
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
Empty file added ci/requirements-2.7_SLOW.pip
Empty file.
13 changes: 6 additions & 7 deletions pandas/io/ga.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
3. Goto APIs and register for OAuth2.0 for installed applications
4. Download JSON secret file and move into same directory as this file
"""

# GH11038
import warnings
warnings.warn("The pandas.io.ga module is deprecated and will be "
"removed in a future version.",
FutureWarning, stacklevel=2)

from datetime import datetime
import re
from pandas import compat
Expand All @@ -27,6 +20,12 @@
from oauth2client.client import AccessTokenRefreshError
from pandas.compat import zip, u

# GH11038
import warnings
warnings.warn("The pandas.io.ga module is deprecated and will be "
"removed in a future version.",
FutureWarning, stacklevel=2)

TYPE_MAP = {u('INTEGER'): int, u('FLOAT'): float, u('TIME'): int}

NO_CALLBACK = auth.OOB_CALLBACK_URN
Expand Down
8 changes: 6 additions & 2 deletions pandas/io/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
import numpy as np
import pandas as pd
from pandas import DataFrame, Timestamp
from pandas.io import data as web
from pandas.io.data import DataReader, SymbolWarning, RemoteDataError, _yahoo_codes
from pandas.util.testing import (assert_series_equal, assert_produces_warning,
network, assert_frame_equal)
import pandas.util.testing as tm

with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
from pandas.io import data as web

from pandas.io.data import DataReader, SymbolWarning, RemoteDataError, _yahoo_codes

if compat.PY3:
from urllib.error import HTTPError
else:
Expand Down Expand Up @@ -293,6 +296,7 @@ def test_get_date_ret_index(self):


class TestYahooOptions(tm.TestCase):

@classmethod
def setUpClass(cls):
super(TestYahooOptions, cls).setUpClass()
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/tests/test_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
from distutils.version import LooseVersion

import warnings
import operator
import functools
import nose
Expand Down Expand Up @@ -1829,7 +1830,6 @@ def test_column_format(self):
# Applicable to xlsxwriter only.
_skip_if_no_xlsxwriter()

import warnings
with warnings.catch_warnings():
# Ignore the openpyxl lxml warning.
warnings.simplefilter("ignore")
Expand Down
8 changes: 7 additions & 1 deletion pandas/io/tests/test_ga.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from datetime import datetime

import warnings
import nose
import pandas as pd
from pandas import compat
Expand All @@ -13,7 +14,12 @@

try:
import httplib2
import pandas.io.ga as ga
import apiclient

# deprecated
with warnings.catch_warnings(record=True):
import pandas.io.ga as ga

from pandas.io.ga import GAnalytics, read_ga
from pandas.io.auth import AuthenticationConfigError, reset_default_token_store
from pandas.io import auth
Expand Down
23 changes: 12 additions & 11 deletions pandas/io/tests/test_packers.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,20 +461,21 @@ def test_sparse_frame(self):

def test_sparse_panel(self):

items = ['x', 'y', 'z']
p = Panel(dict((i, tm.makeDataFrame().ix[:2, :2]) for i in items))
sp = p.to_sparse()
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
items = ['x', 'y', 'z']
p = Panel(dict((i, tm.makeDataFrame().ix[:2, :2]) for i in items))
sp = p.to_sparse()

self._check_roundtrip(sp, tm.assert_panel_equal,
check_panel_type=True)
self._check_roundtrip(sp, tm.assert_panel_equal,
check_panel_type=True)

sp2 = p.to_sparse(kind='integer')
self._check_roundtrip(sp2, tm.assert_panel_equal,
check_panel_type=True)
sp2 = p.to_sparse(kind='integer')
self._check_roundtrip(sp2, tm.assert_panel_equal,
check_panel_type=True)

sp3 = p.to_sparse(fill_value=0)
self._check_roundtrip(sp3, tm.assert_panel_equal,
check_panel_type=True)
sp3 = p.to_sparse(fill_value=0)
self._check_roundtrip(sp3, tm.assert_panel_equal,
check_panel_type=True)


class TestCompression(TestPackers):
Expand Down
4 changes: 3 additions & 1 deletion pandas/io/tests/test_wb.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
from pandas.util.testing import network
from pandas.util.testing import assert_frame_equal
from numpy.testing.decorators import slow
from pandas.io.wb import search, download, get_countries
import pandas.util.testing as tm

# deprecated
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
from pandas.io.wb import search, download, get_countries

class TestWB(tm.TestCase):

Expand Down
1 change: 1 addition & 0 deletions pandas/rpy/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np
import unittest
import nose
import warnings
import pandas.util.testing as tm

try:
Expand Down
17 changes: 15 additions & 2 deletions pandas/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,15 @@ def __getitem__(self, key):
if com.is_integer(key):
return self._get_val_at(key)
else:
data_slice = self.values[key]
if isinstance(key, SparseArray):
key = np.asarray(key)
if hasattr(key,'__len__') and len(self) != len(key):
indices = self.sp_index
if hasattr(indices,'to_int_index'):
indices = indices.to_int_index()
data_slice = self.values.take(indices.indices)[key]
else:
data_slice = self.values[key]
return self._constructor(data_slice)

def __getslice__(self, i, j):
Expand Down Expand Up @@ -513,7 +521,12 @@ def make_sparse(arr, kind='block', fill_value=nan):
else:
mask = arr != fill_value

indices = np.arange(length, dtype=np.int32)[mask]
length = len(arr)
if length != mask.size:
# the arr is a SparseArray
indices = mask.sp_index.indices
else:
indices = np.arange(length, dtype=np.int32)[mask]

if kind == 'block':
locs, lens = splib.get_blocks(indices)
Expand Down
11 changes: 0 additions & 11 deletions pandas/stats/tests/test_moments.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ class TestMoments(Base):

def setUp(self):
self._create_data()
warnings.simplefilter("ignore", category=FutureWarning)

def tearDown(self):
warnings.simplefilter("default", category=FutureWarning)

def test_centered_axis_validation(self):
# ok
Expand Down Expand Up @@ -890,7 +886,6 @@ def _create_data(self):

def setUp(self):
self._create_data()
warnings.simplefilter("ignore", category=FutureWarning)

def _test_moments_consistency(self,
min_periods,
Expand Down Expand Up @@ -1516,9 +1511,6 @@ def test_rolling_functions_window_non_shrinkage(self):

functions = [lambda x: mom.rolling_cov(x, x, pairwise=True, window=10, min_periods=5),
lambda x: mom.rolling_corr(x, x, pairwise=True, window=10, min_periods=5),
# rolling_corr_pairwise is depracated, so the following line should be deleted
# when rolling_corr_pairwise is removed.
lambda x: mom.rolling_corr_pairwise(x, x, window=10, min_periods=5),
]
for f in functions:
df_result_panel = f(df)
Expand Down Expand Up @@ -1585,9 +1577,6 @@ def test_moment_functions_zero_length(self):
lambda x: mom.expanding_corr(x, x, pairwise=True, min_periods=5),
lambda x: mom.rolling_cov(x, x, pairwise=True, window=10, min_periods=5),
lambda x: mom.rolling_corr(x, x, pairwise=True, window=10, min_periods=5),
# rolling_corr_pairwise is depracated, so the following line should be deleted
# when rolling_corr_pairwise is removed.
lambda x: mom.rolling_corr_pairwise(x, x, window=10, min_periods=5),
]
for f in functions:
df1_result_panel = f(df1)
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/test_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3169,6 +3169,7 @@ def test_pie_df_nan(self):
ax.get_legend().get_texts()],
base_expected[:i] + base_expected[i+1:])

@slow
def test_errorbar_plot(self):
d = {'x': np.arange(12), 'y': np.arange(12, 0, -1)}
df = DataFrame(d)
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,7 @@ def check_nunique(df, keys):
check_nunique(frame, ['jim'])
check_nunique(frame, ['jim', 'joe'])

@slow
def test_series_groupby_value_counts(self):
from itertools import product

Expand Down
116 changes: 58 additions & 58 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import pandas.util.testing as tm
from pandas import date_range
from numpy.testing.decorators import slow

_verbose = False

Expand Down Expand Up @@ -1689,74 +1690,71 @@ def test_multiindex_perf_warn(self):
with tm.assert_produces_warning(PerformanceWarning):
_ = df.loc[(0,)]

@slow
def test_multiindex_get_loc(self): # GH7724, GH2646

# ignore the warning here
warnings.simplefilter('ignore', PerformanceWarning)
with warnings.catch_warnings(record=True):

# test indexing into a multi-index before & past the lexsort depth
from numpy.random import randint, choice, randn
cols = ['jim', 'joe', 'jolie', 'joline', 'jolia']
# test indexing into a multi-index before & past the lexsort depth
from numpy.random import randint, choice, randn
cols = ['jim', 'joe', 'jolie', 'joline', 'jolia']

def validate(mi, df, key):
mask = np.ones(len(df)).astype('bool')
def validate(mi, df, key):
mask = np.ones(len(df)).astype('bool')

# test for all partials of this key
for i, k in enumerate(key):
mask &= df.iloc[:, i] == k
# test for all partials of this key
for i, k in enumerate(key):
mask &= df.iloc[:, i] == k

if not mask.any():
self.assertNotIn(key[:i+1], mi.index)
continue

self.assertIn(key[:i+1], mi.index)
right = df[mask].copy()
if not mask.any():
self.assertNotIn(key[:i+1], mi.index)
continue

if i + 1 != len(key): # partial key
right.drop(cols[:i+1], axis=1, inplace=True)
right.set_index(cols[i+1:-1], inplace=True)
assert_frame_equal(mi.loc[key[:i+1]], right)
self.assertIn(key[:i+1], mi.index)
right = df[mask].copy()

else: # full key
right.set_index(cols[:-1], inplace=True)
if len(right) == 1: # single hit
right = Series(right['jolia'].values,
name=right.index[0], index=['jolia'])
assert_series_equal(mi.loc[key[:i+1]], right)
else: # multi hit
if i + 1 != len(key): # partial key
right.drop(cols[:i+1], axis=1, inplace=True)
right.set_index(cols[i+1:-1], inplace=True)
assert_frame_equal(mi.loc[key[:i+1]], right)

def loop(mi, df, keys):
for key in keys:
validate(mi, df, key)

n, m = 1000, 50

vals = [randint(0, 10, n), choice(list('abcdefghij'), n),
choice(pd.date_range('20141009', periods=10).tolist(), n),
choice(list('ZYXWVUTSRQ'), n), randn(n)]
vals = list(map(tuple, zip(*vals)))

# bunch of keys for testing
keys = [randint(0, 11, m), choice(list('abcdefghijk'), m),
choice(pd.date_range('20141009', periods=11).tolist(), m),
choice(list('ZYXWVUTSRQP'), m)]
keys = list(map(tuple, zip(*keys)))
keys += list(map(lambda t: t[:-1], vals[::n//m]))

# covers both unique index and non-unique index
df = pd.DataFrame(vals, columns=cols)
a, b = pd.concat([df, df]), df.drop_duplicates(subset=cols[:-1])

for frame in a, b:
for i in range(5): # lexsort depth
df = frame.copy() if i == 0 else frame.sort_values(by=cols[:i])
mi = df.set_index(cols[:-1])
assert not mi.index.lexsort_depth < i
loop(mi, df, keys)

# restore
warnings.simplefilter('always', PerformanceWarning)
else: # full key
right.set_index(cols[:-1], inplace=True)
if len(right) == 1: # single hit
right = Series(right['jolia'].values,
name=right.index[0], index=['jolia'])
assert_series_equal(mi.loc[key[:i+1]], right)
else: # multi hit
assert_frame_equal(mi.loc[key[:i+1]], right)

def loop(mi, df, keys):
for key in keys:
validate(mi, df, key)

n, m = 1000, 50

vals = [randint(0, 10, n), choice(list('abcdefghij'), n),
choice(pd.date_range('20141009', periods=10).tolist(), n),
choice(list('ZYXWVUTSRQ'), n), randn(n)]
vals = list(map(tuple, zip(*vals)))

# bunch of keys for testing
keys = [randint(0, 11, m), choice(list('abcdefghijk'), m),
choice(pd.date_range('20141009', periods=11).tolist(), m),
choice(list('ZYXWVUTSRQP'), m)]
keys = list(map(tuple, zip(*keys)))
keys += list(map(lambda t: t[:-1], vals[::n//m]))

# covers both unique index and non-unique index
df = pd.DataFrame(vals, columns=cols)
a, b = pd.concat([df, df]), df.drop_duplicates(subset=cols[:-1])

for frame in a, b:
for i in range(5): # lexsort depth
df = frame.copy() if i == 0 else frame.sort_values(by=cols[:i])
mi = df.set_index(cols[:-1])
assert not mi.index.lexsort_depth < i
loop(mi, df, keys)

def test_series_getitem_multiindex(self):

Expand Down Expand Up @@ -4653,13 +4651,15 @@ def test_indexing_dtypes_on_empty(self):
assert_series_equal(df2.loc[:,'a'], df2.iloc[:,0])
assert_series_equal(df2.loc[:,'a'], df2.ix[:,0])

@slow
def test_large_dataframe_indexing(self):
#GH10692
result = DataFrame({'x': range(10**6)},dtype='int64')
result.loc[len(result)] = len(result) + 1
expected = DataFrame({'x': range(10**6 + 1)},dtype='int64')
assert_frame_equal(result, expected)

@slow
def test_large_mi_dataframe_indexing(self):
#GH10645
result = MultiIndex.from_arrays([range(10**6), range(10**6)])
Expand Down
Loading