def ints_floats_datetimes_and_timedeltas(draw):
    dtypes = (
        unsigned_integer_dtypes(endianness="="),
        integer_dtypes(endianness="="),
        floating_dtypes(endianness="="),
        datetime64_dtypes(endianness="="),
        timedelta64_dtypes(endianness="="),
    )
    return draw(one_of(dtypes))
Beispiel #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)
    test_set = load_by_id(datasaver.run_id)
    expec_data = np.array([item for item in list_of_strings])
    actual_data = test_set.get_parameter_data()["p"]["p"]

    try:
        np.testing.assert_array_equal(actual_data, expec_data)
    finally:
        test_set.conn.close()


@settings(suppress_health_check=(HealthCheck.function_scoped_fixture, ),
          deadline=None)
@given(p_values=hypnumpy.arrays(dtype=hst.sampled_from(
    (hypnumpy.unicode_string_dtypes(), hypnumpy.byte_string_dtypes(),
     hypnumpy.timedelta64_dtypes(), hypnumpy.datetime64_dtypes())),
                                shape=hypnumpy.array_shapes()))
def test_string_and_date_data_in_array(experiment, p_values):
    p = qc.Parameter('p',
                     label='String parameter',
                     unit='',
                     get_cmd=None,
                     set_cmd=None,
                     initial_value=p_values)

    meas = Measurement(experiment)
    meas.register_parameter(p, paramtype='array')

    with meas.run() as datasaver:
        datasaver.add_result((p, p.get()))
    actual_data = datasaver.dataset.get_parameter_data()["p"]["p"]
     id="unsigned_integer_dtype",
 ),
 pytest.param(
     byte_string_dtypes(endianness="="), None, id="byte_string_dtype"),
 pytest.param(
     datetime64_dtypes(endianness="="),
     None,
     id="datetime64_dtype",
     marks=[
         pytest.mark.xfail(
             reason="RIP-375 - Categorical unsupported dtypes"),
         pytest.mark.skip,
     ],
 ),
 pytest.param(
     timedelta64_dtypes(endianness="="),
     None,
     id="timedelta64_dtype",
     marks=[
         pytest.mark.xfail(
             reason="RIP-375 - Categorical unsupported dtypes"),
         pytest.mark.skip,
     ],
 ),
 pytest.param(
     unicode_string_dtypes(endianness="="),
     None,
     id="unicode_string_dtype",
     marks=[
         pytest.mark.xfail(
             reason="RIP-375 - Categorical unsupported dtypes"),
Beispiel #5
0
    expec_data = np.array([item for item in list_of_strings])
    actual_data = test_set.get_parameter_data()["p"]["p"]

    try:
        np.testing.assert_array_equal(actual_data, expec_data)
    finally:
        test_set.conn.close()


@settings(suppress_health_check=(HealthCheck.function_scoped_fixture,))
@given(
    p_values=hypnumpy.arrays(
        dtype=hst.sampled_from(
            (hypnumpy.unicode_string_dtypes(),
             hypnumpy.byte_string_dtypes(),
             hypnumpy.timedelta64_dtypes(),
             hypnumpy.datetime64_dtypes())
        ),
        shape=hypnumpy.array_shapes()
    )
)
def test_string_and_date_data_in_array(experiment, p_values):
    p = qc.Parameter('p', label='String parameter', unit='', get_cmd=None,
                     set_cmd=None, initial_value=p_values)

    meas = Measurement(experiment)
    meas.register_parameter(p, paramtype='array')

    with meas.run() as datasaver:
        datasaver.add_result((p, p.get()))
    actual_data = datasaver.dataset.get_parameter_data()["p"]["p"]