Skip to content

Commit 3d6e182

Browse files
authored
Do not depend on pkg not specified in setup.py (#214)
* Added a test agains missing dependencies * Make sure distributed is installed automatically * Make the joblib dependency optional * Make the sklearn dependency optional
1 parent 501e130 commit 3d6e182

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

.github/workflows/test.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,44 @@ jobs:
170170
pytest tests
171171
env:
172172
DASK_SQL_TEST_SCHEDULER: tcp://127.0.0.1:8786
173+
test_import:
174+
name: "Test importing with bare requirements"
175+
needs: build
176+
runs-on: ubuntu-latest
177+
steps:
178+
- uses: actions/checkout@v2
179+
- name: Cache local Maven repository
180+
uses: actions/cache@v2
181+
with:
182+
path: ~/.m2/repository
183+
key: ${{ runner.os }}-maven-v1-11-${{ hashFiles('**/pom.xml') }}
184+
- name: Cache downloaded conda packages
185+
uses: actions/cache@v2
186+
with:
187+
path: ~/conda_pkgs_dir
188+
key: ${{ runner.os }}-conda-v2-11-${{ hashFiles('conda.txt') }}
189+
- name: Set up Python
190+
uses: conda-incubator/setup-miniconda@v2
191+
with:
192+
python-version: 3.8
193+
mamba-version: "*"
194+
channels: conda-forge,defaults
195+
channel-priority: true
196+
use-only-tar-bz2: true
197+
- name: Download the pre-build jar
198+
uses: actions/download-artifact@v1
199+
with:
200+
name: jar
201+
path: dask_sql/jar/
202+
- name: Install dependencies and nothing else
203+
shell: bash -l {0}
204+
run: |
205+
pip install -e .
206+
207+
which python
208+
pip list
209+
mamba list
210+
- name: Try to import dask-sql
211+
shell: bash -l {0}
212+
run: |
213+
python -c "import dask_sql; print('ok')"

dask_sql/physical/rel/custom/export_model.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import logging
22
import pickle
33

4-
import joblib
5-
import sklearn
6-
74
from dask_sql.physical.rel.base import BaseRelPlugin
85
from dask_sql.utils import convert_sql_kwargs
96

@@ -62,16 +59,21 @@ def convert(
6259
with open(location, "wb") as pkl_file:
6360
pickle.dump(model, pkl_file, **kwargs)
6461
elif format == "joblib":
65-
joblib.dump(model, location, **kwargs)
62+
import joblib
6663

64+
joblib.dump(model, location, **kwargs)
6765
elif format == "mlflow":
6866
try:
6967
import mlflow
7068
except ImportError: # pragma: no cover
7169
raise ImportError(
7270
f"For export in the mlflow format, you need to have mlflow installed"
7371
)
74-
if isinstance(model, sklearn.base.BaseEstimator):
72+
try:
73+
import sklearn
74+
except ImportError: # pragma: no cover
75+
sklearn = None
76+
if sklearn is not None and isinstance(model, sklearn.base.BaseEstimator):
7577
mlflow.sklearn.save_model(model, location, **kwargs)
7678
else:
7779
raise NotImplementedError(

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def run(self):
7474
python_requires=">=3.6",
7575
setup_requires=["setuptools_scm"] + sphinx_requirements,
7676
install_requires=[
77-
"dask[dataframe]>=2.19.0,!=2021.3.0", # dask 2021.3.0 makes
77+
"dask[dataframe,distributed]>=2.19.0,!=2021.3.0", # dask 2021.3.0 makes
7878
# dask-ml fail (see https://github.com/dask/dask-ml/issues/803)
7979
"pandas>=1.0.0", # below 1.0, there were no nullable ext. types
8080
"jpype1>=1.0.2",

0 commit comments

Comments
 (0)