diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100644 index 0000000000000000000000000000000000000000..3d7459ba2410c663b83fbc9f3e506f748c7468cc --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,76 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed. +# Called by "git commit" with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message if +# it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-commit". + +if git rev-parse --verify HEAD >/dev/null 2>&1 +then + against=HEAD +else + # Initial commit: diff against an empty tree object + against=$(git hash-object -t tree /dev/null) +fi + +# If you want to allow non-ASCII filenames set this variable to true. +allownonascii=$(git config --bool hooks.allownonascii) + +# Redirect output to stderr. +exec 1>&2 + +# Cross platform projects tend to avoid non-ASCII filenames; prevent +# them from being added to the repository. We exploit the fact that the +# printable range starts at the space character and ends with tilde. +if [ "$allownonascii" != "true" ] && + # Note that the use of brackets around a tr range is ok here, (it's + # even required, for portability to Solaris 10's /usr/bin/tr), since + # the square bracket bytes happen to fall in the designated range. + test $(git diff --cached --name-only --diff-filter=A -z $against | + LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 +then + cat <<\EOF +Error: Attempt to add a non-ASCII file name. + +This can cause problems if you want to work with people on other platforms. + +To be portable it is advisable to rename the file. + +If you know what you are doing you can disable this check using: + + git config hooks.allownonascii true +EOF + exit 1 +fi + +# If there are whitespace errors, print the offending file names and fail. +#exec git diff-index --check --cached $against -- + + + +# NOTE: To activate all hooks in this directory, +# run "git config --local core.hooksPath .githooks" + +# Indicate that hook is running. +echo "------ BEGIN CUSTOM ${0##*/} HOOK ------" + +# Find staged .py files. +PYFILES=$( + git diff --staged --name-only --diff-filter=ACM | + sed -n '/.*\.py/ { s| |\\ |g ; p}' +) + +# Format staged .py files. +if [ -n "$PYFILES" ]; then + if ! black $PYFILES; then + exit 1 + else + git add $PYFILES + fi +fi + +# Indicate that hook is finished. +echo "------ END CUSTOM ${0##*/} HOOK ------" + diff --git a/examples/overview_complex.py b/examples/overview_complex.py index 79d5dfeae519f993962ea97aa227bd4934ea7777..16c38d548e17ad13e52b05a31bcb98f104052762 100644 --- a/examples/overview_complex.py +++ b/examples/overview_complex.py @@ -10,38 +10,48 @@ import facetswrapper def load_data(): """Load UCI census train and test data into dataframes.""" - features = ["Age", "Workclass", "fnlwgt", "Education", "Education-Num", "Marital Status", - "Occupation", "Relationship", "Race", "Sex", "Capital Gain", "Capital Loss", - "Hours per week", "Country", "Target"] + features = [ + "Age", + "Workclass", + "fnlwgt", + "Education", + "Education-Num", + "Marital Status", + "Occupation", + "Relationship", + "Race", + "Sex", + "Capital Gain", + "Capital Loss", + "Hours per week", + "Country", + "Target", + ] result = pd.read_csv( "https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.test", names=features, - sep=r'\s*,\s*', + sep=r"\s*,\s*", skiprows=[0], - engine='python', - na_values="?") + engine="python", + na_values="?", + ) return result def write_overview_html(data, output_filepath): """Generate overview html code and write it in a file.""" - overview_html = facetswrapper.overview.overview_html(data, groupby=["Target", "Sex"]) - with open(output_filepath, 'w') as file: + overview_html = facetswrapper.overview.overview_html( + data, groupby=["Target", "Sex"] + ) + with open(output_filepath, "w") as file: file.write(overview_html) if __name__ == "__main__": - print("Loading data... ", end='', flush=True) + print("Loading data... ", end="", flush=True) data = load_data() - print('Done') - print('Generating HTML page... ', end='', flush=True) - output_filepath = Path(sys.argv[0]).with_suffix('.html') + print("Done") + print("Generating HTML page... ", end="", flush=True) + output_filepath = Path(sys.argv[0]).with_suffix(".html") write_overview_html(data, output_filepath) - print('Done') - - - - - - - + print("Done") diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000000000000000000000000000000000..a4967d1743f45c172ce9e9f30ede159c4f01e5a5 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[tool.black] +exclude = '/(\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|_build|buck-out|build|dist|venv|src/facets)/' diff --git a/setup.py b/setup.py index 9b6c02b01a6a175fdae5cc17adfa01aa198f7140..53cb3d9bd67c00468d3a1ec21c393825c9b96dfd 100644 --- a/setup.py +++ b/setup.py @@ -26,10 +26,10 @@ setup( license="", url="https://gitlab.com/sivan.altinakar/facetswrapper", project_urls={ - 'Documentation': 'https://gitlab.com/sivan.altinakar/facetswrapper/blob/master/README.md', + "Documentation": "https://gitlab.com/sivan.altinakar/facetswrapper/blob/master/README.md", # 'Funding': 'https://donate.pypi.org', # 'Say Thanks!': 'http://saythanks.io/to/example', - 'Source': 'https://gitlab.com/sivan.altinakar/facetswrapper', + "Source": "https://gitlab.com/sivan.altinakar/facetswrapper", # 'Tracker': 'https://github.com/pypa/sampleproject/issues', }, packages=find_packages("src"), @@ -39,13 +39,8 @@ setup( include_package_data=True, zip_safe=False, python_requires=">=3.6", - install_requires=[ - 'pandas', - 'protobuf', - ], - extras_require={ # Optional - 'test': [], - }, + install_requires=["pandas", "protobuf"], + extras_require={"dev": ["black"]}, # Optional classifiers=( "Development Status :: 4 - Beta", "Intended Audience :: Science/Research", @@ -54,7 +49,7 @@ setup( "Programming Language :: Python :: 3", "Topic :: Scientific/Engineering :: Visualization", ), - keywords='dataviz data_visualization wrapper', + keywords="dataviz data_visualization wrapper", ) @@ -73,5 +68,3 @@ pip install --no-deps -e . python3 setup.py sdist bdist_wheel ``` """ - - diff --git a/src/facetswrapper/__init__.py b/src/facetswrapper/__init__.py index 1c23fd3285b49ed20d8437680d064b592f02a154..13a9ca717f53dccb2b492dcc8e44ed42564394d8 100644 --- a/src/facetswrapper/__init__.py +++ b/src/facetswrapper/__init__.py @@ -1 +1 @@ -from .overview import overview_html \ No newline at end of file +from .overview import overview_html diff --git a/src/facetswrapper/overview.py b/src/facetswrapper/overview.py index 09b8551728c2f27dd5536cf39d6453e86d60a8f5..e193c2d86940627a151273c9320825e48cdb1938 100644 --- a/src/facetswrapper/overview.py +++ b/src/facetswrapper/overview.py @@ -10,7 +10,9 @@ import sys # from pathlib import Path # print(Path.cwd()) -from facets.facets_overview.python.generic_feature_statistics_generator import GenericFeatureStatisticsGenerator +from facets.facets_overview.python.generic_feature_statistics_generator import ( + GenericFeatureStatisticsGenerator, +) import base64 # import pandas as pandas