How to use the siuba.siu.symbolic_dispatch function in siuba

To help you get started, we’ve selected a few siuba examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github machow / siuba / siuba / dply / forcats.py View on Github external
@symbolic_dispatch
def fct_rev(fct) -> pd.Categorical:
    """Return a copy of fct with category level order reversed.next
    
    Arguments:
        fct: a pandas.Categorical, or array(-like) used to create one.

    """

    if not isinstance(fct, pd.Categorical):
        fct = pd.Categorical(fct)

    rev_levels = list(reversed(fct.categories))

    return fct.reorder_categories(rev_levels)
github machow / siuba / siuba / experimental / datetime.py View on Github external
@symbolic_dispatch
def ceil_date(x, unit = "S"):
    raise TypeError("ceil_date not implemented for class {}".format(type(x)))
github machow / siuba / siuba / dply / vector.py View on Github external
@symbolic_dispatch(cls = Series)
def cume_dist(x):
    """Return the cumulative distribution corresponding to each value in x.

    This reflects the proportion of values that are less than or equal to each value.

    """
    return x.rank(method = "max") / x.count()
github machow / siuba / siuba / dply / vector.py View on Github external
@symbolic_dispatch(cls = Series)
def between(x, left, right):
    """Return whether a value is between left and right (including either side).

    Example:
        >>> between(pd.Series([1,2,3]), 0, 2)
        0     True
        1     True
        2    False
        dtype: bool

    Note:
        This is a thin wrapper around pd.Series.between(left, right)
    
    """
    # note: NA -> False, in tidyverse NA -> NA
    return x.between(left, right)
github machow / siuba / siuba / dply / vector.py View on Github external
@symbolic_dispatch(cls = Series)
def lag(x, n = 1, default = None):
    """Return an array with each value replaced by the previous (or further backward) value in the array.

    Arguments:
        x: a pandas Series object
        n: number of next values backward to replace each value with
        default: what to replace the n final values of the array with

    Example:
        >>> lag(pd.Series([1,2,3]), n=1)
        0    NaN
        1    1.0
        2    2.0
        dtype: float64

        >>> lag(pd.Series([1,2,3]), n=1, default = 99)
github machow / siuba / siuba / dply / vector.py View on Github external
@symbolic_dispatch(cls = Series)
def cumall(x):
    """Return a same-length array. For each entry, indicates whether that entry and all previous are True-like.

    Example:
        >>> cumall(pd.Series([True, False, False]))
        0     True
        1    False
        2    False
        dtype: bool

    """
    return _expand_bool(x, np.all)
github machow / siuba / siuba / dply / vector.py View on Github external
@symbolic_dispatch(cls = Series)
def coalesce(*args):
    """TODO: Not Implemented"""
    NotImplementedError("coalesce not implemented")
github machow / siuba / siuba / dply / vector.py View on Github external
@symbolic_dispatch(cls = NDFrame)
def row_number(x):
    """Return the row number (position) for each value in x, beginning with 1.

    Example:
        >>> row_number(pd.Series([7,8,9]))
        0    1
        1    2
        2    3
        dtype: int64

    """
    if isinstance(x, pd.DataFrame):
        n = x.shape[0]
    else:
        n = len(x)
github machow / siuba / siuba / dply / vector.py View on Github external
@symbolic_dispatch(cls = Series)
def min_rank(x):
    """Return the min rank. See pd.Series.rank for details.

    """
    return x.rank(method = "min")
github machow / siuba / siuba / dply / vector.py View on Github external
@symbolic_dispatch(cls = Series)
def lead(x, n = 1, default = None):
    """Return an array with each value replaced by the next (or further forward) value in the array.

    Arguments:
        x: a pandas Series object
        n: number of next values forward to replace each value with
        default: what to replace the n final values of the array with

    Example:
        >>> lead(pd.Series([1,2,3]), n=1)
        0    2.0
        1    3.0
        2    NaN
        dtype: float64

        >>> lead(pd.Series([1,2,3]), n=1, default = 99)