Skip to content

Commit 1aa6cd4

Browse files
committed
Merge pull request #11391 from jreback/slow
TST: make a couple of tests slow / remove some warnings
2 parents 84e2f31 + 0634ddf commit 1aa6cd4

17 files changed

+123
-101
lines changed

ci/requirements-2.7_SLOW.pip

Whitespace-only changes.

pandas/io/ga.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44
3. Goto APIs and register for OAuth2.0 for installed applications
55
4. Download JSON secret file and move into same directory as this file
66
"""
7-
8-
# GH11038
9-
import warnings
10-
warnings.warn("The pandas.io.ga module is deprecated and will be "
11-
"removed in a future version.",
12-
FutureWarning, stacklevel=2)
13-
147
from datetime import datetime
158
import re
169
from pandas import compat
@@ -27,6 +20,12 @@
2720
from oauth2client.client import AccessTokenRefreshError
2821
from pandas.compat import zip, u
2922

23+
# GH11038
24+
import warnings
25+
warnings.warn("The pandas.io.ga module is deprecated and will be "
26+
"removed in a future version.",
27+
FutureWarning, stacklevel=2)
28+
3029
TYPE_MAP = {u('INTEGER'): int, u('FLOAT'): float, u('TIME'): int}
3130

3231
NO_CALLBACK = auth.OOB_CALLBACK_URN

pandas/io/tests/test_data.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
import numpy as np
1010
import pandas as pd
1111
from pandas import DataFrame, Timestamp
12-
from pandas.io import data as web
13-
from pandas.io.data import DataReader, SymbolWarning, RemoteDataError, _yahoo_codes
1412
from pandas.util.testing import (assert_series_equal, assert_produces_warning,
1513
network, assert_frame_equal)
1614
import pandas.util.testing as tm
1715

16+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
17+
from pandas.io import data as web
18+
19+
from pandas.io.data import DataReader, SymbolWarning, RemoteDataError, _yahoo_codes
20+
1821
if compat.PY3:
1922
from urllib.error import HTTPError
2023
else:
@@ -293,6 +296,7 @@ def test_get_date_ret_index(self):
293296

294297

295298
class TestYahooOptions(tm.TestCase):
299+
296300
@classmethod
297301
def setUpClass(cls):
298302
super(TestYahooOptions, cls).setUpClass()

pandas/io/tests/test_excel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
from distutils.version import LooseVersion
88

9+
import warnings
910
import operator
1011
import functools
1112
import nose
@@ -1829,7 +1830,6 @@ def test_column_format(self):
18291830
# Applicable to xlsxwriter only.
18301831
_skip_if_no_xlsxwriter()
18311832

1832-
import warnings
18331833
with warnings.catch_warnings():
18341834
# Ignore the openpyxl lxml warning.
18351835
warnings.simplefilter("ignore")

pandas/io/tests/test_ga.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
from datetime import datetime
33

4+
import warnings
45
import nose
56
import pandas as pd
67
from pandas import compat
@@ -13,7 +14,12 @@
1314

1415
try:
1516
import httplib2
16-
import pandas.io.ga as ga
17+
import apiclient
18+
19+
# deprecated
20+
with warnings.catch_warnings(record=True):
21+
import pandas.io.ga as ga
22+
1723
from pandas.io.ga import GAnalytics, read_ga
1824
from pandas.io.auth import AuthenticationConfigError, reset_default_token_store
1925
from pandas.io import auth

pandas/io/tests/test_packers.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -461,20 +461,21 @@ def test_sparse_frame(self):
461461

462462
def test_sparse_panel(self):
463463

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

468-
self._check_roundtrip(sp, tm.assert_panel_equal,
469-
check_panel_type=True)
469+
self._check_roundtrip(sp, tm.assert_panel_equal,
470+
check_panel_type=True)
470471

471-
sp2 = p.to_sparse(kind='integer')
472-
self._check_roundtrip(sp2, tm.assert_panel_equal,
473-
check_panel_type=True)
472+
sp2 = p.to_sparse(kind='integer')
473+
self._check_roundtrip(sp2, tm.assert_panel_equal,
474+
check_panel_type=True)
474475

475-
sp3 = p.to_sparse(fill_value=0)
476-
self._check_roundtrip(sp3, tm.assert_panel_equal,
477-
check_panel_type=True)
476+
sp3 = p.to_sparse(fill_value=0)
477+
self._check_roundtrip(sp3, tm.assert_panel_equal,
478+
check_panel_type=True)
478479

479480

480481
class TestCompression(TestPackers):

pandas/io/tests/test_wb.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
from pandas.util.testing import network
66
from pandas.util.testing import assert_frame_equal
77
from numpy.testing.decorators import slow
8-
from pandas.io.wb import search, download, get_countries
98
import pandas.util.testing as tm
109

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

1214
class TestWB(tm.TestCase):
1315

pandas/rpy/tests/test_common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numpy as np
77
import unittest
88
import nose
9+
import warnings
910
import pandas.util.testing as tm
1011

1112
try:

pandas/sparse/array.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,15 @@ def __getitem__(self, key):
283283
if com.is_integer(key):
284284
return self._get_val_at(key)
285285
else:
286-
data_slice = self.values[key]
286+
if isinstance(key, SparseArray):
287+
key = np.asarray(key)
288+
if hasattr(key,'__len__') and len(self) != len(key):
289+
indices = self.sp_index
290+
if hasattr(indices,'to_int_index'):
291+
indices = indices.to_int_index()
292+
data_slice = self.values.take(indices.indices)[key]
293+
else:
294+
data_slice = self.values[key]
287295
return self._constructor(data_slice)
288296

289297
def __getslice__(self, i, j):
@@ -513,7 +521,12 @@ def make_sparse(arr, kind='block', fill_value=nan):
513521
else:
514522
mask = arr != fill_value
515523

516-
indices = np.arange(length, dtype=np.int32)[mask]
524+
length = len(arr)
525+
if length != mask.size:
526+
# the arr is a SparseArray
527+
indices = mask.sp_index.indices
528+
else:
529+
indices = np.arange(length, dtype=np.int32)[mask]
517530

518531
if kind == 'block':
519532
locs, lens = splib.get_blocks(indices)

pandas/stats/tests/test_moments.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ class TestMoments(Base):
4343

4444
def setUp(self):
4545
self._create_data()
46-
warnings.simplefilter("ignore", category=FutureWarning)
47-
48-
def tearDown(self):
49-
warnings.simplefilter("default", category=FutureWarning)
5046

5147
def test_centered_axis_validation(self):
5248
# ok
@@ -890,7 +886,6 @@ def _create_data(self):
890886

891887
def setUp(self):
892888
self._create_data()
893-
warnings.simplefilter("ignore", category=FutureWarning)
894889

895890
def _test_moments_consistency(self,
896891
min_periods,
@@ -1516,9 +1511,6 @@ def test_rolling_functions_window_non_shrinkage(self):
15161511

15171512
functions = [lambda x: mom.rolling_cov(x, x, pairwise=True, window=10, min_periods=5),
15181513
lambda x: mom.rolling_corr(x, x, pairwise=True, window=10, min_periods=5),
1519-
# rolling_corr_pairwise is depracated, so the following line should be deleted
1520-
# when rolling_corr_pairwise is removed.
1521-
lambda x: mom.rolling_corr_pairwise(x, x, window=10, min_periods=5),
15221514
]
15231515
for f in functions:
15241516
df_result_panel = f(df)
@@ -1585,9 +1577,6 @@ def test_moment_functions_zero_length(self):
15851577
lambda x: mom.expanding_corr(x, x, pairwise=True, min_periods=5),
15861578
lambda x: mom.rolling_cov(x, x, pairwise=True, window=10, min_periods=5),
15871579
lambda x: mom.rolling_corr(x, x, pairwise=True, window=10, min_periods=5),
1588-
# rolling_corr_pairwise is depracated, so the following line should be deleted
1589-
# when rolling_corr_pairwise is removed.
1590-
lambda x: mom.rolling_corr_pairwise(x, x, window=10, min_periods=5),
15911580
]
15921581
for f in functions:
15931582
df1_result_panel = f(df1)

pandas/tests/test_graphics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3169,6 +3169,7 @@ def test_pie_df_nan(self):
31693169
ax.get_legend().get_texts()],
31703170
base_expected[:i] + base_expected[i+1:])
31713171

3172+
@slow
31723173
def test_errorbar_plot(self):
31733174
d = {'x': np.arange(12), 'y': np.arange(12, 0, -1)}
31743175
df = DataFrame(d)

pandas/tests/test_groupby.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,7 @@ def check_nunique(df, keys):
16551655
check_nunique(frame, ['jim'])
16561656
check_nunique(frame, ['jim', 'joe'])
16571657

1658+
@slow
16581659
def test_series_groupby_value_counts(self):
16591660
from itertools import product
16601661

pandas/tests/test_indexing.py

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import pandas.util.testing as tm
2727
from pandas import date_range
28+
from numpy.testing.decorators import slow
2829

2930
_verbose = False
3031

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

1693+
@slow
16921694
def test_multiindex_get_loc(self): # GH7724, GH2646
16931695

1694-
# ignore the warning here
1695-
warnings.simplefilter('ignore', PerformanceWarning)
1696+
with warnings.catch_warnings(record=True):
16961697

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

1701-
def validate(mi, df, key):
1702-
mask = np.ones(len(df)).astype('bool')
1702+
def validate(mi, df, key):
1703+
mask = np.ones(len(df)).astype('bool')
17031704

1704-
# test for all partials of this key
1705-
for i, k in enumerate(key):
1706-
mask &= df.iloc[:, i] == k
1705+
# test for all partials of this key
1706+
for i, k in enumerate(key):
1707+
mask &= df.iloc[:, i] == k
17071708

1708-
if not mask.any():
1709-
self.assertNotIn(key[:i+1], mi.index)
1710-
continue
1711-
1712-
self.assertIn(key[:i+1], mi.index)
1713-
right = df[mask].copy()
1709+
if not mask.any():
1710+
self.assertNotIn(key[:i+1], mi.index)
1711+
continue
17141712

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

1720-
else: # full key
1721-
right.set_index(cols[:-1], inplace=True)
1722-
if len(right) == 1: # single hit
1723-
right = Series(right['jolia'].values,
1724-
name=right.index[0], index=['jolia'])
1725-
assert_series_equal(mi.loc[key[:i+1]], right)
1726-
else: # multi hit
1716+
if i + 1 != len(key): # partial key
1717+
right.drop(cols[:i+1], axis=1, inplace=True)
1718+
right.set_index(cols[i+1:-1], inplace=True)
17271719
assert_frame_equal(mi.loc[key[:i+1]], right)
17281720

1729-
def loop(mi, df, keys):
1730-
for key in keys:
1731-
validate(mi, df, key)
1732-
1733-
n, m = 1000, 50
1734-
1735-
vals = [randint(0, 10, n), choice(list('abcdefghij'), n),
1736-
choice(pd.date_range('20141009', periods=10).tolist(), n),
1737-
choice(list('ZYXWVUTSRQ'), n), randn(n)]
1738-
vals = list(map(tuple, zip(*vals)))
1739-
1740-
# bunch of keys for testing
1741-
keys = [randint(0, 11, m), choice(list('abcdefghijk'), m),
1742-
choice(pd.date_range('20141009', periods=11).tolist(), m),
1743-
choice(list('ZYXWVUTSRQP'), m)]
1744-
keys = list(map(tuple, zip(*keys)))
1745-
keys += list(map(lambda t: t[:-1], vals[::n//m]))
1746-
1747-
# covers both unique index and non-unique index
1748-
df = pd.DataFrame(vals, columns=cols)
1749-
a, b = pd.concat([df, df]), df.drop_duplicates(subset=cols[:-1])
1750-
1751-
for frame in a, b:
1752-
for i in range(5): # lexsort depth
1753-
df = frame.copy() if i == 0 else frame.sort_values(by=cols[:i])
1754-
mi = df.set_index(cols[:-1])
1755-
assert not mi.index.lexsort_depth < i
1756-
loop(mi, df, keys)
1757-
1758-
# restore
1759-
warnings.simplefilter('always', PerformanceWarning)
1721+
else: # full key
1722+
right.set_index(cols[:-1], inplace=True)
1723+
if len(right) == 1: # single hit
1724+
right = Series(right['jolia'].values,
1725+
name=right.index[0], index=['jolia'])
1726+
assert_series_equal(mi.loc[key[:i+1]], right)
1727+
else: # multi hit
1728+
assert_frame_equal(mi.loc[key[:i+1]], right)
1729+
1730+
def loop(mi, df, keys):
1731+
for key in keys:
1732+
validate(mi, df, key)
1733+
1734+
n, m = 1000, 50
1735+
1736+
vals = [randint(0, 10, n), choice(list('abcdefghij'), n),
1737+
choice(pd.date_range('20141009', periods=10).tolist(), n),
1738+
choice(list('ZYXWVUTSRQ'), n), randn(n)]
1739+
vals = list(map(tuple, zip(*vals)))
1740+
1741+
# bunch of keys for testing
1742+
keys = [randint(0, 11, m), choice(list('abcdefghijk'), m),
1743+
choice(pd.date_range('20141009', periods=11).tolist(), m),
1744+
choice(list('ZYXWVUTSRQP'), m)]
1745+
keys = list(map(tuple, zip(*keys)))
1746+
keys += list(map(lambda t: t[:-1], vals[::n//m]))
1747+
1748+
# covers both unique index and non-unique index
1749+
df = pd.DataFrame(vals, columns=cols)
1750+
a, b = pd.concat([df, df]), df.drop_duplicates(subset=cols[:-1])
1751+
1752+
for frame in a, b:
1753+
for i in range(5): # lexsort depth
1754+
df = frame.copy() if i == 0 else frame.sort_values(by=cols[:i])
1755+
mi = df.set_index(cols[:-1])
1756+
assert not mi.index.lexsort_depth < i
1757+
loop(mi, df, keys)
17601758

17611759
def test_series_getitem_multiindex(self):
17621760

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

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

4662+
@slow
46634663
def test_large_mi_dataframe_indexing(self):
46644664
#GH10645
46654665
result = MultiIndex.from_arrays([range(10**6), range(10**6)])

0 commit comments

Comments
 (0)