Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
 def wrapper(*args, **kwargs):
     result = func(*args, **kwargs)
     ck.has_dtypes(result, items)
     return result
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
 def wrapper(*args, **kwargs):
     result = func(*args, **kwargs)
     ck.has_dtypes(result, items)
     return result