Convenient helper functions, decorators, and data analysis tools to make life easier with minimal dependencies:
pip install py-utilz
dplyr like data grammar:
from utilz import pipe
import utilz.dfverbs as _
out = pipe(
df,
_.rename({"weight (male, lbs)": "male", "weight (female, lbs)": "female"}),
_.pivot_longer(columns=["male", "female"], into=("sex", "weight")),
_.split("weight", ("min", "max"), sep="-"),
_.pivot_longer(columns=["min", "max"], into=("stat", "weight")),
_.astype({"weight": float}),
_.groupby("genus", "sex"),
_.mutate(weight="weight.mean()"),
_.pivot_wider(column="sex", using="weight"),
_.mutate(dimorphism="male / female")
)
from utilz import map
# Combine function results into a list, array, or dataframe
map(myfunc, myiterable)
# Syntactic sugar for joblib.Parallel
map(myfunc, myiterable, n_jobs=4)
from utilz import log, maybe
# Print the shape of args and outputs before and after execute
@log
def myfunc(args):
return out
# Only run myfunc if results.csv doesn't eist
@maybe
def myfunc(args, out_file=None):
return out
myfunc(args, out_file='results.csv')
- Install poetry:
curl -sSL https://install.python-poetry.org | python
- Setup virtual environment
poetry install --with dev
- Run all tests:
poetry run pytest
- Live render docs:
poetry run mkdocs serve
- Activate environment in current shell:
source activate .venv/bin/activate
- Activate environment in sub-process shell:
poetry shell
- Add/remove additional packages:
poetry add/remove package_name
- Build local package:
poetry build
- Deploy to pypi:
poetry publish
(requires auth)