From fe7a3df74f0b3388a1e4129f33c70e84aa5f8160 Mon Sep 17 00:00:00 2001 From: Bart Schilperoort Date: Fri, 13 Sep 2024 08:53:52 +0200 Subject: [PATCH] Simplify dependencies. Make statsmodels optional. --- pyproject.toml | 9 +++------ src/dtscalibration/calibrate_utils.py | 10 +++++++++- src/dtscalibration/variance_helpers.py | 9 ++++++++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 262badc..0ce0ccd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/src/dtscalibration/calibrate_utils.py b/src/dtscalibration/calibrate_utils.py index dba3b8a..3cdcde0 100644 --- a/src/dtscalibration/calibrate_utils.py +++ b/src/dtscalibration/calibrate_utils.py @@ -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 @@ -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) diff --git a/src/dtscalibration/variance_helpers.py b/src/dtscalibration/variance_helpers.py index ee66ff5..a24d3e8 100644 --- a/src/dtscalibration/variance_helpers.py +++ b/src/dtscalibration/variance_helpers.py @@ -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