Skip to content

Commit abdb098

Browse files
authored
0.5.0 (#52)
* Specify calling env for verbs internally for 1) better performance and 2) ensurance of pipda.options.assume_all_piping working thoroughly. * Add forcats * Add forcats * Fix linting * Add tests for forcats * Fix tests where factor get lost for fct_count() result for pandas < 1.3 * Remove README.rst
1 parent 4052194 commit abdb098

Some content is hidden

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

62 files changed

+9061
-376
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,6 @@ docs/*/*.nbconvert.ipynb
116116

117117
# vscode's local history extension
118118
.history/
119+
120+
# For quick test
121+
/_t.py

.pre-commit-config.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ repos:
2626
entry: pylint datar
2727
types: [python]
2828
language: system
29-
- id: poetry2setuppy
30-
name: Convert pyproject.toml to setup.py
31-
entry: dephell deps convert --from=poetry --to=setup.py
32-
language: system
33-
files: pyproject.toml
34-
pass_filenames: false
35-
- id: poetry2requirements
36-
name: Convert pyproject.toml to requirements.txt
37-
entry: dephell deps convert --from=poetry --to=requirements.txt
38-
language: system
39-
files: pyproject.toml
40-
pass_filenames: false
29+
# - id: poetry2setuppy
30+
# name: Convert pyproject.toml to setup.py
31+
# entry: dephell deps convert --from=poetry --to=setup.py
32+
# language: system
33+
# files: pyproject.toml
34+
# pass_filenames: false
35+
# - id: poetry2requirements
36+
# name: Convert pyproject.toml to requirements.txt
37+
# entry: dephell deps convert --from=poetry --to=requirements.txt
38+
# language: system
39+
# files: pyproject.toml
40+
# pass_filenames: false
4141
# - id: mypycheck
4242
# name: Type checking by mypy
4343
# entry: mypy

.pylintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ disable=print-statement,
161161
fixme,
162162
consider-using-dict-items,
163163
unexpected-keyword-arg,
164+
consider-using-with,
164165
C0330
165166

166167
# Enable the message, report, category or checker with the given id(s). You can

README.rst

Lines changed: 0 additions & 140 deletions
This file was deleted.

datar/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .core.defaults import f
88

99
__all__ = ('f', 'get_versions')
10-
__version__ = "0.4.4"
10+
__version__ = "0.5.0"
1111

1212
def get_versions(
1313
prnt: bool = True

datar/all.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from .tibble import *
1616
from .tidyr import *
1717
from .utils import *
18+
from .forcats import *
1819

1920
_builtin_names = _base_builtin_names.copy()
2021
_builtin_names.update(_dplyr_builtin_names)

datar/base/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@
4848
factor,
4949
is_categorical,
5050
is_factor,
51+
is_ordered,
5152
levels,
53+
nlevels,
54+
ordered,
5255
)
5356
from .funs import (
5457
cut,
@@ -57,6 +60,7 @@
5760
identity,
5861
make_unique,
5962
make_names,
63+
rank,
6064
)
6165
from .logical import (
6266
FALSE,
@@ -75,12 +79,14 @@
7579
c,
7680
length,
7781
lengths,
82+
order,
7883
rep,
7984
rev,
8085
sample,
8186
seq,
8287
seq_along,
8388
seq_len,
89+
sort,
8490
unique,
8591
match,
8692
)
@@ -123,7 +129,7 @@
123129
tolower,
124130
toupper,
125131
)
126-
from .table import table
132+
from .table import table, tabulate
127133
from .testing import (
128134
is_atomic,
129135
is_double,
@@ -155,6 +161,7 @@
155161
tanpi,
156162
)
157163
from .verbs import (
164+
append,
158165
colnames,
159166
diag,
160167
dim,
@@ -163,6 +170,8 @@
163170
names,
164171
ncol,
165172
nrow,
173+
prop_table,
174+
proportions,
166175
rownames,
167176
setdiff,
168177
setequal,

datar/base/arithmetic.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy
66
from pandas import DataFrame, Series
77
from pipda import register_func, register_verb
8+
from pipda.utils import CallingEnvs
89

910
from ..core.collections import Collection
1011
from ..core.contexts import Context
@@ -13,7 +14,7 @@
1314
NumericOrIter,
1415
NumericType,
1516
is_not_null,
16-
is_scalar
17+
is_scalar,
1718
)
1819
from ..core.utils import Array, length_of, recycle_value, register_numpy_func_x
1920

@@ -264,11 +265,9 @@ def round(x: NumericOrIter, ndigits: int = 0) -> NumericOrIter:
264265
""",
265266
)
266267

268+
267269
@register_func(None, context=Context.EVAL)
268-
def signif(
269-
x: NumericOrIter,
270-
digits: int = 6
271-
) -> NumericOrIter:
270+
def signif(x: NumericOrIter, digits: int = 6) -> NumericOrIter:
272271
"""Rounds the values in its first argument to the specified number of
273272
significant digits
274273
@@ -282,9 +281,10 @@ def signif(
282281
# todo complex?
283282
return numpy.fromiter(
284283
(round(elem, digits - int(ceiling(log10(abs(elem))))) for elem in x),
285-
dtype=float
284+
dtype=float,
286285
)
287286

287+
288288
# pylint: disable=unused-argument
289289
@register_verb(DataFrame, context=Context.EVAL)
290290
def cov(x: DataFrame, y: Iterable = None, ddof: int = 1) -> DataFrame:
@@ -329,11 +329,11 @@ def scale(
329329
out_attrs = {}
330330

331331
if center is True:
332-
center = col_means(x)
332+
center = col_means(x, __calling_env=CallingEnvs.REGULAR)
333333

334334
elif center is not False:
335335
if is_scalar(center):
336-
center = [center] # type: ignore
336+
center = [center] # type: ignore
337337
if len(center) != ncols:
338338
raise ValueError(
339339
f"length of `center` ({len(center)}) must equal "
@@ -351,11 +351,15 @@ def _rms(col: Series) -> Series:
351351
nonnas = col[is_not_null(col)] ** 2
352352
return sqrt(nonnas.sum() / (len(nonnas) - 1))
353353

354-
scale = col_sds(x) if center_is_true else x.agg(_rms)
354+
scale = (
355+
col_sds(x, __calling_env=CallingEnvs.REGULAR)
356+
if center_is_true
357+
else x.agg(_rms)
358+
)
355359

356360
elif scale is not False:
357361
if is_scalar(scale):
358-
scale = [scale] # type: ignore
362+
scale = [scale] # type: ignore
359363
if len(scale) != ncols:
360364
raise ValueError(
361365
f"length of `scale` ({len(center)}) must equal "
@@ -571,6 +575,7 @@ def row_medians(
571575
"""
572576
return x.agg(median, axis=1, na_rm=na_rm)
573577

578+
574579
@register_func(None, context=Context.EVAL)
575580
def log(x: NumericOrIter, base: float = numpy.e) -> FloatOrIter:
576581
"""Computes logarithms, by default natural logarithm
@@ -588,6 +593,7 @@ def log(x: NumericOrIter, base: float = numpy.e) -> FloatOrIter:
588593

589594
return numpy.log(x) / numpy.log(base)
590595

596+
591597
exp = register_numpy_func_x(
592598
"exp",
593599
"exp",
@@ -598,7 +604,7 @@ def log(x: NumericOrIter, base: float = numpy.e) -> FloatOrIter:
598604
599605
Returns:
600606
Power of natural number of element-wise power of natural number for x
601-
"""
607+
""",
602608
)
603609

604610
log2 = register_numpy_func_x(
@@ -612,7 +618,7 @@ def log(x: NumericOrIter, base: float = numpy.e) -> FloatOrIter:
612618
Returns:
613619
The value of log2 if x is scalar, otherwise element-wise
614620
log2 of elements in x
615-
"""
621+
""",
616622
)
617623

618624
log10 = register_numpy_func_x(
@@ -626,7 +632,7 @@ def log(x: NumericOrIter, base: float = numpy.e) -> FloatOrIter:
626632
Returns:
627633
The value of log10 if x is scalar, otherwise element-wise
628634
log10 of elements in x
629-
"""
635+
""",
630636
)
631637

632638
log1p = register_numpy_func_x(
@@ -640,5 +646,5 @@ def log(x: NumericOrIter, base: float = numpy.e) -> FloatOrIter:
640646
Returns:
641647
The value of log(1+x) if x is scalar, otherwise element-wise
642648
log(1+x) of elements in x
643-
"""
649+
""",
644650
)

0 commit comments

Comments
 (0)