diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bc7b1018..d0936fa6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -39,6 +39,7 @@ jobs: poetry install -v pip install wcwidth pip install scipy + pip install python-slugify # reinstall pandas to specific version pip install $PANDAS env: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3ed31e26..2d024be0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,16 +17,15 @@ repos: pass_filenames: false always_run: true language: system -- repo: https://github.com/pre-commit/mirrors-pylint - rev: v2.4.4 +- repo: local hooks: - id: pylint + name: Run pylint files: ^datar/.+$ pass_filenames: false + entry: pylint datar types: [python] - args: [datar] -- repo: local - hooks: + language: system - id: poetry2setuppy name: Convert pyproject.toml to setup.py entry: dephell deps convert --from=poetry --to=setup.py diff --git a/datar/__init__.py b/datar/__init__.py index 4934b6df..d99904a5 100644 --- a/datar/__init__.py +++ b/datar/__init__.py @@ -7,7 +7,7 @@ from .core.defaults import f __all__ = ('f', 'get_versions') -__version__ = "0.4.3" +__version__ = "0.4.4" def get_versions( prnt: bool = True diff --git a/datar/base/__init__.py b/datar/base/__init__.py index 82ca5fdb..efcc0f3c 100644 --- a/datar/base/__init__.py +++ b/datar/base/__init__.py @@ -33,7 +33,7 @@ log, log2, log10, - log1p + log1p, ) from .bessel import bessel_i, bessel_j, bessel_k, bessel_y from .casting import as_double, as_float, as_int, as_integer, as_numeric @@ -50,7 +50,14 @@ is_factor, levels, ) -from .funs import cut, data_context, expandgrid, identity +from .funs import ( + cut, + data_context, + expandgrid, + identity, + make_unique, + make_names, +) from .logical import ( FALSE, TRUE, @@ -75,7 +82,7 @@ seq_along, seq_len, unique, - match + match, ) from .special import ( beta, diff --git a/datar/base/funs.py b/datar/base/funs.py index 15c378be..ae22f300 100644 --- a/datar/base/funs.py +++ b/datar/base/funs.py @@ -4,7 +4,7 @@ registered by `register_verb` and should be placed in `./verbs.py` """ import itertools -from typing import Any, Callable, Iterable, Union +from typing import Any, Callable, Iterable, List, Union import numpy import pandas @@ -12,8 +12,9 @@ from pipda import register_func from ..core.middlewares import WithDataEnv -from ..core.types import NumericType +from ..core.types import NumericType, is_scalar from ..core.contexts import Context +from ..core.names import repair_names @register_func(None, context=Context.EVAL) @@ -131,3 +132,48 @@ def data_context(data: DataFrame) -> Any: The original or modified data """ return WithDataEnv(data) + +def make_names(names: Any, unique: bool = False) -> List[str]: + """Make names available as columns and can be accessed by `df.` + + The names will be transformed using `python-slugify` with + `lowercase=False` and `separator="_"`. When the first character is + a digit, preface it with "_". + + If `unique` is True, the results will be fed into + `datar.core.names.repair_names(names, "unique")` + + Args: + names: The names + if it is scalar, will make it into a list. + Then all elements will be converted into strings + unique: Whether to make the names unique + + Returns: + Converted names + """ + from slugify import slugify + from . import as_character + if is_scalar(names): + names = [names] + names = as_character(names) + names = [slugify(name, separator="_", lowercase=False) for name in names] + names = [f"_{name}" if name[0].isdigit() else name for name in names] + if unique: + return repair_names(names, "unique") + return names + +def make_unique(names: Any) -> List[str]: + """Make the names unique. + + It's a shortcut for `make_names(names, unique=True)` + + Args: + names: The names + if it is scalar, will make it into a list. + Then all elements will be converted into strings + + Returns: + Converted names + """ + return make_names(names, unique=True) diff --git a/datar/tibble/tibble.py b/datar/tibble/tibble.py index 0b462c7a..cbe00589 100644 --- a/datar/tibble/tibble.py +++ b/datar/tibble/tibble.py @@ -3,7 +3,7 @@ from typing import Any, Union, Callable, Mapping, Iterable, Tuple from pandas import DataFrame -from varname import argname2, varname, VarnameRetrievingError +from varname import argname, varname, VarnameException import pipda from pipda import register_func, evaluate_expr @@ -59,13 +59,16 @@ def tibble( args = tuple((arg for arg in args if arg is not None)) if not args and not kwargs: df = DataFrame() if not _rows else DataFrame(index=range(_rows)) - df.__dfname__ = varname(raise_exc=False, ignore=pipda) + try: + df.__dfname__ = varname(ignore=pipda) + except VarnameException: + pass return df names = [None] * len(args) values = list(args) try: - argnames = argname2( + argnames = argname( "*args", frame=frame_, ignore=pipda, @@ -73,8 +76,8 @@ def tibble( vars_only=False, ) if len(argnames) != len(args): - raise VarnameRetrievingError - except VarnameRetrievingError: + raise VarnameException + except VarnameException: argnames = None if argnames: @@ -93,7 +96,10 @@ def tibble( names, values, _name_repair=_name_repair, base0_=base0_, dtypes_=dtypes_ ) - out.__dfname__ = varname(raise_exc=False, frame=frame_, ignore=pipda) + try: + out.__dfname__ = varname(frame=frame_, ignore=pipda) + except VarnameException: + pass if not kwargs and len(args) == 1 and isinstance(args[0], DataFrame): copy_attrs(out, args[0]) @@ -139,8 +145,8 @@ def tibble_row( if df.shape[0] > 1: raise ValueError("All arguments must be size one, use `[]` to wrap.") try: - df.__dfname__ = varname(raise_exc=False) - except VarnameRetrievingError: # pragma: no cover + df.__dfname__ = varname() + except VarnameException: # pragma: no cover df.__dfname__ = None apply_dtypes(df, dtypes_) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4bbfd33d..648a01da 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.4.4 + +- Adopt `varname` `v0.8.0` +- Add `base.make_names()` and `base.make_unique()` + ## 0.4.3 - Adopt `pipda` `0.4.5` diff --git a/docs/reference-maps/base.md b/docs/reference-maps/base.md index 51a6e665..d97b0557 100644 --- a/docs/reference-maps/base.md +++ b/docs/reference-maps/base.md @@ -268,6 +268,8 @@ |[`expandgrid`][115]|Create a Data Frame from All Combinations of Factor Variables|[:material-notebook:][4]| |[`max_col`][136]|Find the maximum position for each row of a matrix|| |[`complete_cases`][137]|Get a bool array indicating whether the values of rows are complete in a data frame.|| +|[`make_names`][137]|Make names available as columns and can be accessed by `df.`|| +|[`make_unique`][138]|Make the names unique, alias of `make_names(names, unique=True)`|| |[**`data_context`**][116]|Mimic R's `with`|[:material-notebook:][4]| @@ -278,133 +280,135 @@ [5]: ../../api/datar.core.options/#datar.core.options.options [6]: ../../api/datar.core.options/#datar.core.options.get_option [7]: ../../api/datar.core.options/#datar.core.options.options_context -[8]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.mean -[9]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.median -[10]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.min -[11]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.max -[12]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.pmin -[13]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.pmax -[14]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.sum -[15]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.abs -[16]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.round -[17]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.var -[18]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.ceiling -[19]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.floor -[20]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.sqrt -[21]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.cov -[22]: ../../api/datar.core.bessel/#datar.core.bessel.bessel_i -[23]: ../../api/datar.core.bessel/#datar.core.bessel.bessel_j -[24]: ../../api/datar.core.bessel/#datar.core.bessel.bessel_k -[25]: ../../api/datar.core.bessel/#datar.core.bessel.bessel_y -[26]: ../../api/datar.core.casting/#datar.core.casting.as_integer -[27]: ../../api/datar.core.casting/#datar.core.casting.as_double -[28]: ../../api/datar.core.casting/#datar.core.casting.as_float -[29]: ../../api/datar.core.casting/#datar.core.casting.as_numeric -[30]: ../../api/datar.core.complex/#datar.core.complex.re -[31]: ../../api/datar.core.complex/#datar.core.complex.mod -[32]: ../../api/datar.core.complex/#datar.core.complex.im -[33]: ../../api/datar.core.complex/#datar.core.complex.arg -[34]: ../../api/datar.core.complex/#datar.core.complex.conj -[35]: ../../api/datar.core.complex/#datar.core.complex.is_complex -[36]: ../../api/datar.core.complex/#datar.core.complex.as_complex -[37]: ../../api/datar.core.cum/#datar.core.cum.cumsum -[38]: ../../api/datar.core.cum/#datar.core.cum.cumprod -[39]: ../../api/datar.core.cum/#datar.core.cum.cummin -[40]: ../../api/datar.core.cum/#datar.core.cum.cummax -[41]: ../../api/datar.core.date/#datar.core.date.as_date -[42]: ../../api/datar.core.factor/#datar.core.factor.factor -[43]: ../../api/datar.core.factor/#datar.core.factor.droplevels -[44]: ../../api/datar.core.factor/#datar.core.factor.levels -[45]: ../../api/datar.core.factor/#datar.core.factor.is_factor -[46]: ../../api/datar.core.factor/#datar.core.factor.as_factor -[47]: ../../api/datar.core.logical/#datar.core.logical.is_true -[48]: ../../api/datar.core.logical/#datar.core.logical.is_false -[49]: ../../api/datar.core.logical/#datar.core.logical.is_logical -[50]: ../../api/datar.core.logical/#datar.core.logical.as_logical -[51]: ../../api/datar.core.na/#datar.core.na.is_na -[52]: ../../api/datar.core.na/#datar.core.na.any_na -[53]: ../../api/datar.core.null/#datar.core.null.is_null -[54]: ../../api/datar.core.null/#datar.core.null.as_null -[55]: ../../api/datar.core.random/#datar.core.random.set_seed -[56]: ../../api/datar.core.seq/#datar.core.seq.c -[57]: ../../api/datar.core.seq/#datar.core.seq.seq -[58]: ../../api/datar.core.seq/#datar.core.seq.seq_len -[59]: ../../api/datar.core.seq/#datar.core.seq.seq_along -[60]: ../../api/datar.core.seq/#datar.core.seq.rev -[61]: ../../api/datar.core.seq/#datar.core.seq.rep -[62]: ../../api/datar.core.seq/#datar.core.seq.lengths -[63]: ../../api/datar.core.seq/#datar.core.seq.unique -[64]: ../../api/datar.core.seq/#datar.core.seq.sample -[65]: ../../api/datar.core.seq/#datar.core.seq.length -[66]: ../../api/datar.core.special/#datar.core.special.beta -[67]: ../../api/datar.core.special/#datar.core.special.lbeta -[68]: ../../api/datar.core.special/#datar.core.special.gamma -[69]: ../../api/datar.core.special/#datar.core.special.lgamma -[70]: ../../api/datar.core.special/#datar.core.special.digamma -[71]: ../../api/datar.core.special/#datar.core.special.trigamma -[72]: ../../api/datar.core.special/#datar.core.special.psigamma -[73]: ../../api/datar.core.special/#datar.core.special.choose -[74]: ../../api/datar.core.special/#datar.core.special.lchoose -[75]: ../../api/datar.core.special/#datar.core.special.factorial -[76]: ../../api/datar.core.special/#datar.core.special.lfactorial -[77]: ../../api/datar.core.string/#datar.core.string.is_character -[78]: ../../api/datar.core.string/#datar.core.string.as_character -[79]: ../../api/datar.core.string/#datar.core.string.grep -[80]: ../../api/datar.core.string/#datar.core.string.grepl -[81]: ../../api/datar.core.string/#datar.core.string.sub -[82]: ../../api/datar.core.string/#datar.core.string.gsub -[83]: ../../api/datar.core.string/#datar.core.string.nchar -[84]: ../../api/datar.core.string/#datar.core.string.nzchar -[85]: ../../api/datar.core.string/#datar.core.string.paste -[86]: ../../api/datar.core.string/#datar.core.string.paste0 -[87]: ../../api/datar.core.string/#datar.core.string.sprintf -[88]: ../../api/datar.core.string/#datar.core.string.substr -[89]: ../../api/datar.core.string/#datar.core.string.substring -[90]: ../../api/datar.core.string/#datar.core.string.strsplit -[91]: ../../api/datar.core.table/#datar.core.table.table -[92]: ../../api/datar.core.testing/#datar.core.testing.is_double -[93]: ../../api/datar.core.testing/#datar.core.testing.is_float -[94]: ../../api/datar.core.testing/#datar.core.testing.is_integer -[95]: ../../api/datar.core.testing/#datar.core.testing.is_atomic -[96]: ../../api/datar.core.testing/#datar.core.testing.is_element -[97]: ../../api/datar.core.trig_hb/#datar.core.trig_hb.cos -[98]: ../../api/datar.core.trig_hb/#datar.core.trig_hb.sin -[99]: ../../api/datar.core.trig_hb/#datar.core.trig_hb.tan -[100]: ../../api/datar.core.trig_hb/#datar.core.trig_hb.acos -[101]: ../../api/datar.core.trig_hb/#datar.core.trig_hb.asin -[102]: ../../api/datar.core.trig_hb/#datar.core.trig_hb.atan -[103]: ../../api/datar.core.trig_hb/#datar.core.trig_hb.atan2 -[104]: ../../api/datar.core.trig_hb/#datar.core.trig_hb.cospi -[105]: ../../api/datar.core.trig_hb/#datar.core.trig_hb.sinpi -[106]: ../../api/datar.core.trig_hb/#datar.core.trig_hb.tanpi -[107]: ../../api/datar.core.trig_hb/#datar.core.trig_hb.cosh -[108]: ../../api/datar.core.trig_hb/#datar.core.trig_hb.sinh -[109]: ../../api/datar.core.trig_hb/#datar.core.trig_hb.tanh -[110]: ../../api/datar.core.trig_hb/#datar.core.trig_hb.acosh -[111]: ../../api/datar.core.trig_hb/#datar.core.trig_hb.asinh -[112]: ../../api/datar.core.trig_hb/#datar.core.trig_hb.atanh -[113]: ../../api/datar.core.funs/#datar.core.funs.cut -[114]: ../../api/datar.core.funs/#datar.core.funs.identity -[115]: ../../api/datar.core.funs/#datar.core.funs.expandgrid -[116]: ../../api/datar.core.funs/#datar.core.funs.data_context -[117]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.prod -[118]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.sign -[119]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.trunc -[120]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.exp -[121]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.log -[122]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.log2 -[123]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.log10 -[124]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.log1p -[125]: ../../api/datar.core.arithmetic/#datar.core.arithmetic.signif -[126]: ../../api/datar.core.na/#datar.core.na.is_finite -[127]: ../../api/datar.core.na/#datar.core.na.is_infinite -[128]: ../../api/datar.core.na/#datar.core.na.is_nan -[129]: ../../api/datar.core.seq/#datar.core.seq.match -[130]: ../../api/datar.core.string/#datar.core.string.startswith -[131]: ../../api/datar.core.string/#datar.core.string.endswith -[132]: ../../api/datar.core.string/#datar.core.string.strtoi -[133]: ../../api/datar.core.string/#datar.core.string.chartr -[134]: ../../api/datar.core.string/#datar.core.string.tolower -[135]: ../../api/datar.core.string/#datar.core.string.toupper -[136]: ../../api/datar.core.verbs/#datar.core.verbs.max_col -[137]: ../../api/datar.core.verbs/#datar.core.verbs.complete_cases +[8]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.mean +[9]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.median +[10]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.min +[11]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.max +[12]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.pmin +[13]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.pmax +[14]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.sum +[15]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.abs +[16]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.round +[17]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.var +[18]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.ceiling +[19]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.floor +[20]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.sqrt +[21]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.cov +[22]: ../../api/datar.base.bessel/#datar.base.bessel.bessel_i +[23]: ../../api/datar.base.bessel/#datar.base.bessel.bessel_j +[24]: ../../api/datar.base.bessel/#datar.base.bessel.bessel_k +[25]: ../../api/datar.base.bessel/#datar.base.bessel.bessel_y +[26]: ../../api/datar.base.casting/#datar.base.casting.as_integer +[27]: ../../api/datar.base.casting/#datar.base.casting.as_double +[28]: ../../api/datar.base.casting/#datar.base.casting.as_float +[29]: ../../api/datar.base.casting/#datar.base.casting.as_numeric +[30]: ../../api/datar.base.complex/#datar.base.complex.re +[31]: ../../api/datar.base.complex/#datar.base.complex.mod +[32]: ../../api/datar.base.complex/#datar.base.complex.im +[33]: ../../api/datar.base.complex/#datar.base.complex.arg +[34]: ../../api/datar.base.complex/#datar.base.complex.conj +[35]: ../../api/datar.base.complex/#datar.base.complex.is_complex +[36]: ../../api/datar.base.complex/#datar.base.complex.as_complex +[37]: ../../api/datar.base.cum/#datar.base.cum.cumsum +[38]: ../../api/datar.base.cum/#datar.base.cum.cumprod +[39]: ../../api/datar.base.cum/#datar.base.cum.cummin +[40]: ../../api/datar.base.cum/#datar.base.cum.cummax +[41]: ../../api/datar.base.date/#datar.base.date.as_date +[42]: ../../api/datar.base.factor/#datar.base.factor.factor +[43]: ../../api/datar.base.factor/#datar.base.factor.droplevels +[44]: ../../api/datar.base.factor/#datar.base.factor.levels +[45]: ../../api/datar.base.factor/#datar.base.factor.is_factor +[46]: ../../api/datar.base.factor/#datar.base.factor.as_factor +[47]: ../../api/datar.base.logical/#datar.base.logical.is_true +[48]: ../../api/datar.base.logical/#datar.base.logical.is_false +[49]: ../../api/datar.base.logical/#datar.base.logical.is_logical +[50]: ../../api/datar.base.logical/#datar.base.logical.as_logical +[51]: ../../api/datar.base.na/#datar.base.na.is_na +[52]: ../../api/datar.base.na/#datar.base.na.any_na +[53]: ../../api/datar.base.null/#datar.base.null.is_null +[54]: ../../api/datar.base.null/#datar.base.null.as_null +[55]: ../../api/datar.base.random/#datar.base.random.set_seed +[56]: ../../api/datar.base.seq/#datar.base.seq.c +[57]: ../../api/datar.base.seq/#datar.base.seq.seq +[58]: ../../api/datar.base.seq/#datar.base.seq.seq_len +[59]: ../../api/datar.base.seq/#datar.base.seq.seq_along +[60]: ../../api/datar.base.seq/#datar.base.seq.rev +[61]: ../../api/datar.base.seq/#datar.base.seq.rep +[62]: ../../api/datar.base.seq/#datar.base.seq.lengths +[63]: ../../api/datar.base.seq/#datar.base.seq.unique +[64]: ../../api/datar.base.seq/#datar.base.seq.sample +[65]: ../../api/datar.base.seq/#datar.base.seq.length +[66]: ../../api/datar.base.special/#datar.base.special.beta +[67]: ../../api/datar.base.special/#datar.base.special.lbeta +[68]: ../../api/datar.base.special/#datar.base.special.gamma +[69]: ../../api/datar.base.special/#datar.base.special.lgamma +[70]: ../../api/datar.base.special/#datar.base.special.digamma +[71]: ../../api/datar.base.special/#datar.base.special.trigamma +[72]: ../../api/datar.base.special/#datar.base.special.psigamma +[73]: ../../api/datar.base.special/#datar.base.special.choose +[74]: ../../api/datar.base.special/#datar.base.special.lchoose +[75]: ../../api/datar.base.special/#datar.base.special.factorial +[76]: ../../api/datar.base.special/#datar.base.special.lfactorial +[77]: ../../api/datar.base.string/#datar.base.string.is_character +[78]: ../../api/datar.base.string/#datar.base.string.as_character +[79]: ../../api/datar.base.string/#datar.base.string.grep +[80]: ../../api/datar.base.string/#datar.base.string.grepl +[81]: ../../api/datar.base.string/#datar.base.string.sub +[82]: ../../api/datar.base.string/#datar.base.string.gsub +[83]: ../../api/datar.base.string/#datar.base.string.nchar +[84]: ../../api/datar.base.string/#datar.base.string.nzchar +[85]: ../../api/datar.base.string/#datar.base.string.paste +[86]: ../../api/datar.base.string/#datar.base.string.paste0 +[87]: ../../api/datar.base.string/#datar.base.string.sprintf +[88]: ../../api/datar.base.string/#datar.base.string.substr +[89]: ../../api/datar.base.string/#datar.base.string.substring +[90]: ../../api/datar.base.string/#datar.base.string.strsplit +[91]: ../../api/datar.base.table/#datar.base.table.table +[92]: ../../api/datar.base.testing/#datar.base.testing.is_double +[93]: ../../api/datar.base.testing/#datar.base.testing.is_float +[94]: ../../api/datar.base.testing/#datar.base.testing.is_integer +[95]: ../../api/datar.base.testing/#datar.base.testing.is_atomic +[96]: ../../api/datar.base.testing/#datar.base.testing.is_element +[97]: ../../api/datar.base.trig_hb/#datar.base.trig_hb.cos +[98]: ../../api/datar.base.trig_hb/#datar.base.trig_hb.sin +[99]: ../../api/datar.base.trig_hb/#datar.base.trig_hb.tan +[100]: ../../api/datar.base.trig_hb/#datar.base.trig_hb.acos +[101]: ../../api/datar.base.trig_hb/#datar.base.trig_hb.asin +[102]: ../../api/datar.base.trig_hb/#datar.base.trig_hb.atan +[103]: ../../api/datar.base.trig_hb/#datar.base.trig_hb.atan2 +[104]: ../../api/datar.base.trig_hb/#datar.base.trig_hb.cospi +[105]: ../../api/datar.base.trig_hb/#datar.base.trig_hb.sinpi +[106]: ../../api/datar.base.trig_hb/#datar.base.trig_hb.tanpi +[107]: ../../api/datar.base.trig_hb/#datar.base.trig_hb.cosh +[108]: ../../api/datar.base.trig_hb/#datar.base.trig_hb.sinh +[109]: ../../api/datar.base.trig_hb/#datar.base.trig_hb.tanh +[110]: ../../api/datar.base.trig_hb/#datar.base.trig_hb.acosh +[111]: ../../api/datar.base.trig_hb/#datar.base.trig_hb.asinh +[112]: ../../api/datar.base.trig_hb/#datar.base.trig_hb.atanh +[113]: ../../api/datar.base.funs/#datar.base.funs.cut +[114]: ../../api/datar.base.funs/#datar.base.funs.identity +[115]: ../../api/datar.base.funs/#datar.base.funs.expandgrid +[116]: ../../api/datar.base.funs/#datar.base.funs.data_context +[117]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.prod +[118]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.sign +[119]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.trunc +[120]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.exp +[121]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.log +[122]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.log2 +[123]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.log10 +[124]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.log1p +[125]: ../../api/datar.base.arithmetic/#datar.base.arithmetic.signif +[126]: ../../api/datar.base.na/#datar.base.na.is_finite +[127]: ../../api/datar.base.na/#datar.base.na.is_infinite +[128]: ../../api/datar.base.na/#datar.base.na.is_nan +[129]: ../../api/datar.base.seq/#datar.base.seq.match +[130]: ../../api/datar.base.string/#datar.base.string.startswith +[131]: ../../api/datar.base.string/#datar.base.string.endswith +[132]: ../../api/datar.base.string/#datar.base.string.strtoi +[133]: ../../api/datar.base.string/#datar.base.string.chartr +[134]: ../../api/datar.base.string/#datar.base.string.tolower +[135]: ../../api/datar.base.string/#datar.base.string.toupper +[136]: ../../api/datar.base.verbs/#datar.base.verbs.max_col +[137]: ../../api/datar.base.verbs/#datar.base.verbs.complete_cases +[138]: ../../api/datar.base.funs/#datar.base.funs.make_names +[139]: ../../api/datar.base.funs/#datar.base.funs.make_unique diff --git a/pyproject.toml b/pyproject.toml index 8213f03e..77761242 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "datar" -version = "0.4.3" +version = "0.4.4" description = "Port of dplyr and other related R packages in python, using pipda." authors = ["pwwang "] readme = "README.md" @@ -17,6 +17,7 @@ varname = "*" pandas = "^1.2" scipy = { version = "^1.6", optional = true } wcwidth = { version = "^0.2", optional = true } +python-slugify = {version = "^5.0.2", optional = true} [tool.poetry.dev-dependencies] pytest = "*" diff --git a/requirements.txt b/requirements.txt index 41361fc6..8c4d954e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,6 +4,7 @@ pandas==1.*,>=1.2.0 pipda pytest pytest-cov +python-slugify==5.*,>=5.0.2 scipy==1.*,>=1.6.0 varname wcwidth==0.*,>=0.2.0 diff --git a/setup.py b/setup.py index 32d795fe..5823dacf 100644 --- a/setup.py +++ b/setup.py @@ -24,19 +24,16 @@ setup( long_description=readme, name='datar', - version='0.4.3', + version='0.4.4', description='Port of dplyr and other related R packages in python, using pipda.', python_requires='==3.*,>=3.7.1', - project_urls={"homepage": "https://github.com/pwwang/datar", - "repository": "https://github.com/pwwang/datar"}, + project_urls={"homepage": "https://github.com/pwwang/datar", "repository": "https://github.com/pwwang/datar"}, author='pwwang', author_email='pwwang@pwwang.com', license='MIT', - packages=['datar', 'datar.base', 'datar.core', 'datar.datar', 'datar.datasets', - 'datar.dplyr', 'datar.stats', 'datar.tibble', 'datar.tidyr', 'datar.utils'], + packages=['datar', 'datar.base', 'datar.core', 'datar.datar', 'datar.datasets', 'datar.dplyr', 'datar.stats', 'datar.tibble', 'datar.tidyr', 'datar.utils'], package_dir={"": "."}, package_data={"datar.datasets": ["*.gz"]}, - install_requires=['diot', 'executing', 'pandas==1.*,>=1.2.0', - 'pipda', 'scipy==1.*,>=1.6.0', 'varname', 'wcwidth==0.*,>=0.2.0'], + install_requires=['diot', 'executing', 'pandas==1.*,>=1.2.0', 'pipda', 'python-slugify==5.*,>=5.0.2', 'scipy==1.*,>=1.6.0', 'varname', 'wcwidth==0.*,>=0.2.0'], extras_require={"dev": ["pytest", "pytest-cov"]}, ) diff --git a/tests/test_base_funs.py b/tests/test_base_funs.py index 5ae808c0..c9e741c7 100644 --- a/tests/test_base_funs.py +++ b/tests/test_base_funs.py @@ -81,3 +81,19 @@ def test_outer(): ["11", "12", "13"], ["21", "22", "23"] ])) + +def test_make_names(): + names = ["a", "1aA b", "_1aA b"] + assert_iterable_equal( + make_names(names), + ['a', '_1aA_b', '_1aA_b'] + ) + assert_iterable_equal( + make_names(names, unique=True), + ['a', '_1aA_b__2', '_1aA_b__3'] + ) + assert_iterable_equal( + make_unique(names), + ['a', '_1aA_b__2', '_1aA_b__3'] + ) + assert make_names(1) == ['_1']