def test_has_dtypes(): df = pd.DataFrame({'A': np.random.randint(0, 10, 10), 'B': np.random.randn(10), 'C': list('abcdefghij'), 'D': pd.Categorical(np.random.choice(['a', 'b'], 10))}) dtypes = {'A': int, 'B': 'float', 'C': object, 'D': 'category'} tm.assert_frame_equal(df, ck.has_dtypes(df, dtypes)) tm.assert_frame_equal(df, dc.has_dtypes(items=dtypes)(_noop)(df)) with pytest.raises(AssertionError): ck.has_dtypes(df, {'A': float}) with pytest.raises(AssertionError): dc.has_dtypes(items={'A': bool})(_noop)(df)
def test_has_dtypes_funcs(): pat = pd.api.types df = pd.DataFrame({ 'A': np.random.randint(0, 10, 10), 'B': np.random.randn(10), 'C': list('abcdefghij'), 'D': pd.Categorical(np.random.choice(['a', 'b'], 10)) }) dtypes = { 'A': pat.is_integer_dtype, 'B': pat.is_float_dtype, 'C': pat.is_string_dtype, 'D': pat.is_categorical_dtype } tm.assert_frame_equal(df, ck.has_dtypes(df, dtypes)) tm.assert_frame_equal(df, dc.has_dtypes(items=dtypes)(_noop)(df)) with pytest.raises(AssertionError): ck.has_dtypes(df, {'A': pat.is_float_dtype}) with pytest.raises(AssertionError): ck.has_dtypes(df, {'A': pat.is_integer}) with pytest.raises(AssertionError): dc.has_dtypes(items={'A': pat.is_bool_dtype})(_noop)(df)
def wrapper(*args, **kwargs): result = func(*args, **kwargs) ck.has_dtypes(result, items) return result
def check(data, ranges=ranges, dtypes=dtypes): ec.unique_index(data) ec.none_missing(data) ec.within_range(data, items=ranges) ec.has_dtypes(data, items=dtypes)