Ejemplo n.º 1
0
def test_cast_copy():
    s = pd.Series(["1", "2", "3", "4"])
    id_s = hex(id(s))

    typeset = CompleteSet()
    ns = typeset.cast_series(s)
    id_ns = hex(id(ns))
    assert id_s != id_ns
Ejemplo n.º 2
0
def test_noncast_noncopy():
    s = pd.Series(["asdasd", "asdasda", "asdasd", "sadasd"])
    id_s = hex(id(s))

    typeset = CompleteSet()
    ns = typeset.cast_series(s)
    id_ns = hex(id(ns))
    assert id_s == id_ns
Ejemplo n.º 3
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_series_type(series.copy(deep=True))
    converted_type = typeset.infer_series_type(series.copy(deep=True))

    if initial_type != converted_type:
        converted_series = typeset.cast_series(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_series(series.copy(deep=True))
        assert (converted_series.eq(series) |
                (converted_series.isna() & series.isna())).all()
Ejemplo n.º 4
0
def test_multiple_inference(series):
    """
    Notes:
        Copy to prevent possible side effects only for testing.
    """
    ts = CompleteSet()

    inferred_type = ts.infer_series_type(series)

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

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

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

    inferred_type_after_convert = ts.detect_series_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())