コード例 #1
0
def test_round_any():
    x = 4.632
    assert round_any(x, 1) == 5
    assert round_any(x, 2) == 4
    assert round_any(x, 3) == 6
    assert round_any(x, 4) == 4
    assert round_any(x, 5) == 5
    assert round_any(x, 1.5) == 4.5
コード例 #2
0
def test_round_any():
    x = 4.632
    assert round_any(x, 1) == 5
    assert round_any(x, 2) == 4
    assert round_any(x, 3) == 6
    assert round_any(x, 4) == 4
    assert round_any(x, 5) == 5
    assert round_any(x, 1.5) == 4.5

    # Maintains the same index
    s = pd.Series([1.1, 2.2, 3.3], index=[3, 2, 1])
    result = round_any(s, 2)
    assert s.index.equals(result.index)
コード例 #3
0
ファイル: test_utils.py プロジェクト: has2k1/mizani
def test_round_any():
    x = 4.632
    assert round_any(x, 1) == 5
    assert round_any(x, 2) == 4
    assert round_any(x, 3) == 6
    assert round_any(x, 4) == 4
    assert round_any(x, 5) == 5
    assert round_any(x, 1.5) == 4.5

    # Maintains the same index
    s = pd.Series([1.1, 2.2, 3.3], index=[3, 2, 1])
    result = round_any(s, 2)
    assert s.index.equals(result.index)
コード例 #4
0
ファイル: binning.py プロジェクト: sthagen/plotnine
def fuzzybreaks(scale,
                breaks=None,
                boundary=None,
                binwidth=None,
                bins=30,
                right=True):
    """
    Compute fuzzy breaks

    For a continuous scale, fuzzybreaks "preserve" the range of
    the scale. The fuzzing is close to numerical roundoff and
    is visually imperceptible.

    Parameters
    ----------
    scale : scale
        Scale
    breaks : array_like
        Sequence of break points. If provided and the scale is not
        discrete, they are returned.
    boundary : float
        First break. If `None` a suitable on is computed using
        the range of the scale and the binwidth.
    binwidth : float
        Separation between the breaks
    bins : int
        Number of bins
    right : bool
        If `True` the right edges of the bins are part of the
        bin. If `False` then the left edges of the bins are part
        of the bin.

    Returns
    -------
    out : array_like
    """
    # Bins for categorical data should take the width
    # of one level, and should show up centered over
    # their tick marks. All other parameters are ignored.
    if isinstance(scale, scale_discrete):
        breaks = scale.get_breaks()
        return -0.5 + np.arange(1, len(breaks) + 2)
    else:
        if breaks is not None:
            breaks = scale.transform(breaks)

    if breaks is not None:
        return breaks

    recompute_bins = binwidth is not None
    srange = scale.limits

    if binwidth is None or np.isnan(binwidth):
        binwidth = (srange[1] - srange[0]) / bins

    if boundary is None or np.isnan(boundary):
        boundary = round_any(srange[0], binwidth, np.floor)

    if recompute_bins:
        bins = int(np.ceil((srange[1] - boundary) / binwidth))

    # To minimise precision errors, we do not pass the boundary and
    # binwidth into np.arange as params. The resulting breaks
    # can then be adjusted with finer(epsilon based rather than
    # some arbitrary small number) precision.
    breaks = np.arange(boundary, srange[1] + binwidth, binwidth)
    return _adjust_breaks(breaks, right)
コード例 #5
0
ファイル: binning.py プロジェクト: jwhendy/plotnine
def fuzzybreaks(scale, breaks=None, boundary=None,
                binwidth=None, bins=30, right=True):
    """
    Compute fuzzy breaks

    For a continuous scale, fuzzybreaks "preserve" the range of
    the scale. The fuzzing is close to numerical roundoff and
    is visually imperceptible.

    Parameters
    ----------
    scale : scale
        Scale
    breaks : array_like
        Sequence of break points. If provided and the scale is not
        discrete, they are returned.
    boundary : float
        First break. If `None` a suitable on is computed using
        the range of the scale and the binwidth.
    binwidth : float
        Separation between the breaks
    bins : int
        Number of bins
    right : bool
        If `True` the right edges of the bins are part of the
        bin. If `False` then the left edges of the bins are part
        of the bin.

    Returns
    -------
    out : array_like
    """
    # Bins for categorical data should take the width
    # of one level, and should show up centered over
    # their tick marks. All other parameters are ignored.
    if isinstance(scale, scale_discrete):
        breaks = scale.get_breaks()
        return -0.5 + np.arange(1, len(breaks)+2)
    else:
        if breaks is not None:
            breaks = scale.transform(breaks)

    if breaks is not None:
        return breaks

    recompute_bins = binwidth is not None
    srange = scale.limits

    if binwidth is None or np.isnan(binwidth):
        binwidth = (srange[1]-srange[0]) / bins

    if boundary is None or np.isnan(boundary):
        boundary = round_any(srange[0], binwidth, np.floor)

    if recompute_bins:
        bins = np.int(np.ceil((srange[1]-boundary)/binwidth))

    # To minimise precision errors, we do not pass the boundary and
    # binwidth into np.arange as params. The resulting breaks
    # can then be adjusted with finer(epsilon based rather than
    # some arbitrary small number) precision.
    breaks = np.arange(boundary, srange[1]+binwidth, binwidth)
    return _adjust_breaks(breaks, right)