Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(6)  |  Call(6)  |  Derive(0)  |  Import(0)
>>> coerce("NaN")
nan
>>> coerce("nan")
nan
>>> coerce("Unkn")
>>> coerce("u")
>>> coerce("1")
1.0
>>> 0.039 < coerce("4.0000000000e-02") < 0.041
True(more...)

        def coerce(value):
    """
    >>> coerce("NaN")
    nan
    >>> coerce("nan")
    nan
    >>> coerce("Unkn")
    >>> coerce("u")
    >>> coerce("1")
    1.0
    >>> 0.039 < coerce("4.0000000000e-02") < 0.041
    True
    >>> 0.039 < coerce(4.0000000000e-02) < 0.041
    True
    """
    if "nan" in str(value):
        return 0.0
    try:
        return float(value)
    except ValueError:
        value = unicode(value).lower()
        if value in ["unkn", "u"]:
            return None
        elif value == "nan":
            return NaN()
    raise ValueError, "Unexpected type for data (%s)" % value
        


src/p/y/PyRRD-0.1.0/pyrrd/backend/external.py   PyRRD(Download)
    for line in lines[2:]:
        time, data = line.split(":")
        data = [common.coerce(datum) for datum in data.split()]
        results["time"][int(time)] = dict(zip(dsNames, data))
        for dsName, datum in zip(dsNames, data):
            results["ds"].setdefault(dsName, [])
            results["ds"][dsName].append((int(time), common.coerce(datum)))

src/p/y/pyrrd-fix-0.1.1/pyrrd/backend/external.py   pyrrd-fix(Download)
    for line in lines[2:]:
        time, data = line.split(":")
        data = [common.coerce(datum) for datum in data.split()]
        results["time"][int(time)] = dict(zip(dsNames, data))
        for dsName, datum in zip(dsNames, data):
            results["ds"].setdefault(dsName, [])
            results["ds"][dsName].append((int(time), common.coerce(datum)))

src/p/y/pyrrd-HEAD/pyrrd/backend/external.py   pyrrd(Download)
    for line in lines[2:]:
        time, data = line.split(":")
        data = [common.coerce(datum) for datum in data.split()]
        results["time"][int(time)] = dict(zip(dsNames, data))
        for dsName, datum in zip(dsNames, data):
            results["ds"].setdefault(dsName, [])
            results["ds"][dsName].append((int(time), common.coerce(datum)))