Skip to content

Commit

Permalink
0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pwwang committed Mar 6, 2021
1 parent ddfb965 commit ee12bb9
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 11 deletions.
37 changes: 37 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,40 @@ repos:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- repo: local
hooks:
- id: masterpylintrc
name: Overwrite local .pylintrc by master one
entry: cp ../.pylintrc ./.pylintrc
pass_filenames: false
always_run: true
language: system
- repo: https://github.com/pre-commit/mirrors-pylint
rev: v2.4.4
hooks:
- id: pylint
files: ^datar/.+$
pass_filenames: false
types: [python]
args: [datar]
- repo: local
hooks:
- id: poetry2setuppy
name: Convert pyproject.toml to setup.py
entry: dephell deps convert --from=poetry --to=setup.py
language: system
files: pyproject.toml
pass_filenames: false
- id: poetry2requirements
name: Convert pyproject.toml to requirements.txt
entry: dephell deps convert --from=poetry --to=requirements.txt
language: system
files: pyproject.toml
pass_filenames: false
- id: pytest
name: Run pytest
entry: pytest
language: system
args: [tests/]
pass_filenames: false
files: ^tests/.+$|^pipda/.+$
2 changes: 1 addition & 1 deletion datar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

f = Symbolic() # pylint: disable=invalid-name

__version__ = '0.0.0'
__version__ = '0.0.1'
36 changes: 28 additions & 8 deletions datar/tidyr/verbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from typing import Any, Callable, Mapping, Optional, Type, Union

import numpy
from numpy.core.fromnumeric import shape
import pandas
from pandas import DataFrame, Series
from pandas import DataFrame
from pandas.core.groupby.generic import DataFrameGroupBy
from pipda import register_verb, Context

from ..core.utils import select_columns, list_diff
from ..core.types import IntOrIter, StringOrIter, is_scalar
from ..core.utils import objectize, select_columns, list_diff
from ..core.types import DataFrameType, IntOrIter, StringOrIter, is_scalar

@register_verb(DataFrame, context=Context.SELECT)
def pivot_longer(
Expand Down Expand Up @@ -207,13 +207,31 @@ def get_new_colname(cols, names):

return ret

@register_verb(DataFrame, context=Context.EVAL)
@register_verb((DataFrame, DataFrameGroupBy), context=Context.EVAL)
def uncount(
_data: DataFrame,
_data: DataFrameType,
weights: IntOrIter,
_remove: bool = True,
_id: Optional[str] = None,
) -> DataFrame:
) -> DataFrameType:
"""Duplicating rows according to a weighting variable
Args:
_data: A data frame
weights: A vector of weights. Evaluated in the context of data
_remove: If TRUE, and weights is the name of a column in data,
then this column is removed.
_id: Supply a string to create a new variable which gives a
unique identifier for each created row (0-based).
Returns:
dataframe with rows repeated.
"""
gnames = (
_data.grouper.names
if isinstance(_data, DataFrameGroupBy) else None
)
_data = objectize(_data)
if is_scalar(weights):
weights = [weights] * _data.shape[0]

Expand All @@ -231,7 +249,9 @@ def uncount(

ret = _data.loc[indexes, rest_columns] if _remove else _data.loc[indexes, :]
if _id:
return ret.groupby(rest_columns).apply(
ret = ret.groupby(rest_columns).apply(
lambda df: df.assign(**{_id: range(df.shape[0])})
).reset_index(drop=True, level=0)
if gnames:
return ret.groupby(gnames, dropna=False)
return ret
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "datar"
version = "0.0.0"
version = "0.0.1"
description = "Probably the closest port of tidyr, dplyr and tibble in python"
authors = ["pwwang <[email protected]>"]
license = "MIT"
Expand Down
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
modkit
pandas==1.*,>=1.2.0
pipda
pytest
pytest-cov
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
setup(
long_description=readme,
name='datar',
version='0.0.0',
version='0.0.1',
description='Probably the closest port of tidyr, dplyr and tibble in python',
python_requires='==3.*,>=3.7.1',
author='pwwang',
Expand Down

0 comments on commit ee12bb9

Please sign in to comment.