Skip to content

Commit 8b6c712

Browse files
committed
Delete code only needed for numpy < 1.4
1 parent 6ddfe4a commit 8b6c712

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

patsy/compat.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,6 @@
1212
# To force use of the compat code, set this env var to a non-empty value:
1313
optional_dep_ok = not os.environ.get("PATSY_AVOID_OPTIONAL_DEPENDENCIES")
1414

15-
# The *_indices functions were added in numpy 1.4
16-
import numpy as np
17-
if optional_dep_ok and hasattr(np, "triu_indices"):
18-
from numpy import triu_indices
19-
from numpy import tril_indices
20-
from numpy import diag_indices
21-
else:
22-
def triu_indices(n):
23-
return np.triu(np.ones((n, n))).nonzero()
24-
def tril_indices(n):
25-
return np.tril(np.ones((n, n))).nonzero()
26-
def diag_indices(n):
27-
return (np.arange(n), np.arange(n))
28-
2915
##### Python standard library
3016

3117
# The Python license requires that all derivative works contain a "brief

patsy/contrasts.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import six
1515
import numpy as np
1616
from patsy import PatsyError
17-
from patsy.compat import triu_indices, tril_indices, diag_indices
1817
from patsy.util import (repr_pretty_delegate, repr_pretty_impl,
1918
safe_issubdtype,
2019
no_pickling, assert_no_pickling)
@@ -479,8 +478,8 @@ def _helmert_contrast(self, levels):
479478

480479
#r-like
481480
contr = np.zeros((n, n - 1))
482-
contr[1:][diag_indices(n - 1)] = np.arange(1, n)
483-
contr[triu_indices(n - 1)] = -1
481+
contr[1:][np.diag_indices(n - 1)] = np.arange(1, n)
482+
contr[np.triu_indices(n - 1)] = -1
484483
return contr
485484

486485
def code_with_intercept(self, levels):
@@ -539,14 +538,14 @@ def _diff_contrast(self, levels):
539538
contr = np.zeros((nlevels, nlevels-1))
540539
int_range = np.arange(1, nlevels)
541540
upper_int = np.repeat(int_range, int_range)
542-
row_i, col_i = triu_indices(nlevels-1)
541+
row_i, col_i = np.triu_indices(nlevels-1)
543542
# we want to iterate down the columns not across the rows
544543
# it would be nice if the index functions had a row/col order arg
545544
col_order = np.argsort(col_i)
546545
contr[row_i[col_order],
547546
col_i[col_order]] = (upper_int-nlevels)/float(nlevels)
548547
lower_int = np.repeat(int_range, int_range[::-1])
549-
row_i, col_i = tril_indices(nlevels-1)
548+
row_i, col_i = np.tril_indices(nlevels-1)
550549
# we want to iterate down the columns not across the rows
551550
col_order = np.argsort(col_i)
552551
contr[row_i[col_order]+1, col_i[col_order]] = lower_int/float(nlevels)

setup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
license="2-clause BSD",
2222
packages=["patsy"],
2323
url="https://github.com/pydata/patsy",
24-
install_requires=["six", "numpy"],
24+
install_requires=[
25+
"six",
26+
# Possibly we need an even newer numpy than this, but we definitely
27+
# need at least 1.4 for triu_indices
28+
"numpy >= 1.4",
29+
],
2530
classifiers =
2631
[ "Development Status :: 4 - Beta",
2732
"Intended Audience :: Developers",

0 commit comments

Comments
 (0)