Skip to content

Commit 54dcf7b

Browse files
authored
Merge pull request #133 from thequackdaddy/fix_travis
MAINT: Travis fixes
2 parents f64e780 + 20f8fc6 commit 54dcf7b

File tree

3 files changed

+56
-25
lines changed

3 files changed

+56
-25
lines changed

.travis.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ before_install:
4040
- conda config --set always_yes yes --set changeps1 no
4141
- conda update -q conda
4242
- conda info -a
43-
- conda create -q -n testenv python=$TRAVIS_PYTHON_VERSION numpy scipy coverage nose pip
43+
- export PKGS="numpy scipy coverage nose pip"
44+
- if [ "$PANDAS_VERSION_STR" != "NONE" ]; then export PKGS="${PKGS} pandas${PANDAS_VERSION_STR}"; fi
45+
- conda create -q -n testenv python=$TRAVIS_PYTHON_VERSION ${PKGS}
4446
- source activate testenv
45-
- if [ "$PANDAS_VERSION_STR" != "NONE" ]; then conda install pandas${PANDAS_VERSION_STR}; fi
4647
install:
4748
- python setup.py sdist
4849
- pip install dist/*

patsy/constraint.py

+22-9
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
from patsy.origin import Origin
1818
from patsy.util import (atleast_2d_column_default,
1919
repr_pretty_delegate, repr_pretty_impl,
20-
SortAnythingKey,
2120
no_pickling, assert_no_pickling)
22-
from patsy.infix_parser import Token, Operator, ParseNode, infix_parse
21+
from patsy.infix_parser import Token, Operator, infix_parse
22+
from patsy.parse_formula import _parsing_error_test
23+
2324

2425
class LinearConstraint(object):
2526
"""A linear constraint in matrix form.
@@ -87,7 +88,10 @@ def combine(cls, constraints):
8788
return cls(variable_names, coefs, constants)
8889

8990
def test_LinearConstraint():
90-
from numpy.testing.utils import assert_equal
91+
try:
92+
from numpy.testing import assert_equal
93+
except ImportError:
94+
from numpy.testing.utils import assert_equal
9195
lc = LinearConstraint(["foo", "bar"], [1, 1])
9296
assert lc.variable_names == ["foo", "bar"]
9397
assert_equal(lc.coefs, [[1, 1]])
@@ -96,7 +100,7 @@ def test_LinearConstraint():
96100
lc = LinearConstraint(["foo", "bar"], [[1, 1], [2, 3]], [10, 20])
97101
assert_equal(lc.coefs, [[1, 1], [2, 3]])
98102
assert_equal(lc.constants, [[10], [20]])
99-
103+
100104
assert lc.coefs.dtype == np.dtype(float)
101105
assert lc.constants.dtype == np.dtype(float)
102106

@@ -124,21 +128,24 @@ def test_LinearConstraint_combine():
124128
comb = LinearConstraint.combine([LinearConstraint(["a", "b"], [1, 0]),
125129
LinearConstraint(["a", "b"], [0, 1], [1])])
126130
assert comb.variable_names == ["a", "b"]
127-
from numpy.testing.utils import assert_equal
131+
try:
132+
from numpy.testing import assert_equal
133+
except ImportError:
134+
from numpy.testing.utils import assert_equal
128135
assert_equal(comb.coefs, [[1, 0], [0, 1]])
129136
assert_equal(comb.constants, [[0], [1]])
130137

131138
from nose.tools import assert_raises
132139
assert_raises(ValueError, LinearConstraint.combine, [])
133140
assert_raises(ValueError, LinearConstraint.combine,
134141
[LinearConstraint(["a"], [1]), LinearConstraint(["b"], [1])])
135-
142+
136143

137144
_ops = [
138145
Operator(",", 2, -100),
139146

140147
Operator("=", 2, 0),
141-
148+
142149
Operator("+", 1, 100),
143150
Operator("-", 1, 100),
144151
Operator("+", 2, 100),
@@ -408,8 +415,12 @@ def linear_constraint(constraint_like, variable_names):
408415
coefs = np.asarray(constraint_like, dtype=float)
409416
return LinearConstraint(variable_names, coefs)
410417

418+
411419
def _check_lincon(input, varnames, coefs, constants):
412-
from numpy.testing.utils import assert_equal
420+
try:
421+
from numpy.testing import assert_equal
422+
except ImportError:
423+
from numpy.testing.utils import assert_equal
413424
got = linear_constraint(input, varnames)
414425
print("got", got)
415426
expected = LinearConstraint(varnames, coefs, constants)
@@ -420,6 +431,7 @@ def _check_lincon(input, varnames, coefs, constants):
420431
assert_equal(got.coefs.dtype, np.dtype(float))
421432
assert_equal(got.constants.dtype, np.dtype(float))
422433

434+
423435
def test_linear_constraint():
424436
from nose.tools import assert_raises
425437
from patsy.compat import OrderedDict
@@ -495,6 +507,7 @@ def test_linear_constraint():
495507
# unknown object type
496508
assert_raises(ValueError, linear_constraint, None, ["a", "b"])
497509

510+
498511
_parse_eval_error_tests = [
499512
# Bad token
500513
"a + <f>oo",
@@ -512,7 +525,7 @@ def test_linear_constraint():
512525
"a = 1, <(a, b)> + 2, c",
513526
]
514527

515-
from patsy.parse_formula import _parsing_error_test
528+
516529
def test_eval_errors():
517530
def doit(bad_code):
518531
return linear_constraint(bad_code, ["a", "b", "c"])

patsy/util.py

+31-14
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
have_pandas_categorical_dtype = (_pandas_is_categorical_dtype
5656
is not None)
5757

58+
5859
# Passes through Series and DataFrames, call np.asarray() on everything else
5960
def asarray_or_pandas(a, copy=False, dtype=None, subok=False):
6061
if have_pandas:
@@ -68,10 +69,17 @@ def asarray_or_pandas(a, copy=False, dtype=None, subok=False):
6869
return a.__class__(a, copy=copy, dtype=dtype, **extra_args)
6970
return np.array(a, copy=copy, dtype=dtype, subok=subok)
7071

72+
7173
def test_asarray_or_pandas():
74+
import warnings
7275
assert type(asarray_or_pandas([1, 2, 3])) is np.ndarray
73-
assert type(asarray_or_pandas(np.matrix([[1, 2, 3]]))) is np.ndarray
74-
assert type(asarray_or_pandas(np.matrix([[1, 2, 3]]), subok=True)) is np.matrix
76+
with warnings.catch_warnings() as w:
77+
warnings.filterwarnings('ignore', 'the matrix subclass',
78+
PendingDeprecationWarning)
79+
assert type(asarray_or_pandas(np.matrix([[1, 2, 3]]))) is np.ndarray
80+
assert type(asarray_or_pandas(
81+
np.matrix([[1, 2, 3]]), subok=True)) is np.matrix
82+
assert w is None
7583
a = np.array([1, 2, 3])
7684
assert asarray_or_pandas(a) is a
7785
a_copy = asarray_or_pandas(a, copy=True)
@@ -147,7 +155,7 @@ def test_asarray_or_pandas():
147155
# instead of rows. It also converts ndarray subclasses into basic ndarrays,
148156
# which makes it easier to guarantee correctness. However, there are many
149157
# places in the code where we want to preserve pandas indexing information if
150-
# present, so there is also an option
158+
# present, so there is also an option
151159
def atleast_2d_column_default(a, preserve_pandas=False):
152160
if preserve_pandas and have_pandas:
153161
if isinstance(a, pandas.Series):
@@ -162,7 +170,9 @@ def atleast_2d_column_default(a, preserve_pandas=False):
162170
assert a.ndim >= 2
163171
return a
164172

173+
165174
def test_atleast_2d_column_default():
175+
import warnings
166176
assert np.all(atleast_2d_column_default([1, 2, 3]) == [[1], [2], [3]])
167177

168178
assert atleast_2d_column_default(1).shape == (1, 1)
@@ -173,7 +183,11 @@ def test_atleast_2d_column_default():
173183
assert atleast_2d_column_default([1, 2, 3]).shape == (3, 1)
174184
assert atleast_2d_column_default([[1], [2], [3]]).shape == (3, 1)
175185

176-
assert type(atleast_2d_column_default(np.matrix(1))) == np.ndarray
186+
with warnings.catch_warnings() as w:
187+
warnings.filterwarnings('ignore', 'the matrix subclass',
188+
PendingDeprecationWarning)
189+
assert type(atleast_2d_column_default(np.matrix(1))) == np.ndarray
190+
assert w is None
177191

178192
global have_pandas
179193
if have_pandas:
@@ -187,18 +201,21 @@ def test_atleast_2d_column_default():
187201
assert (type(atleast_2d_column_default(pandas.DataFrame([[1], [2]]),
188202
preserve_pandas=True))
189203
== pandas.DataFrame)
190-
s = pandas.Series([10, 11,12], name="hi", index=["a", "b", "c"])
204+
s = pandas.Series([10, 11, 12], name="hi", index=["a", "b", "c"])
191205
df = atleast_2d_column_default(s, preserve_pandas=True)
192206
assert isinstance(df, pandas.DataFrame)
193207
assert np.all(df.columns == ["hi"])
194208
assert np.all(df.index == ["a", "b", "c"])
195-
assert (type(atleast_2d_column_default(np.matrix(1),
196-
preserve_pandas=True))
197-
== np.ndarray)
198-
assert (type(atleast_2d_column_default([1, 2, 3],
199-
preserve_pandas=True))
209+
with warnings.catch_warnings() as w:
210+
warnings.filterwarnings('ignore', 'the matrix subclass',
211+
PendingDeprecationWarning)
212+
assert (type(atleast_2d_column_default(np.matrix(1),
213+
preserve_pandas=True))
214+
== np.ndarray)
215+
assert w is None
216+
assert (type(atleast_2d_column_default([1, 2, 3], preserve_pandas=True))
200217
== np.ndarray)
201-
218+
202219
if have_pandas:
203220
had_pandas = have_pandas
204221
try:
@@ -367,15 +384,15 @@ def test_PushbackAdapter():
367384
# The IPython pretty-printer gives very nice output that is difficult to get
368385
# otherwise, e.g., look how much more readable this is than if it were all
369386
# smooshed onto one line:
370-
#
387+
#
371388
# ModelDesc(input_code='y ~ x*asdf',
372389
# lhs_terms=[Term([EvalFactor('y')])],
373390
# rhs_terms=[Term([]),
374391
# Term([EvalFactor('x')]),
375392
# Term([EvalFactor('asdf')]),
376393
# Term([EvalFactor('x'), EvalFactor('asdf')])],
377394
# )
378-
#
395+
#
379396
# But, we don't want to assume it always exists; nor do we want to be
380397
# re-writing every repr function twice, once for regular repr and once for
381398
# the pretty printer. So, here's an ugly fallback implementation that can be
@@ -562,7 +579,7 @@ def test_safe_isnan():
562579
assert not safe_isnan(None)
563580
# raw isnan raises a *different* error for strings than for objects:
564581
assert not safe_isnan("asdf")
565-
582+
566583
def iterable(obj):
567584
try:
568585
iter(obj)

0 commit comments

Comments
 (0)