Skip to content

Commit 9e71287

Browse files
authored
0.3.0 (#22)
* Update CI configuration * Rename argument dtypes of unchop and unnest to ptype * Change all `_base0` to `base0_` * Change argument `how` of tidyr.drop_na to `how_` * Add advanced usage in docs; Adopt pipda v0.3.0; * 0.3.0 * Update docs * Remove pull_request from docs building CI
1 parent 72ab957 commit 9e71287

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+4488
-1280
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: Build and Deploy
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
release:
6+
types: [published]
47

58
jobs:
69

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Build Docs
22

3-
on: [push, pull_request]
3+
on: [push]
44

55
jobs:
66
docs:

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
fail_fast: false
1+
fail_fast: true
22
repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
44
rev: 5df1a4bf6f04a1ed3a643167b38d502575e29aef

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Port of [dplyr][2] and other related R packages in python, using [pipda][3].
99

1010
<img width="30%" style="margin: 10px 10px 10px 30px" align="right" src="logo.png">
1111

12-
Unlike other similar packages in python that just mimic the piping sign, `datar` follows the API designs from the original packages as much as possible. So that minimal effort is needed for those who are familar with those R packages to transition to python.
12+
Unlike other similar packages in python that just mimic the piping syntax, `datar` follows the API designs from the original packages as much as possible. So that minimal effort is needed for those who are familar with those R packages to transition to python.
1313

1414

1515
## Installtion

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Port of `dplyr <https://dplyr.tidyverse.org/index.html>`_ and other related R pa
3838

3939
:raw-html-m2r:`<img width="30%" style="margin: 10px 10px 10px 30px" align="right" src="logo.png">`
4040

41-
Unlike other similar packages in python that just mimic the piping sign, ``datar`` follows the API designs from the original packages as much as possible. So that minimal effort is needed for those who are familar with those R packages to transition to python.
41+
Unlike other similar packages in python that just mimic the piping syntax, ``datar`` follows the API designs from the original packages as much as possible. So that minimal effort is needed for those who are familar with those R packages to transition to python.
4242

4343
Installtion
4444
-----------

datar/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
from .core import frame_format_patch as _
55
from .core.defaults import f
66

7-
__version__ = '0.2.3'
7+
__version__ = '0.3.0'

datar/base/seq.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,37 @@
1717
@register_func(None, context=Context.EVAL)
1818
def seq_along(
1919
along_with: Iterable[Any],
20-
_base0: Optional[bool] = None
20+
base0_: Optional[bool] = None
2121
) -> ArrayLikeType:
2222
"""Generate sequences along an iterable
2323
2424
Args:
2525
along_with: An iterable to seq along with
26-
_base0: Whether the generated sequence should be 0-based.
26+
base0_: Whether the generated sequence should be 0-based.
2727
If not provided, will use `datar.base.get_option('index.base.0')`
2828
2929
Returns:
3030
The generated sequence.
3131
"""
32-
_base0 = get_option('index.base.0', _base0)
33-
return Array(range(len(along_with))) + int(not _base0)
32+
base0_ = get_option('index.base.0', base0_)
33+
return Array(range(len(along_with))) + int(not base0_)
3434

3535
@register_func(None, context=Context.EVAL)
3636
def seq_len(
3737
length_out: IntOrIter,
38-
_base0: Optional[bool] = None
38+
base0_: Optional[bool] = None
3939
) -> ArrayLikeType:
4040
"""Generate sequences with the length"""
41-
_base0 = get_option('index.base.0', _base0)
41+
base0_ = get_option('index.base.0', base0_)
4242
if is_scalar(length_out):
43-
return Array(range(int(length_out))) + int(not _base0)
43+
return Array(range(int(length_out))) + int(not base0_)
4444
if len(length_out) > 1:
4545
logger.warning(
4646
"In seq_len(%r) : first element used of 'length_out' argument",
4747
length_out
4848
)
4949
length_out = int(list(length_out)[0])
50-
return Array(range(length_out)) + int(not _base0)
50+
return Array(range(length_out)) + int(not base0_)
5151

5252

5353
@register_func(None, context=Context.EVAL)
@@ -57,23 +57,23 @@ def seq(
5757
by: IntType = None,
5858
length_out: IntType = None,
5959
along_with: IntType = None,
60-
_base0: Optional[bool] = None,
60+
base0_: Optional[bool] = None,
6161
) -> ArrayLikeType:
6262
"""Generate a sequence
6363
6464
https://rdrr.io/r/base/seq.html
6565
6666
Note that this API is consistent with r-base's seq. 1-based and inclusive.
6767
"""
68-
_base0 = get_option('index.base.0', _base0)
68+
base0_ = get_option('index.base.0', base0_)
6969
if along_with is not None:
70-
return seq_along(along_with, _base0)
70+
return seq_along(along_with, base0_)
7171
if from_ is not None and not is_scalar(from_):
72-
return seq_along(from_, _base0)
72+
return seq_along(from_, base0_)
7373
if length_out is not None and from_ is None and to is None:
7474
return seq_len(length_out)
7575

76-
base = int(not _base0)
76+
base = int(not base0_)
7777

7878
if from_ is None:
7979
from_ = base

datar/base/string.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def grep(
7272
value: bool = False,
7373
fixed: bool = False,
7474
invert: bool = False,
75-
_base0: Optional[bool] = None
75+
base0_: Optional[bool] = None
7676
) -> Iterable[Union[int, str]]:
7777
"""R's grep, get the element in x matching the pattern
7878
@@ -83,7 +83,7 @@ def grep(
8383
value: Return values instead of indices?
8484
fixed: Fixed matching (instead of regex matching)?
8585
invert: Return elements thata don't match instead?
86-
_base0: When return indices, whether return 0-based indices?
86+
base0_: When return indices, whether return 0-based indices?
8787
If not set, will use `datar.base.get_option('which.base.0')`
8888
8989
Returns:
@@ -104,8 +104,8 @@ def grep(
104104
if value:
105105
return x[matched]
106106

107-
_base0 = get_option('which.base.0', _base0)
108-
return numpy.flatnonzero(matched) + int(not _base0)
107+
base0_ = get_option('which.base.0', base0_)
108+
return numpy.flatnonzero(matched) + int(not base0_)
109109

110110
@register_func(None, context=Context.EVAL)
111111
def grepl(
@@ -439,15 +439,15 @@ def substr(
439439
x: StringOrIter,
440440
start: IntOrIter,
441441
stop: IntOrIter,
442-
_base0: Optional[bool] = None
442+
base0_: Optional[bool] = None
443443
) -> StringOrIter:
444444
"""Extract substrings in strings.
445445
446446
Args:
447447
x: The strings
448448
start: The start positions to extract
449449
stop: The stop positions to extract
450-
_base0: Whether `start` and `stop` are 0-based
450+
base0_: Whether `start` and `stop` are 0-based
451451
If not provided, will use `datar.base.get_option('index.base.0')`
452452
453453
Returns:
@@ -456,15 +456,15 @@ def substr(
456456
if is_scalar(x) and is_scalar(start) and is_scalar(stop):
457457
if is_null(x):
458458
return NA
459-
_base0 = get_option('index.base.0', _base0)
459+
base0_ = get_option('index.base.0', base0_)
460460
x = as_character(x)
461461
lenx = len(x)
462462
# int() converts numpy.int64 to int
463-
start0 = position_at(int(start), lenx, base0=_base0)
463+
start0 = position_at(int(start), lenx, base0=base0_)
464464
stop0 = position_at(
465-
min(int(stop), lenx - int(_base0)),
465+
min(int(stop), lenx - int(base0_)),
466466
lenx,
467-
base0=_base0
467+
base0=base0_
468468
)
469469
return x[start0:stop0+1]
470470

@@ -479,7 +479,7 @@ def substr(
479479
start = recycle_value(start, maxlen)
480480
stop = recycle_value(stop, maxlen)
481481
out = [
482-
substr(elem, start_, stop_, _base0)
482+
substr(elem, start_, stop_, base0_)
483483
for elem, start_, stop_ in zip(x, start, stop)
484484
]
485485
if is_null(out).any():
@@ -491,21 +491,21 @@ def substring(
491491
x: StringOrIter,
492492
first: IntOrIter,
493493
last: IntOrIter = 1000000,
494-
_base0: Optional[bool] = None
494+
base0_: Optional[bool] = None
495495
) -> StringOrIter:
496496
"""Extract substrings in strings.
497497
498498
Args:
499499
x: The strings
500500
start: The start positions to extract
501501
stop: The stop positions to extract
502-
_base0: Whether `start` and `stop` are 0-based
502+
base0_: Whether `start` and `stop` are 0-based
503503
If not provided, will use `datar.base.get_option('index.base.0')`
504504
505505
Returns:
506506
The substrings from `x`
507507
"""
508-
return substr(x, first, last, _base0)
508+
return substr(x, first, last, base0_)
509509

510510
# strsplit --------------------------------
511511

datar/base/which.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,48 @@
88
from ..core.contexts import Context
99

1010
@register_func(None, context=Context.EVAL)
11-
def which(x: Iterable[bool], _base0: Optional[bool] = None) -> Iterable[int]:
11+
def which(x: Iterable[bool], base0_: Optional[bool] = None) -> Iterable[int]:
1212
"""Convert a bool iterable to indexes
1313
1414
Args:
1515
x: An iterable of bools.
1616
Note that non-bool values will be converted into
17-
_base0: Whether the returned indexes are 0-based.
17+
base0_: Whether the returned indexes are 0-based.
1818
Controlled by `get_option('which.base.0')` if not provided
1919
2020
Returns:
2121
The indexes
2222
"""
23-
return numpy.flatnonzero(x) + int(not get_option('which.base.0', _base0))
23+
return numpy.flatnonzero(x) + int(not get_option('which.base.0', base0_))
2424

2525
@register_func(None)
26-
def which_min(x: Iterable, _base0: Optional[bool] = None) -> int:
26+
def which_min(x: Iterable, base0_: Optional[bool] = None) -> int:
2727
"""R's `which.min()`
2828
2929
Get the index of the element with the maximum value
3030
3131
Args:
3232
x: The iterable
33-
_base0: Whether the index to return is 0-based or not.
33+
base0_: Whether the index to return is 0-based or not.
3434
Controlled by `get_option('which.base.0')` if not provided
3535
3636
Returns:
3737
The index of the element with the maximum value
3838
"""
39-
return numpy.argmin(x) + int(not get_option('which.base.0', _base0))
39+
return numpy.argmin(x) + int(not get_option('which.base.0', base0_))
4040

4141
@register_func(None)
42-
def which_max(x: Iterable, _base0: bool = True) -> int:
42+
def which_max(x: Iterable, base0_: bool = True) -> int:
4343
"""R's `which.max()`
4444
4545
Get the index of the element with the minimum value
4646
4747
Args:
4848
x: The iterable
49-
_base0: Whether the index to return is 0-based or not
49+
base0_: Whether the index to return is 0-based or not
5050
Not that this is not controlled by `get_option('index.base.0')`
5151
5252
Returns:
5353
The index of the element with the minimum value
5454
"""
55-
return numpy.argmax(x) + int(not get_option('which.base.0', _base0))
55+
return numpy.argmax(x) + int(not get_option('which.base.0', base0_))

datar/core/collections.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ def __init__(
3636
def _pipda_eval(
3737
self,
3838
data: Any,
39-
context: ContextAnnoType,
40-
level: int = 0
39+
context: ContextAnnoType
4140
) -> Any:
4241
"""Defines how the object should be evaluated when evaluated by
4342
pipda's evaluation"""
44-
self.elems = evaluate_args(self.elems, data, context, level)
43+
self.elems = evaluate_args(self.elems, data, context)
4544
return self
4645

4746
@abstractmethod
@@ -60,9 +59,9 @@ class Collection(CollectionBase, list):
6059
convert them into 0-based finally
6160
6261
The Inverted, Negated and slice objects will be expanded immediately. This
63-
means there is no chance to apply `_base0` that is received later on. So
62+
means there is no chance to apply `base0_` that is received later on. So
6463
the original elements are stored in `self.elems` to wait for a second
65-
evaluation with the correct `_base0`.
64+
evaluation with the correct `base0_`.
6665
6766
Args:
6867
*args: The elements

0 commit comments

Comments
 (0)