Skip to content

Commit

Permalink
Simplify dependencies. Make statsmodels optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
BSchilperoort committed Sep 13, 2024
1 parent 23eebc5 commit fe7a3df
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
9 changes: 3 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,13 @@ classifiers = [
"Topic :: Utilities",
]
dependencies = [
"numpy>=1.22.4, <=2.0.1", # >= 1.22 for quantile method support in xarray. https://github.com/statsmodels/statsmodels/issues/9333
"dask",
"numpy",
"xarray[accel]",
"dask[distributed]",
"pandas",
"xarray[parallel]", # numbagg (llvmlite) is a pain to install with pip
"bottleneck", # speeds up Xarray
"flox", # speeds up Xarray
"pyyaml>=6.0.1",
"xmltodict",
"scipy",
"statsmodels",
"matplotlib",
"netCDF4>=1.6.4",
"nc-time-axis>=1.4.1" # plot dependency of xarray
Expand Down
10 changes: 9 additions & 1 deletion src/dtscalibration/calibrate_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np
import scipy.sparse as sp
import statsmodels.api as sm
import xarray as xr
from scipy.sparse import linalg as ln

Expand Down Expand Up @@ -2124,6 +2123,15 @@ def wls_stats(X, y, w=1.0, calc_cov=False, x0=None, return_werr=False, verbose=F
p_cov : ndarray
The covariance of the solution.
"""
try:
import statsmodels.api as sm
except ImportError as err:
msg = (
"Statsmodels has to be installed for this function.\n"
"Install it with `pip install statsmodels`."
)
raise ImportError(msg) from err

y = np.asarray(y)
w = np.asarray(w)

Expand Down
9 changes: 8 additions & 1 deletion src/dtscalibration/variance_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,14 @@ def variance_stokes_exponential_helper(

if use_statsmodels:
# returns the same answer with statsmodel
import statsmodels.api as sm
try:
import statsmodels.api as sm
except ImportError as err:
msg = (
"Statsmodels has to be installed for this function.\n"
"Install it with `pip install statsmodels`."
)
raise ImportError(msg) from err

X = sp.coo_matrix(
(data, coords), shape=(nt * n_locs, ddof), dtype=float, copy=False
Expand Down

0 comments on commit fe7a3df

Please sign in to comment.