From b74c420e6aea1d70ef25300417d554db4003fe6a Mon Sep 17 00:00:00 2001 From: jreback Date: Mon, 25 Nov 2013 09:01:43 -0500 Subject: [PATCH 1/4] BUG: reset setitem_copy on object enlargement TST: eliminate SettingWithCopyWarnings in tests (catch them) TST: tests for GH5597 BUG: don't set copy on equal indexes after an operation --- pandas/core/frame.py | 6 ++-- pandas/core/generic.py | 18 +++++++---- pandas/core/indexing.py | 1 + pandas/tests/test_index.py | 2 ++ pandas/tests/test_indexing.py | 57 +++++++++++++++++++++++++++++++++-- 5 files changed, 73 insertions(+), 11 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 5d658410a0e32..6ef6d8c75216f 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1563,7 +1563,7 @@ def _ixs(self, i, axis=0, copy=False): # a location index by definition i = _maybe_convert_indices(i, len(self._get_axis(axis))) - return self.reindex(i, takeable=True) + return self.reindex(i, takeable=True)._setitem_copy(True) else: new_values, copy = self._data.fast_2d_xs(i, copy=copy) return Series(new_values, index=self.columns, @@ -2714,7 +2714,7 @@ def trans(v): self._clear_item_cache() else: - return self.take(indexer, axis=axis, convert=False) + return self.take(indexer, axis=axis, convert=False, is_copy=False) def sortlevel(self, level=0, axis=0, ascending=True, inplace=False): """ @@ -2760,7 +2760,7 @@ def sortlevel(self, level=0, axis=0, ascending=True, inplace=False): self._clear_item_cache() else: - return self.take(indexer, axis=axis, convert=False) + return self.take(indexer, axis=axis, convert=False, is_copy=False) def swaplevel(self, i, j, axis=0): """ diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 5ab5e9063a2c5..f3097a616ff95 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1064,7 +1064,7 @@ def __delitem__(self, key): except KeyError: pass - def take(self, indices, axis=0, convert=True): + def take(self, indices, axis=0, convert=True, is_copy=True): """ Analogous to ndarray.take @@ -1073,6 +1073,7 @@ def take(self, indices, axis=0, convert=True): indices : list / array of ints axis : int, default 0 convert : translate neg to pos indices (default) + is_copy : mark the returned frame as a copy Returns ------- @@ -1090,12 +1091,17 @@ def take(self, indices, axis=0, convert=True): labels = self._get_axis(axis) new_items = labels.take(indices) new_data = self._data.reindex_axis(new_items, indexer=indices, - axis=0) + axis=baxis) else: - new_data = self._data.take(indices, axis=baxis, verify=convert) - return self._constructor(new_data)\ - ._setitem_copy(True)\ - .__finalize__(self) + new_data = self._data.take(indices, axis=baxis) + + result = self._constructor(new_data).__finalize__(self) + + # maybe set copy if we didn't actually change the index + if is_copy and not result._get_axis(axis).equals(self._get_axis(axis)): + result = result._setitem_copy(is_copy) + + return result # TODO: Check if this was clearer in 0.12 def select(self, crit, axis=0): diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index a258135597078..08f935539ecfc 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -209,6 +209,7 @@ def _setitem_with_indexer(self, indexer, value): labels = _safe_append_to_index(index, key) self.obj._data = self.obj.reindex_axis(labels, i)._data self.obj._maybe_update_cacher(clear=True) + self.obj._setitem_copy(False) if isinstance(labels, MultiIndex): self.obj.sortlevel(inplace=True) diff --git a/pandas/tests/test_index.py b/pandas/tests/test_index.py index 9a18e3c8562f6..c3214a444ea3a 100644 --- a/pandas/tests/test_index.py +++ b/pandas/tests/test_index.py @@ -1381,8 +1381,10 @@ def test_set_value_keeps_names(self): columns=['one', 'two', 'three', 'four'], index=idx) df = df.sortlevel() + self.assert_(df._is_copy is False) self.assertEqual(df.index.names, ('Name', 'Number')) df = df.set_value(('grethe', '4'), 'one', 99.34) + self.assert_(df._is_copy is False) self.assertEqual(df.index.names, ('Name', 'Number')) def test_names(self): diff --git a/pandas/tests/test_indexing.py b/pandas/tests/test_indexing.py index 02b5812c3e653..8baf2b43a22c4 100644 --- a/pandas/tests/test_indexing.py +++ b/pandas/tests/test_indexing.py @@ -1049,6 +1049,8 @@ def f(name,df2): return Series(np.arange(df2.shape[0]),name=df2.index.values[0]).reindex(f_index) new_df = pd.concat([ f(name,df2) for name, df2 in grp ],axis=1).T + # we are actually operating on a copy here + # but in this case, that's ok for name, df2 in grp: new_vals = np.arange(df2.shape[0]) df.ix[name, 'new_col'] = new_vals @@ -1769,7 +1771,8 @@ def f(): 'c' : [42,42,2,3,4,42,6]}) def f(): - df[df.a.str.startswith('o')]['c'] = 42 + indexer = df.a.str.startswith('o') + df[indexer]['c'] = 42 self.assertRaises(com.SettingWithCopyError, f) df['c'][df.a.str.startswith('o')] = 42 assert_frame_equal(df,expected) @@ -1785,7 +1788,8 @@ def f(): # warnings pd.set_option('chained_assignment','warn') df = DataFrame({'A':['aaa','bbb','ccc'],'B':[1,2,3]}) - df.loc[0]['A'] = 111 + with tm.assert_produces_warning(expected_warning=com.SettingWithCopyWarning): + df.loc[0]['A'] = 111 # make sure that _is_copy is picked up reconstruction # GH5475 @@ -1797,6 +1801,55 @@ def f(): df2["B"] = df2["A"] df2["B"] = df2["A"] + # a suprious raise as we are setting the entire column here + # GH5597 + pd.set_option('chained_assignment','raise') + from string import ascii_letters as letters + + def random_text(nobs=100): + df = [] + for i in range(nobs): + idx= np.random.randint(len(letters), size=2) + idx.sort() + df.append([letters[idx[0]:idx[1]]]) + + return DataFrame(df, columns=['letters']) + + df = random_text(100000) + + # always a copy + x = df.iloc[[0,1,2]] + self.assert_(x._is_copy is True) + x = df.iloc[[0,1,2,4]] + self.assert_(x._is_copy is True) + + # explicity copy + indexer = df.letters.apply(lambda x : len(x) > 10) + df = df.ix[indexer].copy() + self.assert_(df._is_copy is False) + df['letters'] = df['letters'].apply(str.lower) + + # implicity take + df = random_text(100000) + indexer = df.letters.apply(lambda x : len(x) > 10) + df = df.ix[indexer] + self.assert_(df._is_copy is True) + df.loc[:,'letters'] = df['letters'].apply(str.lower) + + # this will raise + #df['letters'] = df['letters'].apply(str.lower) + + df = random_text(100000) + indexer = df.letters.apply(lambda x : len(x) > 10) + df.ix[indexer,'letters'] = df.ix[indexer,'letters'].apply(str.lower) + + # an identical take, so no copy + df = DataFrame({'a' : [1]}).dropna() + self.assert_(df._is_copy is False) + df['a'] += 1 + + pd.set_option('chained_assignment','warn') + def test_float64index_slicing_bug(self): # GH 5557, related to slicing a float index ser = {256: 2321.0, 1: 78.0, 2: 2716.0, 3: 0.0, 4: 369.0, 5: 0.0, 6: 269.0, 7: 0.0, 8: 0.0, 9: 0.0, 10: 3536.0, 11: 0.0, 12: 24.0, 13: 0.0, 14: 931.0, 15: 0.0, 16: 101.0, 17: 78.0, 18: 9643.0, 19: 0.0, 20: 0.0, 21: 0.0, 22: 63761.0, 23: 0.0, 24: 446.0, 25: 0.0, 26: 34773.0, 27: 0.0, 28: 729.0, 29: 78.0, 30: 0.0, 31: 0.0, 32: 3374.0, 33: 0.0, 34: 1391.0, 35: 0.0, 36: 361.0, 37: 0.0, 38: 61808.0, 39: 0.0, 40: 0.0, 41: 0.0, 42: 6677.0, 43: 0.0, 44: 802.0, 45: 0.0, 46: 2691.0, 47: 0.0, 48: 3582.0, 49: 0.0, 50: 734.0, 51: 0.0, 52: 627.0, 53: 70.0, 54: 2584.0, 55: 0.0, 56: 324.0, 57: 0.0, 58: 605.0, 59: 0.0, 60: 0.0, 61: 0.0, 62: 3989.0, 63: 10.0, 64: 42.0, 65: 0.0, 66: 904.0, 67: 0.0, 68: 88.0, 69: 70.0, 70: 8172.0, 71: 0.0, 72: 0.0, 73: 0.0, 74: 64902.0, 75: 0.0, 76: 347.0, 77: 0.0, 78: 36605.0, 79: 0.0, 80: 379.0, 81: 70.0, 82: 0.0, 83: 0.0, 84: 3001.0, 85: 0.0, 86: 1630.0, 87: 7.0, 88: 364.0, 89: 0.0, 90: 67404.0, 91: 9.0, 92: 0.0, 93: 0.0, 94: 7685.0, 95: 0.0, 96: 1017.0, 97: 0.0, 98: 2831.0, 99: 0.0, 100: 2963.0, 101: 0.0, 102: 854.0, 103: 0.0, 104: 0.0, 105: 0.0, 106: 0.0, 107: 0.0, 108: 0.0, 109: 0.0, 110: 0.0, 111: 0.0, 112: 0.0, 113: 0.0, 114: 0.0, 115: 0.0, 116: 0.0, 117: 0.0, 118: 0.0, 119: 0.0, 120: 0.0, 121: 0.0, 122: 0.0, 123: 0.0, 124: 0.0, 125: 0.0, 126: 67744.0, 127: 22.0, 128: 264.0, 129: 0.0, 260: 197.0, 268: 0.0, 265: 0.0, 269: 0.0, 261: 0.0, 266: 1198.0, 267: 0.0, 262: 2629.0, 258: 775.0, 257: 0.0, 263: 0.0, 259: 0.0, 264: 163.0, 250: 10326.0, 251: 0.0, 252: 1228.0, 253: 0.0, 254: 2769.0, 255: 0.0} From 713a105ff5885bccb37255d2813fca708b640c6b Mon Sep 17 00:00:00 2001 From: jreback Date: Mon, 25 Nov 2013 12:32:57 -0500 Subject: [PATCH 2/4] TST: add testing base TestCase to provide global testing config --- pandas/tests/test_frame.py | 7 +++++-- pandas/util/testing.py | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index 280b0476efe98..cef8edaeaa5c5 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -1872,7 +1872,7 @@ def test_add_prefix_suffix(self): self.assert_(np.array_equal(with_suffix.columns, expected)) -class TestDataFrame(unittest.TestCase, CheckIndexing, +class TestDataFrame(tm.TestCase, CheckIndexing, SafeForSparse): klass = DataFrame @@ -12026,15 +12026,18 @@ def check_raise_on_panel4d_with_multiindex(self, parser, engine): pd.eval('p4d + 1', parser=parser, engine=engine) -class TestDataFrameQueryNumExprPandas(unittest.TestCase): +class TestDataFrameQueryNumExprPandas(tm.TestCase): + @classmethod def setUpClass(cls): + super(TestDataFrameQueryNumExprPandas, cls).setUpClass() cls.engine = 'numexpr' cls.parser = 'pandas' skip_if_no_ne() @classmethod def tearDownClass(cls): + super(TestDataFrameQueryNumExprPandas, cls).tearDownClass() del cls.engine, cls.parser def test_date_query_method(self): diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 2ea570d6f8e94..ebadc2103220d 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -11,6 +11,7 @@ import os import subprocess import locale +import unittest from datetime import datetime from functools import wraps, partial @@ -52,6 +53,17 @@ K = 4 _RAISE_NETWORK_ERROR_DEFAULT = False +class TestCase(unittest.TestCase): + + @classmethod + def setUpClass(cls): + pd.set_option('chained_assignment','raise') + print("setting up: {0}".format(cls)) + + @classmethod + def tearDownClass(cls): + pass + # NOTE: don't pass an NDFrame or index to this function - may not handle it # well. assert_almost_equal = _testing.assert_almost_equal From e640d0f2a52a80b3dbff833625d849e36d821204 Mon Sep 17 00:00:00 2001 From: jreback Date: Mon, 25 Nov 2013 13:04:49 -0500 Subject: [PATCH 3/4] TST: changed refs to use testing/TestCase where setUpClass/tearDownClass are defined --- pandas/computation/tests/test_eval.py | 15 ++++++-- pandas/io/tests/test_clipboard.py | 6 ++-- pandas/io/tests/test_data.py | 20 +++++++---- pandas/io/tests/test_gbq.py | 34 +++++++++--------- pandas/io/tests/test_html.py | 7 ++-- pandas/stats/tests/test_ols.py | 7 ++-- pandas/tests/test_frame.py | 50 ++++++++------------------- pandas/tools/tests/test_util.py | 9 ++--- pandas/util/testing.py | 3 +- 9 files changed, 75 insertions(+), 76 deletions(-) diff --git a/pandas/computation/tests/test_eval.py b/pandas/computation/tests/test_eval.py index f2d75d3fd21c5..cfbd9335ef9a0 100644 --- a/pandas/computation/tests/test_eval.py +++ b/pandas/computation/tests/test_eval.py @@ -1,6 +1,5 @@ #!/usr/bin/env python -import unittest import functools from itertools import product @@ -104,10 +103,11 @@ def _is_py3_complex_incompat(result, expected): _good_arith_ops = com.difference(_arith_ops_syms, _special_case_arith_ops_syms) -class TestEvalNumexprPandas(unittest.TestCase): +class TestEvalNumexprPandas(tm.TestCase): @classmethod def setUpClass(cls): + super(TestEvalNumexprPandas, cls).setUpClass() skip_if_no_ne() import numexpr as ne cls.ne = ne @@ -116,6 +116,7 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): + super(TestEvalNumexprPandas, cls).tearDownClass() del cls.engine, cls.parser if hasattr(cls, 'ne'): del cls.ne @@ -707,6 +708,7 @@ class TestEvalNumexprPython(TestEvalNumexprPandas): @classmethod def setUpClass(cls): + super(TestEvalNumexprPython, cls).setUpClass() skip_if_no_ne() import numexpr as ne cls.ne = ne @@ -733,6 +735,7 @@ class TestEvalPythonPython(TestEvalNumexprPython): @classmethod def setUpClass(cls): + super(TestEvalPythonPython, cls).setUpClass() cls.engine = 'python' cls.parser = 'python' @@ -761,6 +764,7 @@ class TestEvalPythonPandas(TestEvalPythonPython): @classmethod def setUpClass(cls): + super(TestEvalPythonPandas, cls).setUpClass() cls.engine = 'python' cls.parser = 'pandas' @@ -1024,10 +1028,11 @@ def test_performance_warning_for_poor_alignment(self): #------------------------------------ # slightly more complex ops -class TestOperationsNumExprPandas(unittest.TestCase): +class TestOperationsNumExprPandas(tm.TestCase): @classmethod def setUpClass(cls): + super(TestOperationsNumExprPandas, cls).setUpClass() skip_if_no_ne() cls.engine = 'numexpr' cls.parser = 'pandas' @@ -1035,6 +1040,7 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): + super(TestOperationsNumExprPandas, cls).tearDownClass() del cls.engine, cls.parser def eval(self, *args, **kwargs): @@ -1337,6 +1343,7 @@ class TestOperationsNumExprPython(TestOperationsNumExprPandas): @classmethod def setUpClass(cls): + super(TestOperationsNumExprPython, cls).setUpClass() if not _USE_NUMEXPR: raise nose.SkipTest("numexpr engine not installed") cls.engine = 'numexpr' @@ -1404,6 +1411,7 @@ class TestOperationsPythonPython(TestOperationsNumExprPython): @classmethod def setUpClass(cls): + super(TestOperationsPythonPython, cls).setUpClass() cls.engine = cls.parser = 'python' cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms cls.arith_ops = filter(lambda x: x not in ('in', 'not in'), @@ -1414,6 +1422,7 @@ class TestOperationsPythonPandas(TestOperationsNumExprPandas): @classmethod def setUpClass(cls): + super(TestOperationsPythonPandas, cls).setUpClass() cls.engine = 'python' cls.parser = 'pandas' cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms diff --git a/pandas/io/tests/test_clipboard.py b/pandas/io/tests/test_clipboard.py index 6ee0afa1c8c07..210427c1a9575 100644 --- a/pandas/io/tests/test_clipboard.py +++ b/pandas/io/tests/test_clipboard.py @@ -1,5 +1,3 @@ -import unittest - import numpy as np from numpy.random import randint @@ -18,9 +16,10 @@ raise nose.SkipTest("no clipboard found") -class TestClipboard(unittest.TestCase): +class TestClipboard(tm.TestCase): @classmethod def setUpClass(cls): + super(TestClipboard, cls).setupClass() cls.data = {} cls.data['string'] = mkdf(5, 3, c_idx_type='s', r_idx_type='i', c_idx_names=[None], r_idx_names=[None]) @@ -43,6 +42,7 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): + super(TestClipboard, cls).tearDownClass() del cls.data_types, cls.data def check_round_trip_frame(self, data_type, excel=None, sep=None): diff --git a/pandas/io/tests/test_data.py b/pandas/io/tests/test_data.py index 4e2331f05001d..8f289f41e45b4 100644 --- a/pandas/io/tests/test_data.py +++ b/pandas/io/tests/test_data.py @@ -1,6 +1,5 @@ from __future__ import print_function from pandas import compat -import unittest import warnings import nose from nose.tools import assert_equal @@ -35,15 +34,17 @@ def assert_n_failed_equals_n_null_columns(wngs, obj, cls=SymbolWarning): assert msgs.str.contains('|'.join(failed_symbols)).all() -class TestGoogle(unittest.TestCase): +class TestGoogle(tm.TestCase): @classmethod def setUpClass(cls): + super(TestGoogle, cls).setupClass() cls.locales = tm.get_locales(prefix='en_US') if not cls.locales: raise nose.SkipTest("US English locale not available for testing") @classmethod def tearDownClass(cls): + super(TestGoogle, cls).tearDownClass() del cls.locales @network @@ -105,9 +106,10 @@ def test_get_multi2(self): assert_n_failed_equals_n_null_columns(w, result) -class TestYahoo(unittest.TestCase): +class TestYahoo(tm.TestCase): @classmethod def setUpClass(cls): + super(TestYahoo, cls).setupClass() _skip_if_no_lxml() @network @@ -224,9 +226,10 @@ def test_get_date_ret_index(self): assert np.issubdtype(pan.values.dtype, np.floating) -class TestYahooOptions(unittest.TestCase): +class TestYahooOptions(tm.TestCase): @classmethod def setUpClass(cls): + super(TestYahooOptions, cls).setupClass() _skip_if_no_lxml() # aapl has monthlies @@ -241,6 +244,7 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): + super(TestYahooOptions, cls).tearDownClass() del cls.aapl, cls.expiry @network @@ -283,9 +287,10 @@ def test_get_put_data(self): assert len(puts)>1 -class TestOptionsWarnings(unittest.TestCase): +class TestOptionsWarnings(tm.TestCase): @classmethod def setUpClass(cls): + super(TestOptionsWarnings, cls).setupClass() _skip_if_no_lxml() with assert_produces_warning(FutureWarning): @@ -300,6 +305,7 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): + super(TestOptionsWarnings, cls).tearDownClass() del cls.aapl, cls.year, cls.month @network @@ -342,7 +348,7 @@ def test_get_put_data_warning(self): warnings.warn("IndexError thrown no tables found") -class TestDataReader(unittest.TestCase): +class TestDataReader(tm.TestCase): def test_is_s3_url(self): from pandas.io.common import _is_s3_url self.assert_(_is_s3_url("s3://pandas/somethingelse.com")) @@ -372,7 +378,7 @@ def test_read_famafrench(self): assert isinstance(ff, dict) -class TestFred(unittest.TestCase): +class TestFred(tm.TestCase): @network def test_fred(self): """ diff --git a/pandas/io/tests/test_gbq.py b/pandas/io/tests/test_gbq.py index f56c1aa042421..ba653f39790ad 100644 --- a/pandas/io/tests/test_gbq.py +++ b/pandas/io/tests/test_gbq.py @@ -3,7 +3,6 @@ import os import shutil import subprocess -import unittest import numpy as np @@ -41,18 +40,18 @@ def GetTableSchema(self,table_dict): class FakeApiClient: def __init__(self): self._fakejobs = FakeJobs() - + def jobs(self): return self._fakejobs class FakeJobs: - def __init__(self): + def __init__(self): self._fakequeryresults = FakeResults() def getQueryResults(self, job_id=None, project_id=None, max_results=None, timeout_ms=None, **kwargs): - return self._fakequeryresults + return self._fakequeryresults class FakeResults: def execute(self): @@ -74,7 +73,7 @@ def execute(self): #################################################################################### -class test_gbq(unittest.TestCase): +class TestGbq(tm.TestCase): def setUp(self): with open(self.fake_job_path, 'r') as fin: self.fake_job = ast.literal_eval(fin.read()) @@ -102,7 +101,7 @@ def setUp(self): ('othello', 1603, 'brawl', 2), ('othello', 1603, "'", 17), ('othello', 1603, 'troubled', 1) - ], + ], dtype=[('corpus', 'S16'), ('corpus_date', ' Date: Mon, 25 Nov 2013 14:15:15 -0500 Subject: [PATCH 4/4] TST: change from using unittest.TestCase directly to using pandas.util.testing.TestCase --- pandas/io/tests/test_clipboard.py | 2 +- pandas/io/tests/test_cparser.py | 5 +- pandas/io/tests/test_data.py | 8 +- pandas/io/tests/test_date_converters.py | 5 +- pandas/io/tests/test_excel.py | 17 +- pandas/io/tests/test_ga.py | 10 +- pandas/io/tests/test_gbq.py | 18 ++- pandas/io/tests/test_html.py | 4 +- pandas/io/tests/test_json/test_pandas.py | 3 +- pandas/io/tests/test_json_norm.py | 5 +- pandas/io/tests/test_packers.py | 17 +- pandas/io/tests/test_parsers.py | 11 +- pandas/io/tests/test_pickle.py | 3 +- pandas/io/tests/test_pytables.py | 3 +- pandas/io/tests/test_sql.py | 8 +- pandas/io/tests/test_stata.py | 3 +- pandas/io/tests/test_wb.py | 65 ++++---- pandas/sparse/tests/test_array.py | 3 +- pandas/sparse/tests/test_libsparse.py | 8 +- pandas/sparse/tests/test_sparse.py | 9 +- pandas/stats/tests/common.py | 5 +- pandas/stats/tests/test_math.py | 3 +- pandas/stats/tests/test_moments.py | 3 +- pandas/stats/tests/test_ols.py | 6 +- pandas/tests/test_algos.py | 9 +- pandas/tests/test_base.py | 7 +- pandas/tests/test_categorical.py | 3 +- pandas/tests/test_common.py | 5 +- pandas/tests/test_expressions.py | 4 +- pandas/tests/test_format.py | 9 +- pandas/tests/test_generic.py | 39 ++++- pandas/tests/test_graphics.py | 13 +- pandas/tests/test_groupby.py | 3 +- pandas/tests/test_index.py | 9 +- pandas/tests/test_indexing.py | 3 +- pandas/tests/test_internals.py | 8 +- pandas/tests/test_multilevel.py | 6 +- pandas/tests/test_ndframe.py | 47 ------ pandas/tests/test_panel.py | 5 +- pandas/tests/test_panel4d.py | 3 +- pandas/tests/test_panelnd.py | 3 +- pandas/tests/test_reshape.py | 9 +- pandas/tests/test_rplot.py | 18 +-- pandas/tests/test_series.py | 7 +- pandas/tests/test_stats.py | 4 +- pandas/tests/test_strings.py | 7 +- pandas/tests/test_tseries.py | 18 +-- pandas/tools/tests/test_merge.py | 9 +- pandas/tools/tests/test_pivot.py | 5 +- pandas/tools/tests/test_tile.py | 7 +- pandas/tools/tests/test_tools.py | 25 +-- pandas/tools/tests/test_util.py | 2 +- pandas/tseries/tests/test_converter.py | 4 +- pandas/tseries/tests/test_cursor.py | 196 ----------------------- pandas/tseries/tests/test_daterange.py | 7 +- pandas/tseries/tests/test_frequencies.py | 7 +- pandas/tseries/tests/test_offsets.py | 61 ++++--- pandas/tseries/tests/test_period.py | 23 +-- pandas/tseries/tests/test_plotting.py | 3 +- pandas/tseries/tests/test_resample.py | 7 +- pandas/tseries/tests/test_timedeltas.py | 3 +- pandas/tseries/tests/test_timeseries.py | 17 +- pandas/tseries/tests/test_timezones.py | 17 +- pandas/tseries/tests/test_tslib.py | 18 +-- pandas/tseries/tests/test_util.py | 3 +- 65 files changed, 300 insertions(+), 577 deletions(-) delete mode 100644 pandas/tests/test_ndframe.py delete mode 100644 pandas/tseries/tests/test_cursor.py diff --git a/pandas/io/tests/test_clipboard.py b/pandas/io/tests/test_clipboard.py index 210427c1a9575..3556dfd999d40 100644 --- a/pandas/io/tests/test_clipboard.py +++ b/pandas/io/tests/test_clipboard.py @@ -19,7 +19,7 @@ class TestClipboard(tm.TestCase): @classmethod def setUpClass(cls): - super(TestClipboard, cls).setupClass() + super(TestClipboard, cls).setUpClass() cls.data = {} cls.data['string'] = mkdf(5, 3, c_idx_type='s', r_idx_type='i', c_idx_names=[None], r_idx_names=[None]) diff --git a/pandas/io/tests/test_cparser.py b/pandas/io/tests/test_cparser.py index 8db9c7de6cbcd..0b104ffba4242 100644 --- a/pandas/io/tests/test_cparser.py +++ b/pandas/io/tests/test_cparser.py @@ -9,7 +9,6 @@ import os import sys import re -import unittest import nose @@ -32,7 +31,7 @@ import pandas.parser as parser -class TestCParser(unittest.TestCase): +class TestCParser(tm.TestCase): def setUp(self): self.dirpath = tm.get_data_path() @@ -132,7 +131,7 @@ def test_integer_thousands(self): expected = [123456, 12500] tm.assert_almost_equal(result[0], expected) - + def test_integer_thousands_alt(self): data = '123.456\n12.500' diff --git a/pandas/io/tests/test_data.py b/pandas/io/tests/test_data.py index 8f289f41e45b4..831be69b9db5f 100644 --- a/pandas/io/tests/test_data.py +++ b/pandas/io/tests/test_data.py @@ -37,7 +37,7 @@ def assert_n_failed_equals_n_null_columns(wngs, obj, cls=SymbolWarning): class TestGoogle(tm.TestCase): @classmethod def setUpClass(cls): - super(TestGoogle, cls).setupClass() + super(TestGoogle, cls).setUpClass() cls.locales = tm.get_locales(prefix='en_US') if not cls.locales: raise nose.SkipTest("US English locale not available for testing") @@ -109,7 +109,7 @@ def test_get_multi2(self): class TestYahoo(tm.TestCase): @classmethod def setUpClass(cls): - super(TestYahoo, cls).setupClass() + super(TestYahoo, cls).setUpClass() _skip_if_no_lxml() @network @@ -229,7 +229,7 @@ def test_get_date_ret_index(self): class TestYahooOptions(tm.TestCase): @classmethod def setUpClass(cls): - super(TestYahooOptions, cls).setupClass() + super(TestYahooOptions, cls).setUpClass() _skip_if_no_lxml() # aapl has monthlies @@ -290,7 +290,7 @@ def test_get_put_data(self): class TestOptionsWarnings(tm.TestCase): @classmethod def setUpClass(cls): - super(TestOptionsWarnings, cls).setupClass() + super(TestOptionsWarnings, cls).setUpClass() _skip_if_no_lxml() with assert_produces_warning(FutureWarning): diff --git a/pandas/io/tests/test_date_converters.py b/pandas/io/tests/test_date_converters.py index 8c1009b904857..74dad8537bb88 100644 --- a/pandas/io/tests/test_date_converters.py +++ b/pandas/io/tests/test_date_converters.py @@ -4,7 +4,6 @@ import os import sys import re -import unittest import nose @@ -22,9 +21,9 @@ from pandas import compat from pandas.lib import Timestamp import pandas.io.date_converters as conv +import pandas.util.testing as tm - -class TestConverters(unittest.TestCase): +class TestConverters(tm.TestCase): def setUp(self): self.years = np.array([2007, 2008]) diff --git a/pandas/io/tests/test_excel.py b/pandas/io/tests/test_excel.py index 861f3a785ce22..3446eb07a111e 100644 --- a/pandas/io/tests/test_excel.py +++ b/pandas/io/tests/test_excel.py @@ -3,7 +3,6 @@ from pandas.compat import u, range, map from datetime import datetime import os -import unittest import nose @@ -86,7 +85,7 @@ def read_csv(self, *args, **kwds): return read_csv(*args, **kwds) -class ExcelReaderTests(SharedItems, unittest.TestCase): +class ExcelReaderTests(SharedItems, tm.TestCase): def test_parse_cols_int(self): _skip_if_no_openpyxl() _skip_if_no_xlrd() @@ -942,7 +941,7 @@ def test_swapped_columns(self): tm.assert_series_equal(write_frame['B'], read_frame['B']) -class OpenpyxlTests(ExcelWriterBase, unittest.TestCase): +class OpenpyxlTests(ExcelWriterBase, tm.TestCase): ext = '.xlsx' engine_name = 'openpyxl' check_skip = staticmethod(_skip_if_no_openpyxl) @@ -975,7 +974,7 @@ def test_to_excel_styleconverter(self): xlsx_style.alignment.vertical) -class XlwtTests(ExcelWriterBase, unittest.TestCase): +class XlwtTests(ExcelWriterBase, tm.TestCase): ext = '.xls' engine_name = 'xlwt' check_skip = staticmethod(_skip_if_no_xlwt) @@ -1002,13 +1001,13 @@ def test_to_excel_styleconverter(self): self.assertEquals(xlwt.Alignment.VERT_TOP, xls_style.alignment.vert) -class XlsxWriterTests(ExcelWriterBase, unittest.TestCase): +class XlsxWriterTests(ExcelWriterBase, tm.TestCase): ext = '.xlsx' engine_name = 'xlsxwriter' check_skip = staticmethod(_skip_if_no_xlsxwriter) -class OpenpyxlTests_NoMerge(ExcelWriterBase, unittest.TestCase): +class OpenpyxlTests_NoMerge(ExcelWriterBase, tm.TestCase): ext = '.xlsx' engine_name = 'openpyxl' check_skip = staticmethod(_skip_if_no_openpyxl) @@ -1017,7 +1016,7 @@ class OpenpyxlTests_NoMerge(ExcelWriterBase, unittest.TestCase): merge_cells = False -class XlwtTests_NoMerge(ExcelWriterBase, unittest.TestCase): +class XlwtTests_NoMerge(ExcelWriterBase, tm.TestCase): ext = '.xls' engine_name = 'xlwt' check_skip = staticmethod(_skip_if_no_xlwt) @@ -1026,7 +1025,7 @@ class XlwtTests_NoMerge(ExcelWriterBase, unittest.TestCase): merge_cells = False -class XlsxWriterTests_NoMerge(ExcelWriterBase, unittest.TestCase): +class XlsxWriterTests_NoMerge(ExcelWriterBase, tm.TestCase): ext = '.xlsx' engine_name = 'xlsxwriter' check_skip = staticmethod(_skip_if_no_xlsxwriter) @@ -1035,7 +1034,7 @@ class XlsxWriterTests_NoMerge(ExcelWriterBase, unittest.TestCase): merge_cells = False -class ExcelWriterEngineTests(unittest.TestCase): +class ExcelWriterEngineTests(tm.TestCase): def test_ExcelWriter_dispatch(self): with tm.assertRaisesRegexp(ValueError, 'No engine'): ExcelWriter('nothing') diff --git a/pandas/io/tests/test_ga.py b/pandas/io/tests/test_ga.py index 166917799ca82..33ead20b6815f 100644 --- a/pandas/io/tests/test_ga.py +++ b/pandas/io/tests/test_ga.py @@ -1,5 +1,4 @@ import os -import unittest from datetime import datetime import nose @@ -7,6 +6,7 @@ from pandas import DataFrame from pandas.util.testing import network, assert_frame_equal, with_connectivity_check from numpy.testing.decorators import slow +import pandas.util.testing as tm try: import httplib2 @@ -17,7 +17,7 @@ except ImportError: raise nose.SkipTest("need httplib2 and auth libs") -class TestGoogle(unittest.TestCase): +class TestGoogle(tm.TestCase): _multiprocess_can_split_ = True @@ -103,17 +103,17 @@ def test_v2_advanced_segment_format(self): advanced_segment_id = 1234567 query = ga.format_query('google_profile_id', ['visits'], '2013-09-01', segment=advanced_segment_id) assert query['segment'] == 'gaid::' + str(advanced_segment_id), "An integer value should be formatted as an advanced segment." - + def test_v2_dynamic_segment_format(self): dynamic_segment_id = 'medium==referral' query = ga.format_query('google_profile_id', ['visits'], '2013-09-01', segment=dynamic_segment_id) assert query['segment'] == 'dynamic::ga:' + str(dynamic_segment_id), "A string value with more than just letters and numbers should be formatted as a dynamic segment." - + def test_v3_advanced_segment_common_format(self): advanced_segment_id = 'aZwqR234' query = ga.format_query('google_profile_id', ['visits'], '2013-09-01', segment=advanced_segment_id) assert query['segment'] == 'gaid::' + str(advanced_segment_id), "A string value with just letters and numbers should be formatted as an advanced segment." - + def test_v3_advanced_segment_weird_format(self): advanced_segment_id = 'aZwqR234-s1' query = ga.format_query('google_profile_id', ['visits'], '2013-09-01', segment=advanced_segment_id) diff --git a/pandas/io/tests/test_gbq.py b/pandas/io/tests/test_gbq.py index ba653f39790ad..ec051d008b3f3 100644 --- a/pandas/io/tests/test_gbq.py +++ b/pandas/io/tests/test_gbq.py @@ -138,28 +138,30 @@ def setUp(self): 'NULL_BOOLEAN']] @classmethod - def setUpClass(self): + def setUpClass(cls): # Integration tests require a valid bigquery token # be present in the user's home directory. This # can be generated with 'bq init' in the command line - super(TestGbq, cls).setupClass() - self.dirpath = tm.get_data_path() + super(TestGbq, cls).setUpClass() + cls.dirpath = tm.get_data_path() home = os.path.expanduser("~") - self.bq_token = os.path.join(home, '.bigquery.v2.token') - self.fake_job_path = os.path.join(self.dirpath, 'gbq_fake_job.txt') + cls.bq_token = os.path.join(home, '.bigquery.v2.token') + cls.fake_job_path = os.path.join(cls.dirpath, 'gbq_fake_job.txt') # If we're using a valid token, make a test dataset # Note, dataset functionality is beyond the scope # of the module under test, so we rely on the command # line utility for this. - if os.path.exists(self.bq_token): + if os.path.exists(cls.bq_token): subprocess.call(['bq','mk', '-d', 'pandas_testing_dataset']) @classmethod - def tearDownClass(self): + def tearDownClass(cls): + super(TestGbq, cls).tearDownClass() + # If we're using a valid token, remove the test dataset # created. - if os.path.exists(self.bq_token): + if os.path.exists(cls.bq_token): subprocess.call(['bq', 'rm', '-r', '-f', '-d', 'pandas_testing_dataset']) @with_connectivity_check diff --git a/pandas/io/tests/test_html.py b/pandas/io/tests/test_html.py index 2471667aa456a..893b1768b00c3 100644 --- a/pandas/io/tests/test_html.py +++ b/pandas/io/tests/test_html.py @@ -87,7 +87,7 @@ def test_bs4_version_fails(): class TestReadHtml(tm.TestCase): @classmethod def setUpClass(cls): - super(TestReadHtml, cls).setupClass() + super(TestReadHtml, cls).setUpClass() _skip_if_none_of(('bs4', 'html5lib')) def read_html(self, *args, **kwargs): @@ -585,7 +585,7 @@ def test_parse_dates_combine(self): class TestReadHtmlLxml(tm.TestCase): @classmethod def setUpClass(cls): - super(TestReadHtmlLxml, cls).setupClass() + super(TestReadHtmlLxml, cls).setUpClass() _skip_if_no('lxml') def read_html(self, *args, **kwargs): diff --git a/pandas/io/tests/test_json/test_pandas.py b/pandas/io/tests/test_json/test_pandas.py index 6d392eb265752..084bc63188e2b 100644 --- a/pandas/io/tests/test_json/test_pandas.py +++ b/pandas/io/tests/test_json/test_pandas.py @@ -2,7 +2,6 @@ from pandas.compat import range, lrange, StringIO from pandas import compat import os -import unittest import numpy as np @@ -27,7 +26,7 @@ _mixed_frame = _frame.copy() -class TestPandasContainer(unittest.TestCase): +class TestPandasContainer(tm.TestCase): def setUp(self): self.dirpath = tm.get_data_path() diff --git a/pandas/io/tests/test_json_norm.py b/pandas/io/tests/test_json_norm.py index e96a89e71f12d..8084446d2d246 100644 --- a/pandas/io/tests/test_json_norm.py +++ b/pandas/io/tests/test_json_norm.py @@ -1,5 +1,4 @@ import nose -import unittest from pandas import DataFrame import numpy as np @@ -15,7 +14,7 @@ def _assert_equal_data(left, right): tm.assert_frame_equal(left, right) -class TestJSONNormalize(unittest.TestCase): +class TestJSONNormalize(tm.TestCase): def setUp(self): self.state_data = [ @@ -165,7 +164,7 @@ def test_record_prefix(self): tm.assert_frame_equal(result, expected) -class TestNestedToRecord(unittest.TestCase): +class TestNestedToRecord(tm.TestCase): def test_flat_stays_flat(self): recs = [dict(flat1=1,flat2=2), diff --git a/pandas/io/tests/test_packers.py b/pandas/io/tests/test_packers.py index 28c541e3735c9..1563406b1f8af 100644 --- a/pandas/io/tests/test_packers.py +++ b/pandas/io/tests/test_packers.py @@ -1,5 +1,4 @@ import nose -import unittest import datetime import numpy as np @@ -44,7 +43,7 @@ def check_arbitrary(a, b): assert(a == b) -class Test(unittest.TestCase): +class TestPackers(tm.TestCase): def setUp(self): self.path = '__%s__.msg' % tm.rands(10) @@ -57,7 +56,7 @@ def encode_decode(self, x, **kwargs): to_msgpack(p, x, **kwargs) return read_msgpack(p, **kwargs) -class TestAPI(Test): +class TestAPI(TestPackers): def test_string_io(self): @@ -94,7 +93,7 @@ def test_iterator_with_string_io(self): for i, result in enumerate(read_msgpack(s,iterator=True)): tm.assert_frame_equal(result,dfs[i]) -class TestNumpy(Test): +class TestNumpy(TestPackers): def test_numpy_scalar_float(self): x = np.float32(np.random.rand()) @@ -187,7 +186,7 @@ def test_list_mixed(self): x_rec = self.encode_decode(x) tm.assert_almost_equal(x,x_rec) -class TestBasic(Test): +class TestBasic(TestPackers): def test_timestamp(self): @@ -219,7 +218,7 @@ def test_timedeltas(self): self.assert_(i == i_rec) -class TestIndex(Test): +class TestIndex(TestPackers): def setUp(self): super(TestIndex, self).setUp() @@ -273,7 +272,7 @@ def test_unicode(self): #self.assert_(i.equals(i_rec)) -class TestSeries(Test): +class TestSeries(TestPackers): def setUp(self): super(TestSeries, self).setUp() @@ -312,7 +311,7 @@ def test_basic(self): assert_series_equal(i, i_rec) -class TestNDFrame(Test): +class TestNDFrame(TestPackers): def setUp(self): super(TestNDFrame, self).setUp() @@ -374,7 +373,7 @@ def test_iterator(self): check_arbitrary(packed, l[i]) -class TestSparse(Test): +class TestSparse(TestPackers): def _check_roundtrip(self, obj, comparator, **kwargs): diff --git a/pandas/io/tests/test_parsers.py b/pandas/io/tests/test_parsers.py index 84736f16e7cba..563e9c136cad2 100644 --- a/pandas/io/tests/test_parsers.py +++ b/pandas/io/tests/test_parsers.py @@ -6,7 +6,6 @@ import os import sys import re -import unittest import nose import platform @@ -2049,7 +2048,7 @@ def test_catch_too_many_names(self): tm.assertRaises(Exception, read_csv, StringIO(data), header=0, names=['a', 'b', 'c', 'd']) -class TestPythonParser(ParserTests, unittest.TestCase): +class TestPythonParser(ParserTests, tm.TestCase): def test_negative_skipfooter_raises(self): text = """#foo,a,b,c #foo,a,b,c @@ -2364,7 +2363,7 @@ def test_iteration_open_handle(self): tm.assert_series_equal(result, expected) -class TestFwfColspaceSniffing(unittest.TestCase): +class TestFwfColspaceSniffing(tm.TestCase): def test_full_file(self): # File with all values test = '''index A B C @@ -2464,7 +2463,7 @@ def test_variable_width_unicode(self): header=None, encoding='utf8')) -class TestCParserHighMemory(ParserTests, unittest.TestCase): +class TestCParserHighMemory(ParserTests, tm.TestCase): def read_csv(self, *args, **kwds): kwds = kwds.copy() @@ -2504,7 +2503,7 @@ def test_usecols(self): raise nose.SkipTest("Usecols is not supported in C High Memory engine.") -class TestCParserLowMemory(ParserTests, unittest.TestCase): +class TestCParserLowMemory(ParserTests, tm.TestCase): def read_csv(self, *args, **kwds): kwds = kwds.copy() @@ -2831,7 +2830,7 @@ def test_invalid_c_parser_opts_with_not_c_parser(self): engine)): read_csv(StringIO(data), engine=engine, **kwargs) -class TestParseSQL(unittest.TestCase): +class TestParseSQL(tm.TestCase): def test_convert_sql_column_floats(self): arr = np.array([1.5, None, 3, 4.2], dtype=object) diff --git a/pandas/io/tests/test_pickle.py b/pandas/io/tests/test_pickle.py index ea769a0515a78..b70248d1ef3f4 100644 --- a/pandas/io/tests/test_pickle.py +++ b/pandas/io/tests/test_pickle.py @@ -5,7 +5,6 @@ from datetime import datetime, timedelta import operator import pickle as pkl -import unittest import nose import os @@ -24,7 +23,7 @@ def _read_pickle(vf, encoding=None, compat=False): with open(vf,'rb') as fh: pc.load(fh, encoding=encoding, compat=compat) -class TestPickle(unittest.TestCase): +class TestPickle(tm.TestCase): _multiprocess_can_split_ = True def setUp(self): diff --git a/pandas/io/tests/test_pytables.py b/pandas/io/tests/test_pytables.py index ba69f7a834dad..78d9dcb1fb888 100644 --- a/pandas/io/tests/test_pytables.py +++ b/pandas/io/tests/test_pytables.py @@ -1,5 +1,4 @@ import nose -import unittest import sys import os import warnings @@ -118,7 +117,7 @@ def compat_assert_produces_warning(w,f): f() -class TestHDFStore(unittest.TestCase): +class TestHDFStore(tm.TestCase): def setUp(self): warnings.filterwarnings(action='ignore', category=FutureWarning) diff --git a/pandas/io/tests/test_sql.py b/pandas/io/tests/test_sql.py index f135a3619e03c..38770def8eb7c 100644 --- a/pandas/io/tests/test_sql.py +++ b/pandas/io/tests/test_sql.py @@ -1,5 +1,4 @@ from __future__ import print_function -import unittest import sqlite3 import sys @@ -52,7 +51,7 @@ def _skip_if_no_MySQLdb(): except ImportError: raise nose.SkipTest('MySQLdb not installed, skipping') -class TestSQLite(unittest.TestCase): +class TestSQLite(tm.TestCase): def setUp(self): self.db = sqlite3.connect(':memory:') @@ -243,7 +242,7 @@ def test_onecolumn_of_integer(self): tm.assert_frame_equal(result,mono_df) -class TestMySQL(unittest.TestCase): +class TestMySQL(tm.TestCase): def setUp(self): _skip_if_no_MySQLdb() @@ -487,8 +486,5 @@ def test_keyword_as_column_names(self): if __name__ == '__main__': - # unittest.main() - # nose.runmodule(argv=[__file__,'-vvs','-x', '--pdb-failure'], - # exit=False) nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], exit=False) diff --git a/pandas/io/tests/test_stata.py b/pandas/io/tests/test_stata.py index 0a87ada7097cb..76dae396c04ed 100644 --- a/pandas/io/tests/test_stata.py +++ b/pandas/io/tests/test_stata.py @@ -2,7 +2,6 @@ from datetime import datetime import os -import unittest import warnings import nose @@ -15,7 +14,7 @@ from pandas.util.misc import is_little_endian from pandas import compat -class StataTests(unittest.TestCase): +class TestStata(tm.TestCase): def setUp(self): # Unit test datasets for dta7 - dta9 (old stata formats 104, 105 and 107) can be downloaded from: diff --git a/pandas/io/tests/test_wb.py b/pandas/io/tests/test_wb.py index 60b4d8d462723..9549372823af8 100644 --- a/pandas/io/tests/test_wb.py +++ b/pandas/io/tests/test_wb.py @@ -1,42 +1,47 @@ import nose import pandas +from pandas.compat import u 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 +import pandas.util.testing as tm +class TestWB(tm.TestCase): -@slow -@network -def test_wdi_search(): - raise nose.SkipTest("skipping for now") - expected = {u('id'): {2634: u('GDPPCKD'), - 4649: u('NY.GDP.PCAP.KD'), - 4651: u('NY.GDP.PCAP.KN'), - 4653: u('NY.GDP.PCAP.PP.KD')}, - u('name'): {2634: u('GDP per Capita, constant US$, ' - 'millions'), - 4649: u('GDP per capita (constant 2000 US$)'), - 4651: u('GDP per capita (constant LCU)'), - 4653: u('GDP per capita, PPP (constant 2005 ' - 'international $)')}} - result = search('gdp.*capita.*constant').ix[:, :2] - expected = pandas.DataFrame(expected) - expected.index = result.index - assert_frame_equal(result, expected) - - -@slow -@network -def test_wdi_download(): - raise nose.SkipTest("skipping for now") - expected = {'GDPPCKN': {(u('United States'), u('2003')): u('40800.0735367688'), (u('Canada'), u('2004')): u('37857.1261134552'), (u('United States'), u('2005')): u('42714.8594790102'), (u('Canada'), u('2003')): u('37081.4575704003'), (u('United States'), u('2004')): u('41826.1728310667'), (u('Mexico'), u('2003')): u('72720.0691255285'), (u('Mexico'), u('2004')): u('74751.6003347038'), (u('Mexico'), u('2005')): u('76200.2154469437'), (u('Canada'), u('2005')): u('38617.4563629611')}, 'GDPPCKD': {(u('United States'), u('2003')): u('40800.0735367688'), (u('Canada'), u('2004')): u('34397.055116118'), (u('United States'), u('2005')): u('42714.8594790102'), (u('Canada'), u('2003')): u('33692.2812368928'), (u('United States'), u('2004')): u('41826.1728310667'), (u('Mexico'), u('2003')): u('7608.43848670658'), (u('Mexico'), u('2004')): u('7820.99026814334'), (u('Mexico'), u('2005')): u('7972.55364129367'), (u('Canada'), u('2005')): u('35087.8925933298')}} - expected = pandas.DataFrame(expected) - result = download(country=['CA', 'MX', 'US', 'junk'], indicator=['GDPPCKD', - 'GDPPCKN', 'junk'], start=2003, end=2005) - expected.index = result.index - assert_frame_equal(result, pandas.DataFrame(expected)) + @slow + @network + def test_wdi_search(self): + raise nose.SkipTest + + expected = {u('id'): {2634: u('GDPPCKD'), + 4649: u('NY.GDP.PCAP.KD'), + 4651: u('NY.GDP.PCAP.KN'), + 4653: u('NY.GDP.PCAP.PP.KD')}, + u('name'): {2634: u('GDP per Capita, constant US$, ' + 'millions'), + 4649: u('GDP per capita (constant 2000 US$)'), + 4651: u('GDP per capita (constant LCU)'), + 4653: u('GDP per capita, PPP (constant 2005 ' + 'international $)')}} + result = search('gdp.*capita.*constant').ix[:, :2] + expected = pandas.DataFrame(expected) + expected.index = result.index + assert_frame_equal(result, expected) + + + @slow + @network + def test_wdi_download(self): + raise nose.SkipTest + + expected = {'GDPPCKN': {(u('United States'), u('2003')): u('40800.0735367688'), (u('Canada'), u('2004')): u('37857.1261134552'), (u('United States'), u('2005')): u('42714.8594790102'), (u('Canada'), u('2003')): u('37081.4575704003'), (u('United States'), u('2004')): u('41826.1728310667'), (u('Mexico'), u('2003')): u('72720.0691255285'), (u('Mexico'), u('2004')): u('74751.6003347038'), (u('Mexico'), u('2005')): u('76200.2154469437'), (u('Canada'), u('2005')): u('38617.4563629611')}, 'GDPPCKD': {(u('United States'), u('2003')): u('40800.0735367688'), (u('Canada'), u('2004')): u('34397.055116118'), (u('United States'), u('2005')): u('42714.8594790102'), (u('Canada'), u('2003')): u('33692.2812368928'), (u('United States'), u('2004')): u('41826.1728310667'), (u('Mexico'), u('2003')): u('7608.43848670658'), (u('Mexico'), u('2004')): u('7820.99026814334'), (u('Mexico'), u('2005')): u('7972.55364129367'), (u('Canada'), u('2005')): u('35087.8925933298')}} + expected = pandas.DataFrame(expected) + result = download(country=['CA', 'MX', 'US', 'junk'], indicator=['GDPPCKD', + 'GDPPCKN', 'junk'], start=2003, end=2005) + expected.index = result.index + assert_frame_equal(result, pandas.DataFrame(expected)) if __name__ == '__main__': diff --git a/pandas/sparse/tests/test_array.py b/pandas/sparse/tests/test_array.py index 21ab1c4354316..86fc4598fc1c8 100644 --- a/pandas/sparse/tests/test_array.py +++ b/pandas/sparse/tests/test_array.py @@ -5,7 +5,6 @@ import operator import pickle -import unittest from pandas.core.series import Series from pandas.core.common import notnull @@ -23,7 +22,7 @@ def assert_sp_array_equal(left, right): assert(left.fill_value == right.fill_value) -class TestSparseArray(unittest.TestCase): +class TestSparseArray(tm.TestCase): _multiprocess_can_split_ = True def setUp(self): diff --git a/pandas/sparse/tests/test_libsparse.py b/pandas/sparse/tests/test_libsparse.py index f820142a6e71d..8cbebad61c068 100644 --- a/pandas/sparse/tests/test_libsparse.py +++ b/pandas/sparse/tests/test_libsparse.py @@ -1,5 +1,3 @@ -from unittest import TestCase - from pandas import Series import nose @@ -235,7 +233,7 @@ def _check_case(xloc, xlen, yloc, ylen, eloc, elen): check_cases(_check_case) -class TestBlockIndex(TestCase): +class TestBlockIndex(tm.TestCase): def test_equals(self): index = BlockIndex(10, [0, 4], [2, 5]) @@ -274,7 +272,7 @@ def test_to_block_index(self): self.assert_(index.to_block_index() is index) -class TestIntIndex(TestCase): +class TestIntIndex(tm.TestCase): def test_equals(self): index = IntIndex(10, [0, 1, 2, 3, 4]) @@ -299,7 +297,7 @@ def test_to_int_index(self): self.assert_(index.to_int_index() is index) -class TestSparseOperators(TestCase): +class TestSparseOperators(tm.TestCase): def _nan_op_tests(self, sparse_op, python_op): def _check_case(xloc, xlen, yloc, ylen, eloc, elen): diff --git a/pandas/sparse/tests/test_sparse.py b/pandas/sparse/tests/test_sparse.py index b3f2a8b3b8136..bd05a7093fd7c 100644 --- a/pandas/sparse/tests/test_sparse.py +++ b/pandas/sparse/tests/test_sparse.py @@ -1,6 +1,5 @@ # pylint: disable-msg=E1101,W0612 -from unittest import TestCase import operator from datetime import datetime @@ -119,7 +118,7 @@ def assert_sp_panel_equal(left, right, exact_indices=True): assert(item in left) -class TestSparseSeries(TestCase, +class TestSparseSeries(tm.TestCase, test_series.CheckNameIntegration): _multiprocess_can_split_ = True @@ -742,11 +741,11 @@ def test_combine_first(self): assert_sp_series_equal(result, expected) -class TestSparseTimeSeries(TestCase): +class TestSparseTimeSeries(tm.TestCase): pass -class TestSparseDataFrame(TestCase, test_frame.SafeForSparse): +class TestSparseDataFrame(tm.TestCase, test_frame.SafeForSparse): klass = SparseDataFrame _multiprocess_can_split_ = True @@ -1562,7 +1561,7 @@ def panel_data3(): }, index=index) -class TestSparsePanel(TestCase, +class TestSparsePanel(tm.TestCase, test_panel.SafeForLongAndSparse, test_panel.SafeForSparse): _multiprocess_can_split_ = True diff --git a/pandas/stats/tests/common.py b/pandas/stats/tests/common.py index 2866a36bc435a..717eb51292796 100644 --- a/pandas/stats/tests/common.py +++ b/pandas/stats/tests/common.py @@ -2,13 +2,14 @@ from datetime import datetime import string -import unittest import nose import numpy as np from pandas import DataFrame, bdate_range from pandas.util.testing import assert_almost_equal # imported in other tests +import pandas.util.testing as tm + N = 100 K = 4 @@ -52,7 +53,7 @@ def check_for_statsmodels(): raise nose.SkipTest('no statsmodels') -class BaseTest(unittest.TestCase): +class BaseTest(tm.TestCase): def setUp(self): check_for_scipy() check_for_statsmodels() diff --git a/pandas/stats/tests/test_math.py b/pandas/stats/tests/test_math.py index 008fffdc1db06..32ec2ff2c0853 100644 --- a/pandas/stats/tests/test_math.py +++ b/pandas/stats/tests/test_math.py @@ -1,4 +1,3 @@ -import unittest import nose from datetime import datetime @@ -26,7 +25,7 @@ _have_statsmodels = False -class TestMath(unittest.TestCase): +class TestMath(tm.TestCase): _nan_locs = np.arange(20, 40) _inf_locs = np.array([]) diff --git a/pandas/stats/tests/test_moments.py b/pandas/stats/tests/test_moments.py index 5c7112a2b0981..7381d4c1ae0b4 100644 --- a/pandas/stats/tests/test_moments.py +++ b/pandas/stats/tests/test_moments.py @@ -1,4 +1,3 @@ -import unittest import nose import sys import functools @@ -24,7 +23,7 @@ def _skip_if_no_scipy(): except ImportError: raise nose.SkipTest("no scipy.stats") -class TestMoments(unittest.TestCase): +class TestMoments(tm.TestCase): _multiprocess_can_split_ = True diff --git a/pandas/stats/tests/test_ols.py b/pandas/stats/tests/test_ols.py index 82f9db52d9445..476dec8c19435 100644 --- a/pandas/stats/tests/test_ols.py +++ b/pandas/stats/tests/test_ols.py @@ -69,7 +69,7 @@ class TestOLS(BaseTest): @classmethod def setUpClass(cls): - super(BaseTest, cls).setupClass() + super(TestOLS, cls).setUpClass() try: import matplotlib as mpl mpl.use('Agg', warn=False) @@ -260,8 +260,8 @@ class TestOLSMisc(tm.TestCase): For test coverage with faux data ''' @classmethod - def setupClass(cls): - super(BaseTest, cls).setupClass() + def setUpClass(cls): + super(TestOLSMisc, cls).setUpClass() if not _have_statsmodels: raise nose.SkipTest("no statsmodels") diff --git a/pandas/tests/test_algos.py b/pandas/tests/test_algos.py index 6458d7c31d689..2cbccbaf5c66b 100644 --- a/pandas/tests/test_algos.py +++ b/pandas/tests/test_algos.py @@ -1,5 +1,4 @@ from pandas.compat import range -import unittest import numpy as np @@ -10,7 +9,7 @@ import pandas.util.testing as tm -class TestMatch(unittest.TestCase): +class TestMatch(tm.TestCase): _multiprocess_can_split_ = True def test_ints(self): @@ -30,7 +29,7 @@ def test_strings(self): self.assert_(np.array_equal(result, expected)) -class TestUnique(unittest.TestCase): +class TestUnique(tm.TestCase): _multiprocess_can_split_ = True def test_ints(self): @@ -63,7 +62,7 @@ def test_on_index_object(self): tm.assert_almost_equal(result, expected) -class TestValueCounts(unittest.TestCase): +class TestValueCounts(tm.TestCase): _multiprocess_can_split_ = True def test_value_counts(self): @@ -86,7 +85,7 @@ def test_value_counts_bins(self): result = algos.value_counts(s, bins=2, sort=False) self.assertEqual(result.tolist(), [2, 2]) - self.assertEqual(result.index[0], 0.997) + self.assertEqual(result.index[0], 0.997) self.assertEqual(result.index[1], 2.5) def test_value_counts_dtypes(self): diff --git a/pandas/tests/test_base.py b/pandas/tests/test_base.py index 5d5a269b90428..3cb3528b6fff4 100644 --- a/pandas/tests/test_base.py +++ b/pandas/tests/test_base.py @@ -1,11 +1,10 @@ import re -import unittest import numpy as np import pandas.compat as compat from pandas.compat import u from pandas.core.base import FrozenList, FrozenNDArray from pandas.util.testing import assertRaisesRegexp, assert_isinstance - +import pandas.util.testing as tm class CheckStringMixin(object): def test_string_methods_dont_fail(self): @@ -63,7 +62,7 @@ def check_result(self, result, expected, klass=None): self.assertEqual(result, expected) -class TestFrozenList(CheckImmutable, CheckStringMixin, unittest.TestCase): +class TestFrozenList(CheckImmutable, CheckStringMixin, tm.TestCase): mutable_methods = ('extend', 'pop', 'remove', 'insert') unicode_container = FrozenList([u("\u05d0"), u("\u05d1"), "c"]) @@ -89,7 +88,7 @@ def test_inplace(self): self.check_result(r, self.lst) -class TestFrozenNDArray(CheckImmutable, CheckStringMixin, unittest.TestCase): +class TestFrozenNDArray(CheckImmutable, CheckStringMixin, tm.TestCase): mutable_methods = ('put', 'itemset', 'fill') unicode_container = FrozenNDArray([u("\u05d0"), u("\u05d1"), "c"]) diff --git a/pandas/tests/test_categorical.py b/pandas/tests/test_categorical.py index f41f6a9858b47..7f7af41b635b6 100644 --- a/pandas/tests/test_categorical.py +++ b/pandas/tests/test_categorical.py @@ -2,7 +2,6 @@ from datetime import datetime from pandas.compat import range, lrange, u -import unittest import nose import re @@ -17,7 +16,7 @@ import pandas.util.testing as tm -class TestCategorical(unittest.TestCase): +class TestCategorical(tm.TestCase): _multiprocess_can_split_ = True def setUp(self): diff --git a/pandas/tests/test_common.py b/pandas/tests/test_common.py index 7b4ea855f2f9d..2dd82870e697c 100644 --- a/pandas/tests/test_common.py +++ b/pandas/tests/test_common.py @@ -1,6 +1,5 @@ from datetime import datetime import re -import unittest import nose from nose.tools import assert_equal @@ -350,7 +349,7 @@ def test_ensure_int32(): assert(result.dtype == np.int32) -class TestEnsureNumeric(unittest.TestCase): +class TestEnsureNumeric(tm.TestCase): def test_numeric_values(self): # Test integer self.assertEqual(nanops._ensure_numeric(1), 1, 'Failed for int') @@ -457,7 +456,7 @@ def test_is_recompilable(): assert not com.is_re_compilable(f) -class TestTake(unittest.TestCase): +class TestTake(tm.TestCase): # standard incompatible fill error fill_error = re.compile("Incompatible type for fill_value") diff --git a/pandas/tests/test_expressions.py b/pandas/tests/test_expressions.py index 6284e4551e167..7d392586c159b 100644 --- a/pandas/tests/test_expressions.py +++ b/pandas/tests/test_expressions.py @@ -1,7 +1,6 @@ from __future__ import print_function # pylint: disable-msg=W0612,E1101 -import unittest import nose from numpy.random import randn @@ -48,7 +47,7 @@ _mixed2_panel = Panel(dict(ItemA=_mixed2, ItemB=(_mixed2 + 3))) -class TestExpressions(unittest.TestCase): +class TestExpressions(tm.TestCase): _multiprocess_can_split_ = False @@ -341,7 +340,6 @@ def testit(): testit() if __name__ == '__main__': - # unittest.main() import nose nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], exit=False) diff --git a/pandas/tests/test_format.py b/pandas/tests/test_format.py index 8e23176e9d005..7abe9b8be552e 100644 --- a/pandas/tests/test_format.py +++ b/pandas/tests/test_format.py @@ -6,7 +6,6 @@ import itertools import os import sys -import unittest from textwrap import dedent import warnings @@ -57,7 +56,7 @@ def has_expanded_repr(df): return False -class TestDataFrameFormatting(unittest.TestCase): +class TestDataFrameFormatting(tm.TestCase): _multiprocess_can_split_ = True def setUp(self): @@ -1622,7 +1621,7 @@ def test_to_latex(self): """ self.assertEqual(withoutindex_result, withoutindex_expected) -class TestSeriesFormatting(unittest.TestCase): +class TestSeriesFormatting(tm.TestCase): _multiprocess_can_split_ = True def setUp(self): @@ -1809,7 +1808,7 @@ def test_mixed_datetime64(self): self.assertTrue('2012-01-01' in result) -class TestEngFormatter(unittest.TestCase): +class TestEngFormatter(tm.TestCase): _multiprocess_can_split_ = True def test_eng_float_formatter(self): @@ -2014,7 +2013,7 @@ def _three_digit_exp(): return '%.4g' % 1.7e8 == '1.7e+008' -class TestFloatArrayFormatter(unittest.TestCase): +class TestFloatArrayFormatter(tm.TestCase): def test_misc(self): obj = fmt.FloatArrayFormatter(np.array([], dtype=np.float64)) diff --git a/pandas/tests/test_generic.py b/pandas/tests/test_generic.py index cf9b2d174faea..97e25f105db70 100644 --- a/pandas/tests/test_generic.py +++ b/pandas/tests/test_generic.py @@ -2,7 +2,6 @@ from datetime import datetime, timedelta import operator -import unittest import nose import numpy as np @@ -350,7 +349,7 @@ def test_head_tail(self): self._compare(o.head(-3), o.head(7)) self._compare(o.tail(-3), o.tail(7)) -class TestSeries(unittest.TestCase, Generic): +class TestSeries(tm.TestCase, Generic): _typ = Series _comparator = lambda self, x, y: assert_series_equal(x,y) @@ -576,7 +575,7 @@ def test_interp_nonmono_raise(self): with tm.assertRaises(ValueError): s.interpolate(method='krogh') -class TestDataFrame(unittest.TestCase, Generic): +class TestDataFrame(tm.TestCase, Generic): _typ = DataFrame _comparator = lambda self, x, y: assert_frame_equal(x,y) @@ -769,11 +768,41 @@ def test_spline(self): expected = Series([1, 2, 3, 4, 5, 6, 7]) assert_series_equal(result, expected) - -class TestPanel(unittest.TestCase, Generic): +class TestPanel(tm.TestCase, Generic): _typ = Panel _comparator = lambda self, x, y: assert_panel_equal(x, y) + +class TestNDFrame(tm.TestCase): + # tests that don't fit elsewhere + + def test_squeeze(self): + # noop + for s in [ tm.makeFloatSeries(), tm.makeStringSeries(), tm.makeObjectSeries() ]: + tm.assert_series_equal(s.squeeze(),s) + for df in [ tm.makeTimeDataFrame() ]: + tm.assert_frame_equal(df.squeeze(),df) + for p in [ tm.makePanel() ]: + tm.assert_panel_equal(p.squeeze(),p) + for p4d in [ tm.makePanel4D() ]: + tm.assert_panel4d_equal(p4d.squeeze(),p4d) + + # squeezing + df = tm.makeTimeDataFrame().reindex(columns=['A']) + tm.assert_series_equal(df.squeeze(),df['A']) + + p = tm.makePanel().reindex(items=['ItemA']) + tm.assert_frame_equal(p.squeeze(),p['ItemA']) + + p = tm.makePanel().reindex(items=['ItemA'],minor_axis=['A']) + tm.assert_series_equal(p.squeeze(),p.ix['ItemA',:,'A']) + + p4d = tm.makePanel4D().reindex(labels=['label1']) + tm.assert_panel_equal(p4d.squeeze(),p4d['label1']) + + p4d = tm.makePanel4D().reindex(labels=['label1'],items=['ItemA']) + tm.assert_frame_equal(p4d.squeeze(),p4d.ix['label1','ItemA']) + if __name__ == '__main__': nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], exit=False) diff --git a/pandas/tests/test_graphics.py b/pandas/tests/test_graphics.py index 8f48c2d5951f2..7c8b17fb14abe 100644 --- a/pandas/tests/test_graphics.py +++ b/pandas/tests/test_graphics.py @@ -1,7 +1,6 @@ import nose import os import string -import unittest from distutils.version import LooseVersion from datetime import datetime, date, timedelta @@ -30,7 +29,7 @@ def _skip_if_no_scipy(): @tm.mplskip -class TestSeriesPlots(unittest.TestCase): +class TestSeriesPlots(tm.TestCase): def setUp(self): import matplotlib as mpl self.mpl_le_1_2_1 = str(mpl.__version__) <= LooseVersion('1.2.1') @@ -351,7 +350,7 @@ def test_dup_datetime_index_plot(self): @tm.mplskip -class TestDataFramePlots(unittest.TestCase): +class TestDataFramePlots(tm.TestCase): def setUp(self): import matplotlib as mpl self.mpl_le_1_2_1 = str(mpl.__version__) <= LooseVersion('1.2.1') @@ -449,7 +448,7 @@ def test_plot_xy(self): # columns.inferred_type == 'mixed' # TODO add MultiIndex test - + @slow def test_xcompat(self): import pandas as pd @@ -540,10 +539,10 @@ def test_plot_scatter(self): df = DataFrame(randn(6, 4), index=list(string.ascii_letters[:6]), columns=['x', 'y', 'z', 'four']) - + _check_plot_works(df.plot, x='x', y='y', kind='scatter') _check_plot_works(df.plot, x=1, y=2, kind='scatter') - + with tm.assertRaises(ValueError): df.plot(x='x', kind='scatter') with tm.assertRaises(ValueError): @@ -946,7 +945,7 @@ def test_invalid_kind(self): @tm.mplskip -class TestDataFrameGroupByPlots(unittest.TestCase): +class TestDataFrameGroupByPlots(tm.TestCase): def tearDown(self): tm.close() diff --git a/pandas/tests/test_groupby.py b/pandas/tests/test_groupby.py index d9bdc3adcd041..76fee1702d64a 100644 --- a/pandas/tests/test_groupby.py +++ b/pandas/tests/test_groupby.py @@ -1,6 +1,5 @@ from __future__ import print_function import nose -import unittest from numpy.testing.decorators import slow @@ -49,7 +48,7 @@ def commonSetUp(self): index=self.dateRange) -class TestGroupBy(unittest.TestCase): +class TestGroupBy(tm.TestCase): _multiprocess_can_split_ = True diff --git a/pandas/tests/test_index.py b/pandas/tests/test_index.py index c3214a444ea3a..d102ac999cab0 100644 --- a/pandas/tests/test_index.py +++ b/pandas/tests/test_index.py @@ -5,7 +5,6 @@ import operator import pickle import re -import unittest import nose import warnings import os @@ -34,7 +33,7 @@ from pandas import _np_version_under1p7 -class TestIndex(unittest.TestCase): +class TestIndex(tm.TestCase): _multiprocess_can_split_ = True def setUp(self): @@ -691,7 +690,7 @@ def test_join_self(self): self.assert_(res is joined) -class TestFloat64Index(unittest.TestCase): +class TestFloat64Index(tm.TestCase): _multiprocess_can_split_ = True def setUp(self): @@ -784,7 +783,7 @@ def test_astype(self): self.check_is_index(result) -class TestInt64Index(unittest.TestCase): +class TestInt64Index(tm.TestCase): _multiprocess_can_split_ = True def setUp(self): @@ -1203,7 +1202,7 @@ def test_slice_keep_name(self): self.assertEqual(idx.name, idx[1:].name) -class TestMultiIndex(unittest.TestCase): +class TestMultiIndex(tm.TestCase): _multiprocess_can_split_ = True def setUp(self): diff --git a/pandas/tests/test_indexing.py b/pandas/tests/test_indexing.py index 8baf2b43a22c4..44160609235df 100644 --- a/pandas/tests/test_indexing.py +++ b/pandas/tests/test_indexing.py @@ -1,5 +1,4 @@ # pylint: disable-msg=W0612,E1101 -import unittest import nose import itertools import warnings @@ -84,7 +83,7 @@ def _axify(obj, key, axis): return k -class TestIndexing(unittest.TestCase): +class TestIndexing(tm.TestCase): _multiprocess_can_split_ = True diff --git a/pandas/tests/test_internals.py b/pandas/tests/test_internals.py index b0a64d282e814..701b240479a62 100644 --- a/pandas/tests/test_internals.py +++ b/pandas/tests/test_internals.py @@ -1,6 +1,5 @@ # pylint: disable=W0102 -import unittest import nose import numpy as np @@ -88,7 +87,7 @@ def create_singleblockmanager(blocks): return SingleBlockManager(blocks, [items]) -class TestBlock(unittest.TestCase): +class TestBlock(tm.TestCase): _multiprocess_can_split_ = True @@ -234,7 +233,7 @@ def test_repr(self): pass -class TestBlockManager(unittest.TestCase): +class TestBlockManager(tm.TestCase): _multiprocess_can_split_ = True @@ -586,9 +585,6 @@ def test_missing_unicode_key(self): pass # this is the expected exception if __name__ == '__main__': - # unittest.main() import nose - # nose.runmodule(argv=[__file__,'-vvs','-x', '--pdb-failure'], - # exit=False) nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], exit=False) diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py index bd431843a6b20..151f222d7357a 100644 --- a/pandas/tests/test_multilevel.py +++ b/pandas/tests/test_multilevel.py @@ -1,6 +1,5 @@ # pylint: disable-msg=W0612,E1101,W0141 import nose -import unittest from numpy.random import randn import numpy as np @@ -21,7 +20,7 @@ import pandas.index as _index -class TestMultiLevel(unittest.TestCase): +class TestMultiLevel(tm.TestCase): _multiprocess_can_split_ = True @@ -1860,9 +1859,6 @@ def test_multiindex_set_index(self): if __name__ == '__main__': - # unittest.main() import nose - # nose.runmodule(argv=[__file__,'-vvs','-x', '--pdb-failure'], - # exit=False) nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], exit=False) diff --git a/pandas/tests/test_ndframe.py b/pandas/tests/test_ndframe.py deleted file mode 100644 index edafeb64af98e..0000000000000 --- a/pandas/tests/test_ndframe.py +++ /dev/null @@ -1,47 +0,0 @@ -import unittest - -import numpy as np - -from pandas.core.generic import NDFrame -import pandas.util.testing as t - - -class TestNDFrame(unittest.TestCase): - - _multiprocess_can_split_ = True - - def setUp(self): - tdf = t.makeTimeDataFrame() - self.ndf = NDFrame(tdf._data) - - def test_squeeze(self): - # noop - for s in [ t.makeFloatSeries(), t.makeStringSeries(), t.makeObjectSeries() ]: - t.assert_series_equal(s.squeeze(),s) - for df in [ t.makeTimeDataFrame() ]: - t.assert_frame_equal(df.squeeze(),df) - for p in [ t.makePanel() ]: - t.assert_panel_equal(p.squeeze(),p) - for p4d in [ t.makePanel4D() ]: - t.assert_panel4d_equal(p4d.squeeze(),p4d) - - # squeezing - df = t.makeTimeDataFrame().reindex(columns=['A']) - t.assert_series_equal(df.squeeze(),df['A']) - - p = t.makePanel().reindex(items=['ItemA']) - t.assert_frame_equal(p.squeeze(),p['ItemA']) - - p = t.makePanel().reindex(items=['ItemA'],minor_axis=['A']) - t.assert_series_equal(p.squeeze(),p.ix['ItemA',:,'A']) - - p4d = t.makePanel4D().reindex(labels=['label1']) - t.assert_panel_equal(p4d.squeeze(),p4d['label1']) - - p4d = t.makePanel4D().reindex(labels=['label1'],items=['ItemA']) - t.assert_frame_equal(p4d.squeeze(),p4d.ix['label1','ItemA']) - -if __name__ == '__main__': - import nose - nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], - exit=False) diff --git a/pandas/tests/test_panel.py b/pandas/tests/test_panel.py index 96f14a09180ed..1122b4c7dcfb4 100644 --- a/pandas/tests/test_panel.py +++ b/pandas/tests/test_panel.py @@ -2,7 +2,6 @@ from datetime import datetime import operator -import unittest import nose import numpy as np @@ -811,7 +810,7 @@ def test_set_value(self): tm.add_nans(_panel) -class TestPanel(unittest.TestCase, PanelTests, CheckIndexing, +class TestPanel(tm.TestCase, PanelTests, CheckIndexing, SafeForLongAndSparse, SafeForSparse): _multiprocess_can_split_ = True @@ -1782,7 +1781,7 @@ def test_update_raise(self): **{'raise_conflict': True}) -class TestLongPanel(unittest.TestCase): +class TestLongPanel(tm.TestCase): """ LongPanel no longer exists, but... """ diff --git a/pandas/tests/test_panel4d.py b/pandas/tests/test_panel4d.py index 4d5d29e08fa9f..ea6602dbb0be6 100644 --- a/pandas/tests/test_panel4d.py +++ b/pandas/tests/test_panel4d.py @@ -2,7 +2,6 @@ from pandas.compat import range, lrange import os import operator -import unittest import nose import numpy as np @@ -543,7 +542,7 @@ def test_set_value(self): self.assert_(com.is_float_dtype(res3['l4'].values)) -class TestPanel4d(unittest.TestCase, CheckIndexing, SafeForSparse, +class TestPanel4d(tm.TestCase, CheckIndexing, SafeForSparse, SafeForLongAndSparse): _multiprocess_can_split_ = True diff --git a/pandas/tests/test_panelnd.py b/pandas/tests/test_panelnd.py index 3c86998c5630a..92083afb38f41 100644 --- a/pandas/tests/test_panelnd.py +++ b/pandas/tests/test_panelnd.py @@ -1,7 +1,6 @@ from datetime import datetime import os import operator -import unittest import nose import numpy as np @@ -19,7 +18,7 @@ import pandas.util.testing as tm -class TestPanelnd(unittest.TestCase): +class TestPanelnd(tm.TestCase): def setUp(self): pass diff --git a/pandas/tests/test_reshape.py b/pandas/tests/test_reshape.py index c4e75fcb41d45..c6eb9739cf3d2 100644 --- a/pandas/tests/test_reshape.py +++ b/pandas/tests/test_reshape.py @@ -3,7 +3,6 @@ from datetime import datetime, timedelta import operator import os -import unittest import nose @@ -23,7 +22,7 @@ _multiprocess_can_split_ = True -class TestMelt(unittest.TestCase): +class TestMelt(tm.TestCase): def setUp(self): self.df = tm.makeTimeDataFrame()[:10] @@ -148,7 +147,7 @@ def test_multiindex(self): self.assertEqual(res.columns.tolist(), ['CAP', 'low', 'value']) -class TestGetDummies(unittest.TestCase): +class TestGetDummies(tm.TestCase): def test_basic(self): s_list = list('abc') s_series = Series(s_list) @@ -199,7 +198,7 @@ def test_include_na(self): exp_just_na = DataFrame(Series(1.0,index=[0]),columns=[nan]) assert_array_equal(res_just_na.values, exp_just_na.values) -class TestConvertDummies(unittest.TestCase): +class TestConvertDummies(tm.TestCase): def test_convert_dummies(self): df = DataFrame({'A': ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], @@ -225,7 +224,7 @@ def test_convert_dummies(self): tm.assert_frame_equal(result2, expected2) -class TestLreshape(unittest.TestCase): +class TestLreshape(tm.TestCase): def test_pairs(self): data = {'birthdt': ['08jan2009', '20dec2008', '30dec2008', diff --git a/pandas/tests/test_rplot.py b/pandas/tests/test_rplot.py index d59b182b77d4c..ddfce477a320d 100644 --- a/pandas/tests/test_rplot.py +++ b/pandas/tests/test_rplot.py @@ -1,5 +1,4 @@ from pandas.compat import range -import unittest import pandas.tools.rplot as rplot import pandas.util.testing as tm from pandas import read_csv @@ -33,7 +32,7 @@ def between(a, b, x): @tm.mplskip -class TestUtilityFunctions(unittest.TestCase): +class TestUtilityFunctions(tm.TestCase): """ Tests for RPlot utility functions. """ @@ -102,7 +101,7 @@ def test_sequence_layers(self): @tm.mplskip -class TestTrellis(unittest.TestCase): +class TestTrellis(tm.TestCase): def setUp(self): path = os.path.join(curpath(), 'data/tips.csv') self.data = read_csv(path, sep=',') @@ -150,7 +149,7 @@ def test_trellis_cols_rows(self): @tm.mplskip -class TestScaleGradient(unittest.TestCase): +class TestScaleGradient(tm.TestCase): def setUp(self): path = os.path.join(curpath(), 'data/iris.csv') self.data = read_csv(path, sep=',') @@ -170,7 +169,7 @@ def test_gradient(self): @tm.mplskip -class TestScaleGradient2(unittest.TestCase): +class TestScaleGradient2(tm.TestCase): def setUp(self): path = os.path.join(curpath(), 'data/iris.csv') self.data = read_csv(path, sep=',') @@ -198,7 +197,7 @@ def test_gradient2(self): @tm.mplskip -class TestScaleRandomColour(unittest.TestCase): +class TestScaleRandomColour(tm.TestCase): def setUp(self): path = os.path.join(curpath(), 'data/iris.csv') self.data = read_csv(path, sep=',') @@ -218,7 +217,7 @@ def test_random_colour(self): @tm.mplskip -class TestScaleConstant(unittest.TestCase): +class TestScaleConstant(tm.TestCase): def test_scale_constant(self): scale = rplot.ScaleConstant(1.0) self.assertEqual(scale(None, None), 1.0) @@ -226,7 +225,7 @@ def test_scale_constant(self): self.assertEqual(scale(None, None), "test") -class TestScaleSize(unittest.TestCase): +class TestScaleSize(tm.TestCase): def setUp(self): path = os.path.join(curpath(), 'data/iris.csv') self.data = read_csv(path, sep=',') @@ -247,7 +246,7 @@ def f(): @tm.mplskip -class TestRPlot(unittest.TestCase): +class TestRPlot(tm.TestCase): def test_rplot1(self): import matplotlib.pyplot as plt path = os.path.join(curpath(), 'data/tips.csv') @@ -295,4 +294,5 @@ def test_rplot_iris(self): if __name__ == '__main__': + import unittest unittest.main() diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py index 5a6f790d5851e..0f67fce8b3314 100644 --- a/pandas/tests/test_series.py +++ b/pandas/tests/test_series.py @@ -2,7 +2,6 @@ from datetime import datetime, timedelta import operator -import unittest import string from itertools import product, starmap from distutils.version import LooseVersion @@ -246,7 +245,7 @@ def test_to_sparse_pass_name(self): self.assertEquals(result.name, self.ts.name) -class TestNanops(unittest.TestCase): +class TestNanops(tm.TestCase): _multiprocess_can_split_ = True @@ -298,7 +297,7 @@ class SafeForSparse(object): _ts = tm.makeTimeSeries() -class TestSeries(unittest.TestCase, CheckNameIntegration): +class TestSeries(tm.TestCase, CheckNameIntegration): _multiprocess_can_split_ = True @@ -5336,7 +5335,7 @@ def test_numpy_unique(self): result = np.unique(self.ts) -class TestSeriesNonUnique(unittest.TestCase): +class TestSeriesNonUnique(tm.TestCase): _multiprocess_can_split_ = True diff --git a/pandas/tests/test_stats.py b/pandas/tests/test_stats.py index e3533afc71e95..7e2144e801122 100644 --- a/pandas/tests/test_stats.py +++ b/pandas/tests/test_stats.py @@ -1,6 +1,5 @@ from pandas import compat import nose -import unittest from numpy import nan import numpy as np @@ -11,9 +10,10 @@ from pandas.util.testing import (assert_frame_equal, assert_series_equal, assert_almost_equal) +import pandas.util.testing as tm -class TestRank(unittest.TestCase): +class TestRank(tm.TestCase): _multiprocess_can_split_ = True s = Series([1, 3, 4, 2, nan, 2, 1, 5, nan, 3]) df = DataFrame({'A': s, 'B': s}) diff --git a/pandas/tests/test_strings.py b/pandas/tests/test_strings.py index c75fec44c9f24..15193e44bd5cf 100644 --- a/pandas/tests/test_strings.py +++ b/pandas/tests/test_strings.py @@ -4,7 +4,6 @@ import os import operator import re -import unittest import warnings import nose @@ -26,7 +25,7 @@ import pandas.core.strings as strings -class TestStringMethods(unittest.TestCase): +class TestStringMethods(tm.TestCase): _multiprocess_can_split_ = True @@ -480,7 +479,7 @@ def test_extract(self): tm.assert_frame_equal(result, exp) # no groups - s = Series(['A1', 'B2', 'C3']) + s = Series(['A1', 'B2', 'C3']) f = lambda: s.str.extract('[ABC][123]') self.assertRaises(ValueError, f) @@ -492,7 +491,7 @@ def test_extract(self): result = s.str.extract('(_)') exp = Series([NA, NA, NA]) tm.assert_series_equal(result, exp) - + # two groups, no matches result = s.str.extract('(_)(_)') exp = DataFrame([[NA, NA], [NA, NA], [NA, NA]]) diff --git a/pandas/tests/test_tseries.py b/pandas/tests/test_tseries.py index c1eda35417fd7..7215b9dbf934b 100644 --- a/pandas/tests/test_tseries.py +++ b/pandas/tests/test_tseries.py @@ -1,17 +1,15 @@ -import unittest from numpy import nan import numpy as np from pandas import Index, isnull, Timestamp from pandas.util.testing import assert_almost_equal -import pandas.util.testing as common +import pandas.util.testing as tm from pandas.compat import range, lrange, zip import pandas.lib as lib import pandas.algos as algos from datetime import datetime - -class TestTseriesUtil(unittest.TestCase): +class TestTseriesUtil(tm.TestCase): _multiprocess_can_split_ = True def test_combineFunc(self): @@ -421,7 +419,7 @@ def test_series_bin_grouper(): assert_almost_equal(counts, exp_counts) -class TestBinGroupers(unittest.TestCase): +class TestBinGroupers(tm.TestCase): _multiprocess_can_split_ = True def setUp(self): @@ -560,7 +558,7 @@ def test_try_parse_dates(): assert(np.array_equal(result, expected)) -class TestTypeInference(unittest.TestCase): +class TestTypeInference(tm.TestCase): _multiprocess_can_split_ = True def test_length_zero(self): @@ -653,11 +651,11 @@ def test_to_object_array_tuples(self): pass -class TestMoments(unittest.TestCase): +class TestMoments(tm.TestCase): pass -class TestReducer(unittest.TestCase): +class TestReducer(tm.TestCase): def test_int_index(self): from pandas.core.series import Series @@ -685,7 +683,7 @@ def test_int_index(self): assert_almost_equal(result, expected) -class TestTsUtil(unittest.TestCase): +class TestTsUtil(tm.TestCase): def test_min_valid(self): # Ensure that Timestamp.min is a valid Timestamp Timestamp(Timestamp.min) @@ -700,7 +698,7 @@ def test_to_datetime_bijective(self): self.assertEqual(Timestamp(Timestamp.max.to_pydatetime()).value/1000, Timestamp.max.value/1000) self.assertEqual(Timestamp(Timestamp.min.to_pydatetime()).value/1000, Timestamp.min.value/1000) -class TestPeriodField(unittest.TestCase): +class TestPeriodField(tm.TestCase): def test_get_period_field_raises_on_out_of_range(self): from pandas import tslib diff --git a/pandas/tools/tests/test_merge.py b/pandas/tools/tests/test_merge.py index eec134ebeb990..e3b448b650767 100644 --- a/pandas/tools/tests/test_merge.py +++ b/pandas/tools/tests/test_merge.py @@ -1,7 +1,6 @@ # pylint: disable=E1103 import nose -import unittest from datetime import datetime from numpy.random import randn @@ -39,7 +38,7 @@ def get_test_data(ngroups=NGROUPS, n=N): return arr -class TestMerge(unittest.TestCase): +class TestMerge(tm.TestCase): _multiprocess_can_split_ = True @@ -818,7 +817,7 @@ def _check_merge(x, y): assert_frame_equal(result, expected, check_names=False) # TODO check_names on merge? -class TestMergeMulti(unittest.TestCase): +class TestMergeMulti(tm.TestCase): def setUp(self): self.index = MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'], @@ -1082,7 +1081,7 @@ def _join_by_hand(a, b, how='left'): return a_re.reindex(columns=result_columns) -class TestConcatenate(unittest.TestCase): +class TestConcatenate(tm.TestCase): _multiprocess_can_split_ = True @@ -1840,7 +1839,7 @@ def test_concat_mixed_types_fails(self): with tm.assertRaisesRegexp(TypeError, "Cannot concatenate.+"): concat([df, df[0]], axis=1) -class TestOrderedMerge(unittest.TestCase): +class TestOrderedMerge(tm.TestCase): def setUp(self): self.left = DataFrame({'key': ['a', 'c', 'e'], diff --git a/pandas/tools/tests/test_pivot.py b/pandas/tools/tests/test_pivot.py index 6c18b6582c4cc..0ede6bd2bd46d 100644 --- a/pandas/tools/tests/test_pivot.py +++ b/pandas/tools/tests/test_pivot.py @@ -1,5 +1,4 @@ import datetime -import unittest import numpy as np from numpy.testing import assert_equal @@ -12,7 +11,7 @@ import pandas.util.testing as tm -class TestPivotTable(unittest.TestCase): +class TestPivotTable(tm.TestCase): _multiprocess_can_split_ = True @@ -320,7 +319,7 @@ def test_margins_no_values_two_row_two_cols(self): self.assertEqual(result.All.tolist(), [3.0, 1.0, 4.0, 3.0, 11.0]) -class TestCrosstab(unittest.TestCase): +class TestCrosstab(tm.TestCase): def setUp(self): df = DataFrame({'A': ['foo', 'foo', 'foo', 'foo', diff --git a/pandas/tools/tests/test_tile.py b/pandas/tools/tests/test_tile.py index 3200f336376af..ba51946173d5f 100644 --- a/pandas/tools/tests/test_tile.py +++ b/pandas/tools/tests/test_tile.py @@ -1,6 +1,5 @@ import os import nose -import unittest import numpy as np from pandas.compat import zip @@ -17,7 +16,7 @@ from numpy.testing import assert_equal, assert_almost_equal -class TestCut(unittest.TestCase): +class TestCut(tm.TestCase): def test_simple(self): data = np.ones(5) @@ -120,9 +119,9 @@ def test_inf_handling(self): result = cut(data, [-np.inf, 2, 4, np.inf]) result_ser = cut(data_ser, [-np.inf, 2, 4, np.inf]) - + ex_levels = ['(-inf, 2]', '(2, 4]', '(4, inf]'] - + np.testing.assert_array_equal(result.levels, ex_levels) np.testing.assert_array_equal(result_ser.levels, ex_levels) self.assertEquals(result[5], '(4, inf]') diff --git a/pandas/tools/tests/test_tools.py b/pandas/tools/tests/test_tools.py index b57ff68c97e3d..2c70427f79559 100644 --- a/pandas/tools/tests/test_tools.py +++ b/pandas/tools/tests/test_tools.py @@ -1,22 +1,23 @@ -# import unittest - from pandas import DataFrame from pandas.tools.describe import value_range import numpy as np +import pandas.util.testing as tm + +class TestTools(tm.TestCase): -def test_value_range(): - df = DataFrame(np.random.randn(5, 5)) - df.ix[0, 2] = -5 - df.ix[2, 0] = 5 + def test_value_range(self): + df = DataFrame(np.random.randn(5, 5)) + df.ix[0, 2] = -5 + df.ix[2, 0] = 5 - res = value_range(df) + res = value_range(df) - assert(res['Minimum'] == -5) - assert(res['Maximum'] == 5) + self.assert_(res['Minimum'] == -5) + self.assert_(res['Maximum'] == 5) - df.ix[0, 1] = np.NaN + df.ix[0, 1] = np.NaN - assert(res['Minimum'] == -5) - assert(res['Maximum'] == 5) + self.assert_(res['Minimum'] == -5) + self.assert_(res['Maximum'] == 5) diff --git a/pandas/tools/tests/test_util.py b/pandas/tools/tests/test_util.py index 183bf2afb85ad..36cfb4870a8fe 100644 --- a/pandas/tools/tests/test_util.py +++ b/pandas/tools/tests/test_util.py @@ -28,7 +28,7 @@ class TestLocaleUtils(tm.TestCase): @classmethod def setUpClass(cls): - super(TestLocaleUtils, cls).setupClass() + super(TestLocaleUtils, cls).setUpClass() cls.locales = tm.get_locales() if not cls.locales: diff --git a/pandas/tseries/tests/test_converter.py b/pandas/tseries/tests/test_converter.py index 7cb84b5134a9a..29137f9cb3e50 100644 --- a/pandas/tseries/tests/test_converter.py +++ b/pandas/tseries/tests/test_converter.py @@ -1,12 +1,12 @@ from datetime import datetime, time, timedelta, date import sys import os -import unittest import nose import numpy as np from pandas.compat import u +import pandas.util.testing as tm try: import pandas.tseries.converter as converter @@ -18,7 +18,7 @@ def test_timtetonum_accepts_unicode(): assert(converter.time2num("00:01") == converter.time2num(u("00:01"))) -class TestDateTimeConverter(unittest.TestCase): +class TestDateTimeConverter(tm.TestCase): def setUp(self): self.dtc = converter.DatetimeConverter() diff --git a/pandas/tseries/tests/test_cursor.py b/pandas/tseries/tests/test_cursor.py deleted file mode 100644 index fc02a83cbe639..0000000000000 --- a/pandas/tseries/tests/test_cursor.py +++ /dev/null @@ -1,196 +0,0 @@ - -""" - -class TestNewOffsets(unittest.TestCase): - - def test_yearoffset(self): - off = lib.YearOffset(dayoffset=0, biz=0, anchor=datetime(2002,1,1)) - - for i in range(500): - t = lib.Timestamp(off.ts) - self.assert_(t.day == 1) - self.assert_(t.month == 1) - self.assert_(t.year == 2002 + i) - next(off) - - for i in range(499, -1, -1): - off.prev() - t = lib.Timestamp(off.ts) - self.assert_(t.day == 1) - self.assert_(t.month == 1) - self.assert_(t.year == 2002 + i) - - off = lib.YearOffset(dayoffset=-1, biz=0, anchor=datetime(2002,1,1)) - - for i in range(500): - t = lib.Timestamp(off.ts) - self.assert_(t.month == 12) - self.assert_(t.day == 31) - self.assert_(t.year == 2001 + i) - next(off) - - for i in range(499, -1, -1): - off.prev() - t = lib.Timestamp(off.ts) - self.assert_(t.month == 12) - self.assert_(t.day == 31) - self.assert_(t.year == 2001 + i) - - off = lib.YearOffset(dayoffset=-1, biz=-1, anchor=datetime(2002,1,1)) - - stack = [] - - for i in range(500): - t = lib.Timestamp(off.ts) - stack.append(t) - self.assert_(t.month == 12) - self.assert_(t.day == 31 or t.day == 30 or t.day == 29) - self.assert_(t.year == 2001 + i) - self.assert_(t.weekday() < 5) - next(off) - - for i in range(499, -1, -1): - off.prev() - t = lib.Timestamp(off.ts) - self.assert_(t == stack.pop()) - self.assert_(t.month == 12) - self.assert_(t.day == 31 or t.day == 30 or t.day == 29) - self.assert_(t.year == 2001 + i) - self.assert_(t.weekday() < 5) - - def test_monthoffset(self): - off = lib.MonthOffset(dayoffset=0, biz=0, anchor=datetime(2002,1,1)) - - for i in range(12): - t = lib.Timestamp(off.ts) - self.assert_(t.day == 1) - self.assert_(t.month == 1 + i) - self.assert_(t.year == 2002) - next(off) - - for i in range(11, -1, -1): - off.prev() - t = lib.Timestamp(off.ts) - self.assert_(t.day == 1) - self.assert_(t.month == 1 + i) - self.assert_(t.year == 2002) - - off = lib.MonthOffset(dayoffset=-1, biz=0, anchor=datetime(2002,1,1)) - - for i in range(12): - t = lib.Timestamp(off.ts) - self.assert_(t.day >= 28) - self.assert_(t.month == (12 if i == 0 else i)) - self.assert_(t.year == 2001 + (i != 0)) - next(off) - - for i in range(11, -1, -1): - off.prev() - t = lib.Timestamp(off.ts) - self.assert_(t.day >= 28) - self.assert_(t.month == (12 if i == 0 else i)) - self.assert_(t.year == 2001 + (i != 0)) - - off = lib.MonthOffset(dayoffset=-1, biz=-1, anchor=datetime(2002,1,1)) - - stack = [] - - for i in range(500): - t = lib.Timestamp(off.ts) - stack.append(t) - if t.month != 2: - self.assert_(t.day >= 28) - else: - self.assert_(t.day >= 26) - self.assert_(t.weekday() < 5) - next(off) - - for i in range(499, -1, -1): - off.prev() - t = lib.Timestamp(off.ts) - self.assert_(t == stack.pop()) - if t.month != 2: - self.assert_(t.day >= 28) - else: - self.assert_(t.day >= 26) - self.assert_(t.weekday() < 5) - - for i in (-2, -1, 1, 2): - for j in (-1, 0, 1): - off1 = lib.MonthOffset(dayoffset=i, biz=j, stride=12, - anchor=datetime(2002,1,1)) - off2 = lib.YearOffset(dayoffset=i, biz=j, - anchor=datetime(2002,1,1)) - - for k in range(500): - self.assert_(off1.ts == off2.ts) - next(off1) - next(off2) - - for k in range(500): - self.assert_(off1.ts == off2.ts) - off1.prev() - off2.prev() - - def test_dayoffset(self): - off = lib.DayOffset(biz=0, anchor=datetime(2002,1,1)) - - us_in_day = 1e6 * 60 * 60 * 24 - - t0 = lib.Timestamp(off.ts) - for i in range(500): - next(off) - t1 = lib.Timestamp(off.ts) - self.assert_(t1.value - t0.value == us_in_day) - t0 = t1 - - t0 = lib.Timestamp(off.ts) - for i in range(499, -1, -1): - off.prev() - t1 = lib.Timestamp(off.ts) - self.assert_(t0.value - t1.value == us_in_day) - t0 = t1 - - off = lib.DayOffset(biz=1, anchor=datetime(2002,1,1)) - - t0 = lib.Timestamp(off.ts) - for i in range(500): - next(off) - t1 = lib.Timestamp(off.ts) - self.assert_(t1.weekday() < 5) - self.assert_(t1.value - t0.value == us_in_day or - t1.value - t0.value == 3 * us_in_day) - t0 = t1 - - t0 = lib.Timestamp(off.ts) - for i in range(499, -1, -1): - off.prev() - t1 = lib.Timestamp(off.ts) - self.assert_(t1.weekday() < 5) - self.assert_(t0.value - t1.value == us_in_day or - t0.value - t1.value == 3 * us_in_day) - t0 = t1 - - - def test_dayofmonthoffset(self): - for week in (-1, 0, 1): - for day in (0, 2, 4): - off = lib.DayOfMonthOffset(week=-1, day=day, - anchor=datetime(2002,1,1)) - - stack = [] - - for i in range(500): - t = lib.Timestamp(off.ts) - stack.append(t) - self.assert_(t.weekday() == day) - next(off) - - for i in range(499, -1, -1): - off.prev() - t = lib.Timestamp(off.ts) - self.assert_(t == stack.pop()) - self.assert_(t.weekday() == day) - - -""" diff --git a/pandas/tseries/tests/test_daterange.py b/pandas/tseries/tests/test_daterange.py index 3b40e75194d11..0af3b6281530b 100644 --- a/pandas/tseries/tests/test_daterange.py +++ b/pandas/tseries/tests/test_daterange.py @@ -1,7 +1,6 @@ from datetime import datetime from pandas.compat import range import pickle -import unittest import nose import numpy as np @@ -39,7 +38,7 @@ def eq_gen_range(kwargs, expected): START, END = datetime(2009, 1, 1), datetime(2010, 1, 1) -class TestGenRangeGeneration(unittest.TestCase): +class TestGenRangeGeneration(tm.TestCase): def test_generate(self): rng1 = list(generate_range(START, END, offset=datetools.bday)) rng2 = list(generate_range(START, END, time_rule='B')) @@ -68,7 +67,7 @@ def test_3(self): []) -class TestDateRange(unittest.TestCase): +class TestDateRange(tm.TestCase): def setUp(self): self.rng = bdate_range(START, END) @@ -410,7 +409,7 @@ def test_range_closed(self): self.assert_(expected_right.equals(right)) -class TestCustomDateRange(unittest.TestCase): +class TestCustomDateRange(tm.TestCase): def setUp(self): _skip_if_no_cday() diff --git a/pandas/tseries/tests/test_frequencies.py b/pandas/tseries/tests/test_frequencies.py index f1078f44efd13..ad9c93592a26c 100644 --- a/pandas/tseries/tests/test_frequencies.py +++ b/pandas/tseries/tests/test_frequencies.py @@ -2,7 +2,6 @@ from pandas.compat import range import sys import os -import unittest import nose @@ -18,7 +17,7 @@ import pandas.lib as lib from pandas import _np_version_under1p7 - +import pandas.util.testing as tm def test_to_offset_multiple(): freqstr = '2h30min' @@ -87,7 +86,7 @@ def test_anchored_shortcuts(): _dti = DatetimeIndex -class TestFrequencyInference(unittest.TestCase): +class TestFrequencyInference(tm.TestCase): def test_raise_if_too_few(self): index = _dti(['12/31/1998', '1/3/1999']) @@ -159,7 +158,7 @@ def test_week_of_month(self): for day in days: for i in range(1, 5): self._check_generated_range('1/1/2000', 'WOM-%d%s' % (i, day)) - + def test_week_of_month_fake(self): #All of these dates are on same day of week and are 4 or 5 weeks apart index = DatetimeIndex(["2013-08-27","2013-10-01","2013-10-29","2013-11-26"]) diff --git a/pandas/tseries/tests/test_offsets.py b/pandas/tseries/tests/test_offsets.py index 008bda0a676bf..047bd244fef93 100644 --- a/pandas/tseries/tests/test_offsets.py +++ b/pandas/tseries/tests/test_offsets.py @@ -2,7 +2,6 @@ from dateutil.relativedelta import relativedelta from pandas.compat import range from pandas import compat -import unittest import nose from nose.tools import assert_raises @@ -95,7 +94,7 @@ def test_to_m8(): ### DateOffset Tests ##### -class TestBase(unittest.TestCase): +class TestBase(tm.TestCase): _offset = None def test_apply_out_of_range(self): @@ -1304,25 +1303,25 @@ def test_get_year_end(self): self.assertEqual(makeFY5253NearestEndMonth(startingMonth=8, weekday=WeekDay.SUN).get_year_end(datetime(2013,1,1)), datetime(2013,9,1)) self.assertEqual(makeFY5253NearestEndMonth(startingMonth=8, weekday=WeekDay.FRI).get_year_end(datetime(2013,1,1)), datetime(2013,8,30)) - offset_n = FY5253(weekday=WeekDay.TUE, startingMonth=12, + offset_n = FY5253(weekday=WeekDay.TUE, startingMonth=12, variation="nearest") self.assertEqual(offset_n.get_year_end(datetime(2012,1,1)), datetime(2013,1,1)) self.assertEqual(offset_n.get_year_end(datetime(2012,1,10)), datetime(2013,1,1)) - - self.assertEqual(offset_n.get_year_end(datetime(2013,1,1)), datetime(2013,12,31)) - self.assertEqual(offset_n.get_year_end(datetime(2013,1,2)), datetime(2013,12,31)) - self.assertEqual(offset_n.get_year_end(datetime(2013,1,3)), datetime(2013,12,31)) + + self.assertEqual(offset_n.get_year_end(datetime(2013,1,1)), datetime(2013,12,31)) + self.assertEqual(offset_n.get_year_end(datetime(2013,1,2)), datetime(2013,12,31)) + self.assertEqual(offset_n.get_year_end(datetime(2013,1,3)), datetime(2013,12,31)) self.assertEqual(offset_n.get_year_end(datetime(2013,1,10)), datetime(2013,12,31)) - + JNJ = FY5253(n=1, startingMonth=12, weekday=6, variation="nearest") self.assertEqual(JNJ.get_year_end(datetime(2006, 1, 1)), datetime(2006, 12, 31)) - + def test_onOffset(self): offset_lom_aug_sat = makeFY5253NearestEndMonth(1, startingMonth=8, weekday=WeekDay.SAT) offset_lom_aug_thu = makeFY5253NearestEndMonth(1, startingMonth=8, weekday=WeekDay.THU) - offset_n = FY5253(weekday=WeekDay.TUE, startingMonth=12, + offset_n = FY5253(weekday=WeekDay.TUE, startingMonth=12, variation="nearest") - + tests = [ # From Wikipedia (see: http://en.wikipedia.org/wiki/4%E2%80%934%E2%80%935_calendar#Saturday_nearest_the_end_of_month) # 2006-09-02 2006 September 2 @@ -1369,7 +1368,7 @@ def test_onOffset(self): #From Micron, see: http://google.brand.edgar-online.com/?sym=MU&formtypeID=7 (offset_lom_aug_thu, datetime(2012, 8, 30), True), (offset_lom_aug_thu, datetime(2011, 9, 1), True), - + (offset_n, datetime(2012, 12, 31), False), (offset_n, datetime(2013, 1, 1), True), (offset_n, datetime(2013, 1, 2), False), @@ -1379,16 +1378,16 @@ def test_onOffset(self): assertOnOffset(offset, date, expected) def test_apply(self): - date_seq_nem_8_sat = [datetime(2006, 9, 2), datetime(2007, 9, 1), - datetime(2008, 8, 30), datetime(2009, 8, 29), + date_seq_nem_8_sat = [datetime(2006, 9, 2), datetime(2007, 9, 1), + datetime(2008, 8, 30), datetime(2009, 8, 29), datetime(2010, 8, 28), datetime(2011, 9, 3)] - - JNJ = [datetime(2005, 1, 2), datetime(2006, 1, 1), - datetime(2006, 12, 31), datetime(2007, 12, 30), - datetime(2008, 12, 28), datetime(2010, 1, 3), - datetime(2011, 1, 2), datetime(2012, 1, 1), + + JNJ = [datetime(2005, 1, 2), datetime(2006, 1, 1), + datetime(2006, 12, 31), datetime(2007, 12, 30), + datetime(2008, 12, 28), datetime(2010, 1, 3), + datetime(2011, 1, 2), datetime(2012, 1, 1), datetime(2012, 12, 30)] - + DEC_SAT = FY5253(n=-1, startingMonth=12, weekday=5, variation="nearest") tests = [ @@ -1547,7 +1546,7 @@ def test_year_has_extra_week(self): def test_get_weeks(self): sat_dec_1 = makeFY5253LastOfMonthQuarter(1, startingMonth=12, weekday=WeekDay.SAT, qtr_with_extra_week=1) sat_dec_4 = makeFY5253LastOfMonthQuarter(1, startingMonth=12, weekday=WeekDay.SAT, qtr_with_extra_week=4) - + self.assertEqual(sat_dec_1.get_weeks(datetime(2011, 4, 2)), [14, 13, 13, 13]) self.assertEqual(sat_dec_4.get_weeks(datetime(2011, 4, 2)), [13, 13, 13, 14]) self.assertEqual(sat_dec_1.get_weeks(datetime(2010, 12, 25)), [13, 13, 13, 13]) @@ -1558,9 +1557,9 @@ def test_onOffset(self): offset_nem_sat_aug_4 = makeFY5253NearestEndMonthQuarter(1, startingMonth=8, weekday=WeekDay.SAT, qtr_with_extra_week=4) offset_nem_thu_aug_4 = makeFY5253NearestEndMonthQuarter(1, startingMonth=8, weekday=WeekDay.THU, qtr_with_extra_week=4) - offset_n = FY5253(weekday=WeekDay.TUE, startingMonth=12, + offset_n = FY5253(weekday=WeekDay.TUE, startingMonth=12, variation="nearest", qtr_with_extra_week=4) - + tests = [ #From Wikipedia (offset_nem_sat_aug_4, datetime(2006, 9, 2), True), @@ -1622,12 +1621,12 @@ def test_offset(self): assertEq(offset, datetime(2012, 5, 31), datetime(2012, 8, 30)) assertEq(offset, datetime(2012, 5, 30), datetime(2012, 5, 31)) - - offset2 = FY5253Quarter(weekday=5, startingMonth=12, + + offset2 = FY5253Quarter(weekday=5, startingMonth=12, variation="last", qtr_with_extra_week=4) - + assertEq(offset2, datetime(2013,1,15), datetime(2013, 3, 30)) - + class TestQuarterBegin(TestBase): def test_repr(self): @@ -2281,7 +2280,7 @@ def test_compare_ticks(): assert(kls(3) != kls(4)) -class TestOffsetNames(unittest.TestCase): +class TestOffsetNames(tm.TestCase): def test_get_offset_name(self): assertRaisesRegexp(ValueError, 'Bad rule.*BusinessDays', get_offset_name, BDay(2)) @@ -2350,7 +2349,7 @@ def test_quarterly_dont_normalize(): assert(result.time() == date.time()) -class TestOffsetAliases(unittest.TestCase): +class TestOffsetAliases(tm.TestCase): def setUp(self): _offset_map.clear() @@ -2423,7 +2422,7 @@ def get_all_subclasses(cls): ret | get_all_subclasses(this_subclass) return ret -class TestCaching(unittest.TestCase): +class TestCaching(tm.TestCase): no_simple_ctr = [WeekOfMonth, FY5253, FY5253Quarter, LastWeekOfMonth] @@ -2474,7 +2473,7 @@ def test_week_of_month_index_creation(self): self.assertTrue(inst2 in _daterange_cache) -class TestReprNames(unittest.TestCase): +class TestReprNames(tm.TestCase): def test_str_for_named_is_name(self): # look at all the amazing combinations! month_prefixes = ['A', 'AS', 'BA', 'BAS', 'Q', 'BQ', 'BQS', 'QS'] diff --git a/pandas/tseries/tests/test_period.py b/pandas/tseries/tests/test_period.py index de6918eb8a1d1..ca0eba59fe5fe 100644 --- a/pandas/tseries/tests/test_period.py +++ b/pandas/tseries/tests/test_period.py @@ -6,9 +6,7 @@ """ -from unittest import TestCase from datetime import datetime, date, timedelta -import unittest from numpy.ma.testutils import assert_equal @@ -33,11 +31,9 @@ from numpy.testing import assert_array_equal -class TestPeriodProperties(TestCase): +class TestPeriodProperties(tm.TestCase): "Test properties such as year, month, weekday, etc...." # - def __init__(self, *args, **kwds): - TestCase.__init__(self, *args, **kwds) def test_quarterly_negative_ordinals(self): p = Period(ordinal=-1, freq='Q-DEC') @@ -494,12 +490,9 @@ def noWrap(item): return item -class TestFreqConversion(TestCase): +class TestFreqConversion(tm.TestCase): "Test frequency conversion of date objects" - def __init__(self, *args, **kwds): - TestCase.__init__(self, *args, **kwds) - def test_asfreq_corner(self): val = Period(freq='A', year=2007) self.assertRaises(ValueError, val.asfreq, '5t') @@ -1074,7 +1067,8 @@ def test_conv_secondly(self): assert_equal(ival_S.asfreq('S'), ival_S) -class TestPeriodIndex(TestCase): +class TestPeriodIndex(tm.TestCase): + def setUp(self): pass @@ -2168,12 +2162,9 @@ def _permute(obj): return obj.take(np.random.permutation(len(obj))) -class TestMethods(TestCase): +class TestMethods(tm.TestCase): "Base test class for MaskedArrays." - def __init__(self, *args, **kwds): - TestCase.__init__(self, *args, **kwds) - def test_add(self): dt1 = Period(freq='D', year=2008, month=1, day=1) dt2 = Period(freq='D', year=2008, month=1, day=2) @@ -2183,7 +2174,7 @@ def test_add(self): self.assertRaises(TypeError, dt1.__add__, dt2) -class TestPeriodRepresentation(unittest.TestCase): +class TestPeriodRepresentation(tm.TestCase): """ Wish to match NumPy units """ @@ -2244,7 +2235,7 @@ def test_negone_ordinals(self): repr(period) -class TestComparisons(unittest.TestCase): +class TestComparisons(tm.TestCase): def setUp(self): self.january1 = Period('2000-01', 'M') self.january2 = Period('2000-01', 'M') diff --git a/pandas/tseries/tests/test_plotting.py b/pandas/tseries/tests/test_plotting.py index 233c9f249ab38..e55dd96d64ca0 100644 --- a/pandas/tseries/tests/test_plotting.py +++ b/pandas/tseries/tests/test_plotting.py @@ -1,6 +1,5 @@ from datetime import datetime, timedelta, date, time -import unittest import nose from pandas.compat import lrange, zip @@ -27,7 +26,7 @@ def _skip_if_no_scipy(): @tm.mplskip -class TestTSPlot(unittest.TestCase): +class TestTSPlot(tm.TestCase): def setUp(self): freq = ['S', 'T', 'H', 'D', 'W', 'M', 'Q', 'Y'] idx = [period_range('12/31/1999', freq=x, periods=100) for x in freq] diff --git a/pandas/tseries/tests/test_resample.py b/pandas/tseries/tests/test_resample.py index c60d4b3fd48d1..707b052031d60 100644 --- a/pandas/tseries/tests/test_resample.py +++ b/pandas/tseries/tests/test_resample.py @@ -16,7 +16,6 @@ import pandas.tseries.offsets as offsets import pandas as pd -import unittest import nose from pandas.util.testing import (assert_series_equal, assert_almost_equal, @@ -33,7 +32,7 @@ def _skip_if_no_pytz(): raise nose.SkipTest("pytz not installed") -class TestResample(unittest.TestCase): +class TestResample(tm.TestCase): _multiprocess_can_split_ = True def setUp(self): @@ -662,7 +661,7 @@ def _simple_pts(start, end, freq='D'): return TimeSeries(np.random.randn(len(rng)), index=rng) -class TestResamplePeriodIndex(unittest.TestCase): +class TestResamplePeriodIndex(tm.TestCase): _multiprocess_can_split_ = True @@ -1055,7 +1054,7 @@ def test_resample_doesnt_truncate(self): self.assertEquals(result.index[0], dates[0]) -class TestTimeGrouper(unittest.TestCase): +class TestTimeGrouper(tm.TestCase): def setUp(self): self.ts = Series(np.random.randn(1000), diff --git a/pandas/tseries/tests/test_timedeltas.py b/pandas/tseries/tests/test_timedeltas.py index df03851ca4ddb..1d34c5b91d5ed 100644 --- a/pandas/tseries/tests/test_timedeltas.py +++ b/pandas/tseries/tests/test_timedeltas.py @@ -2,7 +2,6 @@ from datetime import datetime, timedelta import nose -import unittest import numpy as np import pandas as pd @@ -24,7 +23,7 @@ def _skip_if_numpy_not_friendly(): if _np_version_under1p7: raise nose.SkipTest("numpy < 1.7") -class TestTimedeltas(unittest.TestCase): +class TestTimedeltas(tm.TestCase): _multiprocess_can_split_ = True def setUp(self): diff --git a/pandas/tseries/tests/test_timeseries.py b/pandas/tseries/tests/test_timeseries.py index a7bd2250f95e3..f2f137e18a15c 100644 --- a/pandas/tseries/tests/test_timeseries.py +++ b/pandas/tseries/tests/test_timeseries.py @@ -2,7 +2,6 @@ from datetime import datetime, time, timedelta, date import sys import os -import unittest import operator from distutils.version import LooseVersion @@ -51,7 +50,7 @@ def _skip_if_no_pytz(): raise nose.SkipTest("pytz not installed") -class TestTimeSeriesDuplicates(unittest.TestCase): +class TestTimeSeriesDuplicates(tm.TestCase): _multiprocess_can_split_ = True def setUp(self): @@ -271,7 +270,7 @@ def assert_range_equal(left, right): assert(left.tz == right.tz) -class TestTimeSeries(unittest.TestCase): +class TestTimeSeries(tm.TestCase): _multiprocess_can_split_ = True def test_is_(self): @@ -1420,7 +1419,7 @@ def test_normalize(self): result = rng.normalize() expected = date_range('1/1/2000', periods=10, freq='D') self.assert_(result.equals(expected)) - + rng_ns = pd.DatetimeIndex(np.array([1380585623454345752, 1380585612343234312]).astype("datetime64[ns]")) rng_ns_normalized = rng_ns.normalize() expected = pd.DatetimeIndex(np.array([1380585600000000000, 1380585600000000000]).astype("datetime64[ns]")) @@ -1878,7 +1877,7 @@ def _simple_ts(start, end, freq='D'): return Series(np.random.randn(len(rng)), index=rng) -class TestDatetimeIndex(unittest.TestCase): +class TestDatetimeIndex(tm.TestCase): _multiprocess_can_split_ = True def test_hash_error(self): @@ -2217,7 +2216,7 @@ def test_join_with_period_index(self): df.columns.join(s.index, how=join) -class TestDatetime64(unittest.TestCase): +class TestDatetime64(tm.TestCase): """ Also test supoprt for datetime64[ns] in Series / DataFrame """ @@ -2431,7 +2430,7 @@ def test_slice_locs_indexerror(self): s.ix[datetime(1900, 1, 1):datetime(2100, 1, 1)] -class TestSeriesDatetime64(unittest.TestCase): +class TestSeriesDatetime64(tm.TestCase): def setUp(self): self.series = Series(date_range('1/1/2000', periods=10)) @@ -2550,7 +2549,7 @@ def test_string_index_series_name_converted(self): self.assertEquals(result.name, df.index[2]) -class TestTimestamp(unittest.TestCase): +class TestTimestamp(tm.TestCase): def test_class_ops(self): _skip_if_no_pytz() @@ -2794,7 +2793,7 @@ def test_timestamp_compare_series(self): tm.assert_series_equal(result, expected) -class TestSlicing(unittest.TestCase): +class TestSlicing(tm.TestCase): def test_slice_year(self): dti = DatetimeIndex(freq='B', start=datetime(2005, 1, 1), periods=500) diff --git a/pandas/tseries/tests/test_timezones.py b/pandas/tseries/tests/test_timezones.py index 083de95895d18..d82f91767d413 100644 --- a/pandas/tseries/tests/test_timezones.py +++ b/pandas/tseries/tests/test_timezones.py @@ -2,7 +2,6 @@ from datetime import datetime, time, timedelta, tzinfo, date import sys import os -import unittest import nose import numpy as np @@ -65,7 +64,7 @@ def dst(self, dt): fixed_off_no_name = FixedOffset(-330, None) -class TestTimeZoneSupport(unittest.TestCase): +class TestTimeZoneSupport(tm.TestCase): _multiprocess_can_split_ = True def setUp(self): @@ -366,18 +365,18 @@ def test_infer_dst(self): tz = pytz.timezone('US/Eastern') dr = date_range(datetime(2011, 11, 6, 0), periods=5, freq=datetools.Hour()) - self.assertRaises(pytz.AmbiguousTimeError, dr.tz_localize, + self.assertRaises(pytz.AmbiguousTimeError, dr.tz_localize, tz, infer_dst=True) - + # With repeated hours, we can infer the transition - dr = date_range(datetime(2011, 11, 6, 0), periods=5, + dr = date_range(datetime(2011, 11, 6, 0), periods=5, freq=datetools.Hour(), tz=tz) - di = DatetimeIndex(['11/06/2011 00:00', '11/06/2011 01:00', - '11/06/2011 01:00', '11/06/2011 02:00', + di = DatetimeIndex(['11/06/2011 00:00', '11/06/2011 01:00', + '11/06/2011 01:00', '11/06/2011 02:00', '11/06/2011 03:00']) localized = di.tz_localize(tz, infer_dst=True) self.assert_(np.array_equal(dr, localized)) - + # When there is no dst transition, nothing special happens dr = date_range(datetime(2011, 6, 1, 0), periods=10, freq=datetools.Hour()) @@ -673,7 +672,7 @@ def test_datetimeindex_tz(self): self.assert_(idx1.equals(other)) -class TestTimeZones(unittest.TestCase): +class TestTimeZones(tm.TestCase): _multiprocess_can_split_ = True def setUp(self): diff --git a/pandas/tseries/tests/test_tslib.py b/pandas/tseries/tests/test_tslib.py index 40dbb2d3712af..9a8c19bdc00ab 100644 --- a/pandas/tseries/tests/test_tslib.py +++ b/pandas/tseries/tests/test_tslib.py @@ -1,4 +1,3 @@ -import unittest import nose import numpy as np @@ -7,15 +6,12 @@ import datetime from pandas.core.api import Timestamp - from pandas.tslib import period_asfreq, period_ordinal - from pandas.tseries.frequencies import get_freq - from pandas import _np_version_under1p7 +import pandas.util.testing as tm - -class TestTimestamp(unittest.TestCase): +class TestTimestamp(tm.TestCase): def test_bounds_with_different_units(self): out_of_bounds_dates = ( '1677-09-21', @@ -61,7 +57,7 @@ def test_barely_oob_dts(self): # One us more than the maximum is an error self.assertRaises(ValueError, tslib.Timestamp, max_ts_us + one_us) -class TestDatetimeParsingWrappers(unittest.TestCase): +class TestDatetimeParsingWrappers(tm.TestCase): def test_does_not_convert_mixed_integer(self): bad_date_strings = ( '-50000', @@ -91,7 +87,7 @@ def test_does_not_convert_mixed_integer(self): ) -class TestArrayToDatetime(unittest.TestCase): +class TestArrayToDatetime(tm.TestCase): def test_parsing_valid_dates(self): arr = np.array(['01-01-2013', '01-02-2013'], dtype=object) self.assert_( @@ -194,7 +190,7 @@ def test_coerce_of_invalid_datetimes(self): ) -class TestTimestampNsOperations(unittest.TestCase): +class TestTimestampNsOperations(tm.TestCase): def setUp(self): if _np_version_under1p7: raise nose.SkipTest('numpy >= 1.7 required') @@ -224,7 +220,7 @@ def test_nanosecond_string_parsing(self): self.assertEqual(self.timestamp.value, 1367392545123456000) -class TestTslib(unittest.TestCase): +class TestTslib(tm.TestCase): def test_intraday_conversion_factors(self): self.assertEqual(period_asfreq(1, get_freq('D'), get_freq('H'), False), 24) @@ -283,7 +279,7 @@ def test_period_ordinal_business_day(self): # Tuesday self.assertEqual(11418, period_ordinal(2013, 10, 8, 0, 0, 0, 0, 0, get_freq('B'))) -class TestTomeStampOps(unittest.TestCase): +class TestTomeStampOps(tm.TestCase): def test_timestamp_and_datetime(self): self.assertEqual((Timestamp(datetime.datetime(2013, 10,13)) - datetime.datetime(2013, 10,12)).days, 1) self.assertEqual((datetime.datetime(2013, 10, 12) - Timestamp(datetime.datetime(2013, 10,13))).days, -1) diff --git a/pandas/tseries/tests/test_util.py b/pandas/tseries/tests/test_util.py index 8bf448118561d..b10c4351c8725 100644 --- a/pandas/tseries/tests/test_util.py +++ b/pandas/tseries/tests/test_util.py @@ -1,6 +1,5 @@ from pandas.compat import range import nose -import unittest import numpy as np from numpy.testing.decorators import slow @@ -14,7 +13,7 @@ from pandas.tseries.util import pivot_annual, isleapyear -class TestPivotAnnual(unittest.TestCase): +class TestPivotAnnual(tm.TestCase): """ New pandas of scikits.timeseries pivot_annual """