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/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/io/tests/test_clipboard.py b/pandas/io/tests/test_clipboard.py index 6ee0afa1c8c07..3556dfd999d40 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_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 4e2331f05001d..831be69b9db5f 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_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 f56c1aa042421..ec051d008b3f3 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', ' 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} 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 66ae52983b692..36cfb4870a8fe 100644 --- a/pandas/tools/tests/test_util.py +++ b/pandas/tools/tests/test_util.py @@ -1,8 +1,6 @@ import os import locale import codecs -import unittest - import nose import numpy as np @@ -16,7 +14,7 @@ LOCALE_OVERRIDE = os.environ.get('LOCALE_OVERRIDE', None) -class TestCartesianProduct(unittest.TestCase): +class TestCartesianProduct(tm.TestCase): def test_simple(self): x, y = list('ABC'), [1, 22] @@ -26,9 +24,11 @@ def test_simple(self): assert_equal(result, expected) -class TestLocaleUtils(unittest.TestCase): +class TestLocaleUtils(tm.TestCase): + @classmethod def setUpClass(cls): + super(TestLocaleUtils, cls).setUpClass() cls.locales = tm.get_locales() if not cls.locales: @@ -39,6 +39,7 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): + super(TestLocaleUtils, cls).tearDownClass() del cls.locales def test_get_locales(self): 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 """ diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 2ea570d6f8e94..0c4e083b54eda 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,18 @@ 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): + #print("tearing down up: {0}".format(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