From 127331f54e001b7920e434aab2b23b53875fe09c Mon Sep 17 00:00:00 2001 From: Ross Markello Date: Tue, 18 Dec 2018 16:20:08 -0500 Subject: [PATCH] [TEST] Pandas optional --- .travis.yml | 8 +++++--- pyls/examples/datasets.py | 12 ++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index b7158ce..3b6001b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,14 +15,13 @@ env: matrix: - LINTING=1 - DOCTEST=1 - - JOBLIB=1 + - JOBLIB=1 PANDAS=1 matrix: include: - python: 3.6 env: - - COVERAGE=1 - - JOBLIB=1 + - COVERAGE=1 JOBLIB=1 PANDAS=1 - python: 3.7 dist: xenial sudo: required @@ -43,6 +42,9 @@ before_install: - if [ "${JOBLIB}" == "1" ]; then pip install joblib; fi + - if [ "${PANDAS}" == "1" ]; then + pip install pandas; + fi install: - if [ "${DOCTEST}" == "1" ]; then diff --git a/pyls/examples/datasets.py b/pyls/examples/datasets.py index 7764dc8..ee7fb7d 100644 --- a/pyls/examples/datasets.py +++ b/pyls/examples/datasets.py @@ -10,10 +10,15 @@ import urllib import numpy as np -import pandas as pd from ..structures import PLSInputs +try: + import pandas as pd + pandas_avail = True +except ImportError: + pandas_avail = False + with open(resource_filename('pyls', 'examples/datasets.json'), 'r') as src: _DATASETS = json.load(src) @@ -132,7 +137,10 @@ def load_dataset(name, data_dir=None, verbose=1, return_reference=False): if isinstance(value, str) and key in PLSInputs.allowed: fname = os.path.join(data_dir, name, value) if fname.endswith('.csv'): - value = pd.read_csv(fname, index_col=0) + if pandas_avail: + value = pd.read_csv(fname, index_col=0) + else: + value = np.loadtxt(fname, skiprows=1, delimiter=',')[:, 1:] elif fname.endswith('.txt'): value = np.loadtxt(fname) elif fname.endswith('.npy'):