def test_numpy_ufuncs(self): # test ufuncs of numpy 1.9.2. see: # http://docs.scipy.org/doc/numpy/reference/ufuncs.html # some functions are skipped because it may return different result # for unicode input depending on numpy version for name, idx in compat.iteritems(self.indices): for func in [ np.exp, np.exp2, np.expm1, np.log, np.log2, np.log10, np.log1p, np.sqrt, np.sin, np.cos, np.tan, np.arcsin, np.arccos, np.arctan, np.sinh, np.cosh, np.tanh, np.arcsinh, np.arccosh, np.arctanh, np.deg2rad, np.rad2deg ]: if isinstance(idx, pd.tseries.base.DatetimeIndexOpsMixin): # raise TypeError or ValueError (PeriodIndex) # PeriodIndex behavior should be changed in future version with tm.assertRaises(Exception): with np.errstate(all='ignore'): func(idx) elif isinstance(idx, (Float64Index, Int64Index, UInt64Index)): # coerces to float (e.g. np.sin) with np.errstate(all='ignore'): result = func(idx) exp = Index(func(idx.values), name=idx.name) self.assert_index_equal(result, exp) self.assertIsInstance(result, pd.Float64Index) else: # raise AttributeError or TypeError if len(idx) == 0: continue else: with tm.assertRaises(Exception): with np.errstate(all='ignore'): func(idx) for func in [np.isfinite, np.isinf, np.isnan, np.signbit]: if isinstance(idx, pd.tseries.base.DatetimeIndexOpsMixin): # raise TypeError or ValueError (PeriodIndex) with tm.assertRaises(Exception): func(idx) elif isinstance(idx, (Float64Index, Int64Index, UInt64Index)): # results in bool array result = func(idx) exp = func(idx.values) self.assertIsInstance(result, np.ndarray) tm.assertNotIsInstance(result, Index) else: if len(idx) == 0: continue else: with tm.assertRaises(Exception): func(idx)
def test_numpy_ufuncs(self): # test ufuncs of numpy 1.9.2. see: # http://docs.scipy.org/doc/numpy/reference/ufuncs.html # some functions are skipped because it may return different result # for unicode input depending on numpy version for name, idx in compat.iteritems(self.indices): for func in [np.exp, np.exp2, np.expm1, np.log, np.log2, np.log10, np.log1p, np.sqrt, np.sin, np.cos, np.tan, np.arcsin, np.arccos, np.arctan, np.sinh, np.cosh, np.tanh, np.arcsinh, np.arccosh, np.arctanh, np.deg2rad, np.rad2deg]: if isinstance(idx, pd.tseries.base.DatetimeIndexOpsMixin): # raise TypeError or ValueError (PeriodIndex) # PeriodIndex behavior should be changed in future version with tm.assertRaises(Exception): with np.errstate(all='ignore'): func(idx) elif isinstance(idx, (Float64Index, Int64Index, UInt64Index)): # coerces to float (e.g. np.sin) with np.errstate(all='ignore'): result = func(idx) exp = Index(func(idx.values), name=idx.name) self.assert_index_equal(result, exp) self.assertIsInstance(result, pd.Float64Index) else: # raise AttributeError or TypeError if len(idx) == 0: continue else: with tm.assertRaises(Exception): with np.errstate(all='ignore'): func(idx) for func in [np.isfinite, np.isinf, np.isnan, np.signbit]: if isinstance(idx, pd.tseries.base.DatetimeIndexOpsMixin): # raise TypeError or ValueError (PeriodIndex) with tm.assertRaises(Exception): func(idx) elif isinstance(idx, (Float64Index, Int64Index, UInt64Index)): # results in bool array result = func(idx) exp = func(idx.values) self.assertIsInstance(result, np.ndarray) tm.assertNotIsInstance(result, Index) else: if len(idx) == 0: continue else: with tm.assertRaises(Exception): func(idx)
def test_notisinstance(self): expected = "Input must not be type " with assertRaisesRegexp(AssertionError, expected): tm.assertNotIsInstance(pd.Series([1]), pd.Series)