Skip to content

Commit

Permalink
[TEST] Pandas optional
Browse files Browse the repository at this point in the history
  • Loading branch information
rmarkello committed Dec 18, 2018
1 parent 893f223 commit 5967325
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,6 +41,8 @@ before_install:
fi
- if [ "${JOBLIB}" == "1" ]; then
pip install joblib;
- if [ "${PANDAS}" == "1" ]; then
pip install pandas;
fi

install:
Expand Down
12 changes: 10 additions & 2 deletions pyls/examples/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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'):
Expand Down

0 comments on commit 5967325

Please sign in to comment.