Esempio n. 1
0
def ints_floats_complex_or_booleans(draw):
    dtypes = (
        unsigned_integer_dtypes(endianness="="),
        integer_dtypes(endianness="="),
        floating_dtypes(endianness="="),
        # complex_number_dtypes(endianness="="),
        boolean_dtypes(),
    )
    return draw(one_of(dtypes))
Esempio n. 2
0
def test_generate_arbitrary_indices(data):
    min_size = data.draw(st.integers(0, 10), "min_size")
    max_size = data.draw(st.none() | st.integers(min_size, min_size + 10),
                         "max_size")
    unique = data.draw(st.booleans(), "unique")
    dtype = data.draw(
        st.one_of(
            npst.boolean_dtypes(),
            npst.integer_dtypes(endianness="="),
            npst.floating_dtypes(endianness="="),
            npst.complex_number_dtypes(endianness="="),
            npst.datetime64_dtypes(endianness="="),
            npst.timedelta64_dtypes(endianness="="),
        ).filter(supported_by_pandas),
        "dtype",
    )
    pass_elements = data.draw(st.booleans(), "pass_elements")

    converted_dtype = pandas.Index([], dtype=dtype).dtype

    try:
        inferred_dtype = pandas.Index([data.draw(npst.from_dtype(dtype))
                                       ]).dtype

        if pass_elements:
            elements = npst.from_dtype(dtype)
            dtype = None
        else:
            elements = None

        index = data.draw(
            pdst.indexes(
                elements=elements,
                dtype=dtype,
                min_size=min_size,
                max_size=max_size,
                unique=unique,
            ))

    except Exception as e:
        if type(e).__name__ == "OutOfBoundsDatetime":
            # See https://github.com/HypothesisWorks/hypothesis-python/pull/826
            reject()
        else:
            raise
    if dtype is None:
        assert index.dtype == inferred_dtype
    else:
        assert index.dtype == converted_dtype

    if unique:
        assert len(set(index.values)) == len(index)
Esempio n. 3
0
def one_of_supported_dtypes(draw):
    # A strategy that selects a dtype that riptable is known to handle.
    # dtype size 16-bit is not supported
    # little endian is not supported
    return one_of(
        boolean_dtypes(),
        integer_dtypes(endianness="=", sizes=(8, 32, 64)),
        unsigned_integer_dtypes(endianness="=", sizes=(8, 32, 64)),
        floating_dtypes(endianness="=", sizes=(32, 64)),
        byte_string_dtypes(endianness="="),
        unicode_string_dtypes(endianness="="),
        # the following dtypes are not supported
        # complex_number_dtypes(),
        # datetime64_dtypes(),
        # timedelta64_dtypes(),
    )
    booleans,
    dictionaries,
    floats,
    integers,
    lists,
    one_of,
    recursive,
    text,
)

import superintendent.prioritisation
from superintendent import SemiSupervisor

primitive_strategy = text() | integers() | floats(allow_nan=False) | booleans()

guaranteed_dtypes = (boolean_dtypes()
                     | integer_dtypes()
                     | floating_dtypes()
                     | unicode_string_dtypes())

container_strategy = dictionaries(
    text(), primitive_strategy) | lists(primitive_strategy)

nested_strategy = recursive(
    container_strategy,
    lambda children: lists(children) | dictionaries(text(), children),
)

container_strategy = dictionaries(
    text(), primitive_strategy) | lists(primitive_strategy)
    dictionaries,
    floats,
    integers,
    lists,
    one_of,
    recursive,
    text,
)
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import cross_validate
from superintendent.distributed import SemiSupervisor

primitive_strategy = text() | integers() | floats(allow_nan=False) | booleans()

guaranteed_dtypes = (
    boolean_dtypes()
    | integer_dtypes()
    | floating_dtypes()
    | unicode_string_dtypes()
)

container_strategy = dictionaries(text(), primitive_strategy) | lists(
    primitive_strategy
)

nested_strategy = recursive(
    container_strategy,
    lambda children: lists(children) | dictionaries(text(), children),
)

container_strategy = dictionaries(text(), primitive_strategy) | lists(
Esempio n. 6
0
def generate_array_and_where(draw, shape, dtype):
    arr = draw(arrays(shape=shape, dtype=dtype))
    where = draw(arrays(shape=arr.shape, dtype=boolean_dtypes()))
    return arr, where
Esempio n. 7
0
from hypothesis import given
from hypothesis import strategies as st
from hypothesis.extra import numpy as nst

from oh import Config

# ints are not strictly json but they're important & supported by Python's json module
jsons = st.recursive(
    st.none() | st.booleans() | st.integers() | st.floats() | st.text(),
    lambda children:
    (st.lists(children)
     | st.dictionaries(st.text(ascii_letters, min_size=1), children)),
)

numpy_scalar_dtypes = st.one_of(
    nst.boolean_dtypes(),
    nst.integer_dtypes(),
    nst.unsigned_integer_dtypes(),
    nst.floating_dtypes(),
)


@given(jsons)
def test_json_types(value):
    c = Config({"x": value})
    assert isinstance(c.x, type(value))
    assert c.x == value or (isinstance(c.x, float) and isnan(c.x)
                            and isinstance(value, float) and isnan(value))
    assert_valid_json(c)

import pandas as pd
from hypothesis import given
from hypothesis.extra.pandas import column, columns, data_frames, series
from hypothesis.strategies import (
    booleans,
    dictionaries,
    floats,
    integers,
    lists,
    one_of,
    recursive,
    text,
)
from superintendent.distributed.serialization import data_dumps, data_loads

guaranteed_dtypes = (np_strategies.boolean_dtypes()
                     | np_strategies.integer_dtypes()
                     | np_strategies.floating_dtypes()
                     | np_strategies.unicode_string_dtypes())

json_array = recursive(
    floats(allow_nan=False) | integers() | text() | booleans(), lists)
json_object = recursive(
    floats(allow_nan=False) | integers() | text() | booleans(),
    partial(dictionaries, text()),
)


def exact_element_match(a, b):
    if isinstance(a, np.ndarray) and isinstance(b, np.ndarray):
        try:
Esempio n. 9
0
from hypothesis import given
from hypothesis.extra.pandas import column, columns, data_frames, series
from hypothesis.strategies import (
    booleans,
    dictionaries,
    floats,
    integers,
    lists,
    one_of,
    recursive,
    text,
)
from superintendent.distributed.serialization import data_dumps, data_loads

guaranteed_dtypes = (
    np_strategies.boolean_dtypes()
    | np_strategies.integer_dtypes()
    | np_strategies.floating_dtypes()
    | np_strategies.unicode_string_dtypes()
)


json_array = recursive(
    floats(allow_nan=False) | integers() | text() | booleans(), lists
)
json_object = recursive(
    floats(allow_nan=False) | integers() | text() | booleans(),
    partial(dictionaries, text()),
)