Ejemplo n.º 1
0
def test_side_effects(name, series):
    reference = series.copy()

    typeset = CompleteSet()
    typeset.detect_type(series)
    typeset.infer_type(series)

    assert sequences_equal(series, reference)
Ejemplo n.º 2
0
def test_side_effects(series):
    reference = series.copy()

    typeset = CompleteSet()
    typeset.detect_type(series)
    typeset.infer_type(series)

    # Check if NaN mask is equal
    assert series.notna().eq(reference.notna()).all()
    # Check if NonNaN values are equal
    assert series[series.notna()].eq(reference[reference.notna()]).all()
Ejemplo n.º 3
0
def test_consistency(name, series):
    typeset = CompleteSet()

    if (
        name in ["timedelta_series_nat", "date_series_nat", "timestamp_series_nat"]
        and sys.version_info.major == 3
        and sys.version_info.minor == 7
    ):
        pytest.skip("unsupported configuration")

    initial_type = str(typeset.detect_type(series))
    converted_type = str(typeset.infer_type(series))

    if initial_type != converted_type:
        converted_series = typeset.cast_to_inferred(series.copy(deep=True))

        if hasattr(series, "dtype") and hasattr(converted_series, "dtype"):
            assert (
                series.dtype.kind != converted_series.dtype.kind
                or not sequences_equal(series, converted_series)
            )
        else:
            assert not sequences_equal(series, converted_series)

    else:
        converted_series = typeset.cast_to_inferred(series)
        assert sequences_equal(series, converted_series)
Ejemplo n.º 4
0
def test_multiple_inference(name, series):
    """
    Notes:
        Copy to prevent possible side effects only for testing.
    """
    ts = CompleteSet()

    inferred_type = str(ts.infer_type(series))

    series_convert = ts.cast_to_inferred(copy.copy(series))

    initial_type_after_convert = str(ts.detect_type(series_convert))
    assert inferred_type == initial_type_after_convert

    series_convert2 = ts.cast_to_inferred(series_convert)

    inferred_type_after_convert = str(ts.infer_type(series_convert2))
    assert initial_type_after_convert == inferred_type_after_convert
    assert sequences_equal(series_convert, series_convert2)
Ejemplo n.º 5
0
def test_consistency(series):
    typeset = CompleteSet()

    if (series.name in [
            "timedelta_series_nat", "date_series_nat", "timestamp_series_nat"
    ] and sys.version_info.major == 3 and sys.version_info.minor == 7):
        pytest.skip("unsupported configuration")

    initial_type = typeset.detect_type(series.copy(deep=True))
    converted_type = typeset.infer_type(series.copy(deep=True))

    if initial_type != converted_type:
        converted_series = typeset.cast_to_inferred(series.copy(deep=True))
        assert series.dtype.kind != converted_series.dtype.kind or not (
            (converted_series.eq(series) |
             (converted_series.isna() & series.isna())).all())
    else:
        converted_series = typeset.cast_to_inferred(series.copy(deep=True))
        assert (converted_series.eq(series) |
                (converted_series.isna() & series.isna())).all()
Ejemplo n.º 6
0
def test_multiple_inference(series):
    """
    Notes:
        Copy to prevent possible side effects only for testing.
    """
    ts = CompleteSet()

    inferred_type = ts.infer_type(series)

    series_convert = ts.cast_to_inferred(series.copy(deep=True))

    initial_type_after_convert = ts.detect_type(series_convert.copy(deep=True))
    assert inferred_type == initial_type_after_convert

    series_convert2 = ts.cast_to_inferred(series_convert.copy(deep=True))

    inferred_type_after_convert = ts.infer_type(
        series_convert2.copy(deep=True))
    assert initial_type_after_convert == inferred_type_after_convert

    assert series_convert.isna().eq(series_convert2.isna()).all()
    assert (series_convert[series_convert.notna()].eq(
        series_convert2[series_convert2.notna()]).all())