diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml index a7adccd..1ce1ef1 100644 --- a/.github/workflows/publish-pypi.yml +++ b/.github/workflows/publish-pypi.yml @@ -7,6 +7,8 @@ on: jobs: publish: runs-on: ubuntu-latest + permissions: + id-token: write steps: - uses: actions/checkout@v4 - name: Install poetry @@ -14,21 +16,13 @@ jobs: - name: Python setup uses: actions/setup-python@v5 with: - python-version: 3.9 - cache: 'poetry' - cache-dependency-path: "pyproject.toml" - - name: Install package - run: | - python -m pip install --upgrade pip - pip install wheel - pip install . + python-version: 3.11 - name: Build package run: | - poetry build -o dist + poetry build - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1 with: - user: __token__ password: ${{ secrets.PYPI_API_TOKEN }} packages_dir: ./dist verbose: true diff --git a/elapid/models.py b/elapid/models.py index 3f06b31..c979743 100644 --- a/elapid/models.py +++ b/elapid/models.py @@ -4,6 +4,7 @@ import matplotlib.pyplot as plt import numpy as np +from numpy.exceptions import AxisError from scipy import stats as scistats from sklearn.base import BaseEstimator from sklearn.exceptions import NotFittedError @@ -359,7 +360,7 @@ def fit( a .fit_transform() method. Some examples include a PCA() object or a RobustScaler(). """ - + # clear state variables self.alpha_ = 0.0 self.entropy_ = 0.0 @@ -563,7 +564,7 @@ def initialize_sklearn_model(self, C: float, fit_intercept: bool = True) -> None solver="liblinear", tol=self.convergence_tolerance, max_iter=self.n_lambdas, - random_state=self.random_state + random_state=self.random_state, ) @@ -840,14 +841,14 @@ def format_occurrence_data(y: ArrayLike) -> ArrayLike: formatted uint8 ndarray of shape (n_samples,) Raises: - np.AxisError: an array with 2 or more columns is passed + np.exceptions.AxisError: an array with 2 or more columns is passed """ if not isinstance(y, np.ndarray): y = np.array(y) if y.ndim > 1: if y.shape[1] > 1 or y.ndim > 2: - raise np.AxisError(f"Multi-column y data passed of shape {y.shape}. Must be 1d or 1 column.") + raise AxisError(f"Multi-column y data passed of shape {y.shape}. Must be 1d or 1 column.") y = y.flatten() return y.astype("uint8") diff --git a/pyproject.toml b/pyproject.toml index 6a7fa1d..4b5ee75 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "elapid" -version = "1.0.2" +version = "1.0.3" description = "Species distribution modeling tools" authors = ["Christopher Anderson "] license = "MIT" @@ -12,14 +12,15 @@ include = [ [tool.poetry.dependencies] python = ">=3.9" -numpy = ">=1.18,<2.0" -pandas = ">=1.0.3" +numpy = ">=2.0" +pandas = ">=1.0.3,<3.0" pyproj = ">3.0" geopandas = ">=1.0" rasterio = ">=1.2.1" tqdm = ">=4.60" rtree = ">=0.9" scikit-learn = ">=1.2,<1.6" +scipy = ">=1.13" matplotlib = ">=3.7" [tool.poetry.group.dev.dependencies] diff --git a/tests/test_models.py b/tests/test_models.py index 27412a2..456257f 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,5 +1,6 @@ import numpy as np import pytest +from numpy.exceptions import AxisError from sklearn import metrics from sklearn.decomposition import PCA from sklearn.linear_model import LogisticRegression @@ -113,6 +114,7 @@ def test_sklearn_MaxentModel(): assert ypred.max() <= 1.0 assert ypred.min() >= 0.0 + def test_MaxentModel_random_state_behavior(): model1 = models.MaxentModel(random_state=1) model2 = models.MaxentModel(random_state=1) @@ -124,11 +126,15 @@ def test_MaxentModel_random_state_behavior(): model3 = models.MaxentModel(random_state=2) model3.fit(x, y) - ypred3 = model3.predict(x) - + ypred3 = model3.predict(x) + if np.allclose(ypred1, ypred3): import warnings - warnings.warn("MaxentModel predictions are identical for different random_state values; model may be deterministic for this configuration.") + + warnings.warn( + "MaxentModel predictions are identical for different random_state values; model may be deterministic for this configuration." + ) + def test_format_occurrence_data(): # add a trailing dimension @@ -137,7 +143,7 @@ def test_format_occurrence_data(): model.fit(x, yt) # fail on >2 dims - with pytest.raises(np.AxisError): + with pytest.raises(AxisError): ytt = np.concatenate((yt, yt), axis=1) model.fit(x, ytt)