Skip to content

Commit

Permalink
Merge pull request #19 from ak-gupta/develop
Browse files Browse the repository at this point in the history
v0.2.1
  • Loading branch information
ak-gupta authored Apr 19, 2024
2 parents 3026ee0 + 674d8d2 commit 7698288
Show file tree
Hide file tree
Showing 26 changed files with 852 additions and 609 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/edgetest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ jobs:
- uses: actions/checkout@v2
with:
ref: develop

- id: run-edgetest
uses: fdosani/run-edgetest-action@v1.0
uses: edgetest-dev/run-edgetest-action@v1.4
with:
edgetest-flags: '-c setup.cfg -r requirements.txt --export'
edgetest-flags: '-c pyproject.toml -r requirements.txt --export'
base-branch: 'develop'
skip-pr: 'false'
2 changes: 1 addition & 1 deletion .github/workflows/publish-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
python-version: '3.9'
- name: Install dependencies
run: python -m pip install -r requirements.txt .[dev]
- name: Build and publish
Expand Down
25 changes: 18 additions & 7 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,40 @@ jobs:
strategy:
matrix:
python_version:
- 3.7
- 3.8
- 3.9
- '3.10'
- '3.11'
steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install setuptools and upgrade pip
run: python -m pip install 'setuptools>=64.0.0' 'pip>=22.3'

- name: Install dependencies
run: python -m pip install -r requirements.txt .[dev]
- name: Check docstrings
run: python -m pydocstyle bayte --convention=numpy
run: python -m pip install -r requirements.txt .[plots,tests,qa]

- name: Run ruff QA checks
run: python -m ruff check .

- name: Check formatting
run: python -m ruff format . --check

- name: Check static typing
run: python -m mypy bayte
- name: Run flake8
run: python -m flake8 bayte

- name: Run unit testing
run: python -m pytest tests --cov=./bayte --cov-report=xml

- name: Run Codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
files: ./coverage.xml
verbose: true
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Akshay Gupta

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 4 additions & 5 deletions bayte/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"""Import path."""

from ._meta import __version__ # noqa: F401

from typing import List

from .encoder import BayesianTargetEncoder
from .ensemble import BayesianTargetClassifier, BayesianTargetRegressor
from bayte._meta import __version__ # noqa: F401
from bayte.encoder import BayesianTargetEncoder
from bayte.ensemble import BayesianTargetClassifier, BayesianTargetRegressor

__all__: List[str] = [
"BayesianTargetEncoder",
"BayesianTargetClassifier",
"BayesianTargetEncoder",
"BayesianTargetRegressor",
]
2 changes: 1 addition & 1 deletion bayte/_meta.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Package metadata."""

__version__ = "0.1.1"
__version__ = "0.2.1"
27 changes: 19 additions & 8 deletions bayte/encoder.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Bayesian target encoder."""

import logging
from typing import Callable, List, Optional, Tuple, Union
from typing import Callable, ClassVar, List, Optional, Tuple, Union

from joblib import Parallel, effective_n_jobs
import numpy as np
import scipy.stats
from joblib import Parallel, effective_n_jobs
from sklearn.preprocessing._encoders import _BaseEncoder
from sklearn.utils.fixes import delayed
from sklearn.utils.validation import check_is_fitted
Expand Down Expand Up @@ -242,7 +242,7 @@ class BayesianTargetEncoder(_BaseEncoder):
the parameters for the posterior distribution for the given level.
"""

_required_parameters = ["dist"]
_required_parameters: ClassVar[List[str]] = ["dist"]

def __init__(
self,
Expand Down Expand Up @@ -283,8 +283,15 @@ def fit(self, X, y):
self : object
Fitted encoder.
"""
X, y = self._validate_data(X, y, dtype=None)
self._fit(X, handle_unknown=self.handle_unknown, force_all_finite=True)
tags = self._get_tags()
X, y = self._validate_data(
X, y, dtype=None, force_all_finite=not tags.get("allow_nan", True)
)
self._fit(
X,
handle_unknown=self.handle_unknown,
force_all_finite=not tags.get("allow_nan", True),
)
# Initialize the prior distribution parameters
initializer_ = self.initializer or _init_prior
self.prior_params_ = initializer_(self.dist, y)
Expand Down Expand Up @@ -322,10 +329,11 @@ def transform(self, X):
"""
check_is_fitted(self)

tags = self._get_tags()
X_int, X_mask = self._transform(
X,
handle_unknown=self.handle_unknown,
force_all_finite=True,
force_all_finite=not tags.get("allow_nan", True),
)

if effective_n_jobs(self.n_jobs) == 1:
Expand Down Expand Up @@ -376,14 +384,17 @@ def transform(self, X):
n_chunks = np.ceil(len(varencoded) / self.chunksize)
chunks = np.array_split(np.arange(len(varencoded)), n_chunks)

varencoded = list(
varencoded = [
np.ma.stack(varencoded[chunk[0] : chunk[-1] + 1], axis=2).sum(
axis=2
)
for chunk in chunks
)
]

combined = np.ma.stack(varencoded, axis=2).sum(axis=2)
encoded.append(combined.data)

return np.hstack(encoded)

def _more_tags(self):
return {"allow_nan": False}
Loading

0 comments on commit 7698288

Please sign in to comment.