Skip to content
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
14 changes: 4 additions & 10 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,22 @@ on:
jobs:
publish:
runs-on: ubuntu-latest
permissions:
id-token: write
Comment on lines +10 to +11
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workflow grants id-token: write but still authenticates via PYPI_API_TOKEN. If you’re not using PyPI Trusted Publishing, drop the id-token permission to follow least privilege; if you are, switch the publish step to OIDC/trusted publishing and remove the API token secret usage.

Suggested change
permissions:
id-token: write

Copilot uses AI. Check for mistakes.
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- 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
9 changes: 5 additions & 4 deletions elapid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
)


Expand Down Expand Up @@ -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")
Expand Down
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "elapid"
version = "1.0.2"
version = "1.0.3"
description = "Species distribution modeling tools"
authors = ["Christopher Anderson <cbanderson08@gmail.com>"]
license = "MIT"
Expand All @@ -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]
Expand Down
14 changes: 10 additions & 4 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)

Expand Down