Skip to content

Commit

Permalink
πŸ”– 0.6.2 (#88)
Browse files Browse the repository at this point in the history
* πŸš‘ Fix #87 boolean operator losing index

* πŸ“ Update doc for case_when (#87)

* πŸ“ Update doc for case_when (#87)

* πŸ“ Fix links in reference map

* πŸ”– 0.6.2

* ✨ Add `base.diff()`

* πŸ“ Update docs for `dplyr.base`

* πŸ“ Update mkdocs.yml

* πŸ“ Update CHANGELOG

* πŸš‘ Fix false alarm from `rename()`/`relocate()` for missing grouping variables (#89)

* πŸ“ Update CHANGELOG

* πŸ“ Add deps for docs building
  • Loading branch information
pwwang authored Mar 12, 2022
1 parent ac7cf21 commit 4d8d3d5
Show file tree
Hide file tree
Showing 20 changed files with 2,306 additions and 654 deletions.
2 changes: 1 addition & 1 deletion datar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
)

__all__ = ("f", "get_versions")
__version__ = "0.6.1"
__version__ = "0.6.2"


def get_versions(prnt: bool = True) -> _VersionsTuple:
Expand Down
1 change: 1 addition & 0 deletions datar/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .dplyr import _warn as _
from .tibble import *
from .tidyr import *
from .base import rank # overwrite dplyr.rank

_builtin_names = _base_builtin_names.copy()
_builtin_names.update(_dplyr_builtin_names)
Expand Down
1 change: 1 addition & 0 deletions datar/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
from .funs import (
cut,
data_context,
diff,
expandgrid,
identity,
make_unique,
Expand Down
33 changes: 33 additions & 0 deletions datar/base/funs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from ..core.middlewares import WithDataEnv
from ..core.contexts import Context
from ..core.factory import func_factory
from ..core.tibble import Tibble
from ..core.utils import arg_match, name_of
from ..core.names import repair_names
Expand Down Expand Up @@ -66,6 +67,38 @@ def cut(
)


@func_factory("agg", "x")
def diff(x, lag: int = 1, differences: int = 1):
"""Calculates suitably lagged and iterated differences.
If the data is a vector of length n and differences = 1, then the computed
result is equal to the successive differences
`x[lag:] – x[:-lag]`.
Examples:
>>> rv = [52, 21, 10, 11, 19]
>>> data = diff(rv)
>>> # -31 -11 1 8
>>> # rv[1:] - rv[:-1]
>>> # rv[1:] [21, 10, 11, 19]
>>> # rv[:-1] [52, 21, 10, 11]
Args:
x: The data
lag: The lag to use. Could be negative.
It always calculates `x[lag:] - x[:-lag]` even when `lag` is negative
differences: The order of the difference
Returns:
An array of `x[lag:] – x[:-lag]`.
If `differences > 1`, the rule applies `differences` times on `x`
"""
x = x.values
for _ in range(differences):
x = x[lag:] - x[:-lag]
return x


@register_func(None, context=Context.EVAL)
def identity(x):
"""Return whatever passed in
Expand Down
4 changes: 3 additions & 1 deletion datar/core/broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,9 @@ def init_tibble_from(value, name: str) -> Tibble:

@init_tibble_from.register(Series)
def _(value: Series, name: str) -> Tibble:
name = name or value.name
# Deprecate warning, None will be used as series name in the future
# So use 0 as default here
name = name or value.name or 0
return Tibble(value.to_frame(name=name), copy=False)


Expand Down
11 changes: 9 additions & 2 deletions datar/core/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@
def _binop(op, left, right, fill_false=False):
left, right, grouper, is_rowwise = broadcast2(left, right)
if fill_false:
left = Series(left).fillna(False).values
right = Series(right).fillna(False).values
if isinstance(left, Series):
left = left.fillna(False)
else:
left = Series(left).fillna(False).values

if isinstance(right, Series):
right = right.fillna(False)
else:
right = Series(right).fillna(False).values

out = op(left, right)
if grouper:
Expand Down
3 changes: 3 additions & 0 deletions datar/dplyr/relocate.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def relocate(
*args,
**kwargs,
_group_vars=gvars,
_missing_gvars_inform=False,
)

to_move = list(to_move)
Expand All @@ -65,6 +66,7 @@ def relocate(
all_columns,
_before,
_group_vars=[],
_missing_gvars_inform=False,
)[0]
)
if where not in to_move:
Expand All @@ -76,6 +78,7 @@ def relocate(
all_columns,
_after,
_group_vars=[],
_missing_gvars_inform=False,
)[0]
)
if where not in to_move:
Expand Down
1 change: 1 addition & 0 deletions datar/dplyr/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def rename(_data, **kwargs):
selected, new_names = _eval_select(
all_columns,
_group_vars=gvars,
_missing_gvars_inform=False,
**kwargs,
)

Expand Down
8 changes: 5 additions & 3 deletions datar/dplyr/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def _eval_select(
_all_columns: Index,
*args: Any,
_group_vars: Sequence[str],
_missing_gvars_inform: bool = True,
**kwargs: Any,
) -> Tuple[Sequence[int], Mapping[str, str]]:
"""Evaluate selections to get locations
Expand All @@ -79,9 +80,10 @@ def _eval_select(
*kwargs.values(),
)

missing = regcall(setdiff, _group_vars, _all_columns[selected_idx])
if len(missing) > 0:
logger.info("Adding missing grouping variables: %s", missing)
if _missing_gvars_inform:
missing = regcall(setdiff, _group_vars, _all_columns[selected_idx])
if len(missing) > 0:
logger.info("Adding missing grouping variables: %s", missing)

selected_idx = regcall(
union,
Expand Down
9 changes: 9 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 0.6.2

- πŸš‘ Fix #87 boolean operator losing index
- πŸš‘ Fix false alarm from `rename()`/`relocate()` for missing grouping variables (#89)
- ✨ Add `base.diff()`
- πŸ“ [doc] Update/Fix doc for case_when (#87)
- πŸ“ [doc] Fix links in reference map
- πŸ“ [doc] Update docs for `dplyr.base`

## 0.6.1

- πŸ› Fix `rep(df, n)` producing a nested df
Expand Down
Loading

0 comments on commit 4d8d3d5

Please sign in to comment.