Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.1.2 #37

Merged
merged 3 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CD

on:
pull_request:
types: [closed]
branches:
- main

jobs:
build-n-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: 3.10

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install tox

- name: Test With Tox
run: tox -e pytest

- name: Build and Publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
tox -r -e build,publish
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ jobs:
run: |
make lint
make lint-notebooks
continue-on-error: true
continue-on-error: false

- name: Run Tests with Tox
- name: Run Tests and Coverage
run: |
make tox
make coverage

# TO DO: Add codecov
# - name: Upload coverage to Codecov
Expand Down
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ PYLINT := pylint
TOX := $(PYTHON) -m tox
SETUP := $(PYTHON) setup.py

DIR := denseclus

.PHONY: lint lint-notebooks test coverage tox install install-dev pypi clean help

lint:
@echo "Running linting..."
@$(BLACK) denseclus tests setup.py
@$(RUFF) denseclus tests setup.py --fix --preview
@$(PYLINT) denseclus --disable=R0902,W0222,W0221,C0103,W0632
@$(BLACK) $(DIR) tests setup.py
@$(RUFF) $(DIR) tests setup.py --fix --preview
@$(PYLINT) $(DIR) --disable=R0902,W0222,W0221,C0103,W0632

lint-notebooks:
@echo "Linting notebooks..."
Expand All @@ -29,7 +31,7 @@ test:
coverage:
@echo "Running coverage..."
@$(COVERAGE) erase
@$(COVERAGE) run --include=denseclus/* -m pytest -ra
@$(COVERAGE) run --source=$(DIR) -m pytest -ra
@$(COVERAGE) report -m

tox:
Expand Down
20 changes: 14 additions & 6 deletions denseclus/DenseClus.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,14 @@ def __init__(
self.umap_params = default_umap_params

if hdbscan_params:
self.hdbscan_params = hdbscan_params
self.hdbscan_params = hdbscan_params # pragma: no cover
else:
self.hdbscan_params = default_hdbscan_params

if verbose:
if verbose: # pragma: no cover
logger.setLevel(logging.DEBUG)
self.verbose = True
else:
else: # pragma: no cover
logger.setLevel(logging.ERROR)
self.verbose = False

Expand All @@ -201,13 +201,21 @@ def noop(*args, **kargs):

if isinstance(random_state, int):
np.random.seed(seed=random_state)
else:
else: # pragma: no cover
logger.info("No random seed passed, running UMAP in Numba, parallel")

self.kwargs = kwargs

def __repr__(self):
return str(self.__dict__)
def __repr__(self): # pragma: no cover
return f"""DenseClus(random_state={self.random_state}
,umap_combine_method={self.umap_combine_method}
,umap_params={self.umap_params}
,hdbscan_params={self.hdbscan_params})"""

def __str__(self): # pragma: no cover
return f"""DenseClus object (random_state={self.random_state}
,umap_combine_method={self.umap_combine_method}
,verbose={self.verbose})"""

def fit(self, df: pd.DataFrame) -> None:
"""Fits the UMAP and HDBSCAN models to the provided data.
Expand Down
4 changes: 2 additions & 2 deletions denseclus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .DenseClus import DenseClus
from .utils import extract_categorical, extract_numerical

__version__ = "0.1.1"
__version__ = "0.1.2"

if __name__ == "__main__":
if __name__ == "__main__": # pragma: no cover
print(type(DenseClus), type(extract_categorical), type(extract_numerical))
4 changes: 0 additions & 4 deletions denseclus/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ def extract_categorical(
raise TypeError("Input should be a pandas DataFrame")
if df.empty:
raise ValueError("Input DataFrame should not be empty.")
if df.shape[1] < 1:
raise ValueError("Input DataFrame should have at least one column.")

categorical = df.select_dtypes(exclude=["float", "int"])

Expand Down Expand Up @@ -128,8 +126,6 @@ def extract_numerical(df: pd.DataFrame, impute_strategy: str = "median", **kwarg
raise TypeError("Input should be a pandas DataFrame")
if df.empty:
raise ValueError("Input DataFrame should not be empty.")
if df.shape[1] < 1:
raise ValueError("Input DataFrame should have at least one column.")

numerical = df.select_dtypes(include=["float", "int"])
if numerical.shape[1] == 0:
Expand Down
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ exclude = [
]

[tool.pytest.ini_options]
addopts = "--cov=src --cov-report=term-missing"
addopts = "--cov=denseclus --cov-report=term-missing"
markers = [
"unit",
"integration"
"fast",
"slow"
]

[tool.pytest]
Expand All @@ -96,6 +96,9 @@ doctest_optionflags = [
"ELLIPSIS",
"NUMBER",
]
filterwarnings = [
"ignore::UserWarning"
]

[tool.pylint.'MESSAGES CONTROL']
disable = [
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setuptools.setup(
name="amazon_denseclus",
version="0.1.1",
version="0.1.2",
author="Charles Frenzel & Baichuan Sun",
description="Dense Clustering for Mixed Data Types",
long_description=long_description,
Expand Down
10 changes: 10 additions & 0 deletions tests/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,13 @@ def test_extract_numerical_columns(df, numerical_df):
# Test with DataFrame with no numeric columns
with pytest.raises(ValueError):
extract_numerical(pd.DataFrame({"col1": ["a", "b", "c"]}))


def test_impute_categorical_strategy_error(categorical_df):
with pytest.raises(ValueError):
impute_categorical(categorical_df, strategy="median", fill_value="Error")


def test_impute_numerical_strategy_error(numerical_df):
with pytest.raises(ValueError):
impute_numerical(numerical_df, strategy="constant")
59 changes: 19 additions & 40 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,20 @@
[main]
line_len = 100
src_dir =
notebooks
denseclus

[tox]
isolated_build = True
minversion = 3.15
envlist = py310

requires = tox>=3.15

[testenv]
deps =
pytest
pytest-cov
ruff
black
coverage
mypy
pylint

description = invoke pytest to run automated tests
;install_command = pip install {opts} {packages}
Expand All @@ -32,13 +28,9 @@ passenv =
extras =
testing
commands =
pytest --cov=src --cov-report=term-missing {posargs}
black denseclus
ruff denseclus --fix --preview
pylint --fail-under=7 denseclus --disable=R0902,W0222,W0221,C0103
mypy denseclus
coverage erase
coverage run --include=denseclus/* -m pytest -ra
pytest {posargs}
mypy {[main]src_dir}
coverage run --include={[main]src_dir}/* -m pytest -ra
coverage report -m


Expand Down Expand Up @@ -90,43 +82,17 @@ commands =
python -m twine upload {posargs:--repository pypi} dist/*


[mypy]
ignore_missing_imports = True
files = **/*.py

[pytest]
addopts =
-v
filterwarnings =
# https://github.com/boto/boto3/issues/1968
ignore:Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated

[testenv:ruff]
description = check ruff formatting for CI
deps =
ruff
commands =
ruff --max-complexity=20 --exclude=build/, .git, __pycache__, .*_cache, examples/, .tox, data/, venv/, .venv/ --ignore=E203,W503,E722,E231 {[main]src_dir}

[testenv:isort-check]
description = check ruff formatting for CI
[testenv:lint]
deps = ruff
commands =
ruff --line-length=100 --check --atomic --profile=black {[main]src_dir}


[testenv:black-check]
description = check black formatting for CI
deps = black==23.11.0
commands =
black -l {[main]line_len} --check {[main]src_dir}

[testenv:mypy]
deps =
mypy
commands =
mypy --config-file tox.ini {[main]src_dir}

commands = ruff --max-complexity=20 --exclude=build/, .git, __pycache__, .*_cache, examples/, .tox, data/, venv/, .venv/ --ignore=E203,W503,E722,E231 {[main]src_dir}

[testenv:pytest]
deps =
Expand All @@ -138,3 +104,16 @@ commands =
[gh-actions]
python =
3.10: py310


[testenv:mypy]
deps =
mypy
commands =
mypy --config-file tox.ini {[main]src_dir}
ignore_missing_imports = True
files = {[main]src_dir}/*.py

[mypy]
ignore_missing_imports = True
files = {[main]src_dir}/*.py
Loading