Skip to content

Commit 6ddfe4a

Browse files
committed
Delete code only needed on python 2.5 and earlier
1 parent dd6b3ba commit 6ddfe4a

File tree

3 files changed

+3
-70
lines changed

3 files changed

+3
-70
lines changed

patsy/compat.py

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -34,73 +34,6 @@ def diag_indices(n):
3434
# add here explaining their provenance, any changes made, and what versions of
3535
# Python require them:
3636

37-
# Copied unchanged from Python 2.7.3's re.py module; all I did was add the
38-
# import statements at the top.
39-
# This code seems to be included in Python 2.5+.
40-
import re
41-
if optional_dep_ok and hasattr(re, "Scanner"):
42-
Scanner = re.Scanner
43-
else:
44-
import sre_parse
45-
import sre_compile
46-
class Scanner:
47-
def __init__(self, lexicon, flags=0):
48-
from sre_constants import BRANCH, SUBPATTERN
49-
self.lexicon = lexicon
50-
# combine phrases into a compound pattern
51-
p = []
52-
s = sre_parse.Pattern()
53-
s.flags = flags
54-
for phrase, action in lexicon:
55-
p.append(sre_parse.SubPattern(s, [
56-
(SUBPATTERN, (len(p)+1, sre_parse.parse(phrase, flags))),
57-
]))
58-
s.groups = len(p)+1
59-
p = sre_parse.SubPattern(s, [(BRANCH, (None, p))])
60-
self.scanner = sre_compile.compile(p)
61-
def scan(self, string):
62-
result = []
63-
append = result.append
64-
match = self.scanner.scanner(string).match
65-
i = 0
66-
while 1:
67-
m = match()
68-
if not m:
69-
break
70-
j = m.end()
71-
if i == j:
72-
break
73-
action = self.lexicon[m.lastindex-1][1]
74-
if hasattr(action, '__call__'):
75-
self.match = m
76-
action = action(self, m.group())
77-
if action is not None:
78-
append(action)
79-
i = j
80-
return result, string[i:]
81-
82-
# functools available in Python 2.5+
83-
# This is just a cosmetic thing, so don't bother emulating it if we don't
84-
# have it.
85-
def compat_wraps(f1):
86-
def do_wrap(f2):
87-
return f2
88-
return do_wrap
89-
if optional_dep_ok:
90-
try:
91-
from functools import wraps
92-
except ImportError:
93-
wraps = compat_wraps
94-
else:
95-
wraps = compat_wraps
96-
97-
# collections.Mapping available in Python 2.6+
98-
import collections
99-
if optional_dep_ok and hasattr(collections, "Mapping"):
100-
Mapping = collections.Mapping
101-
else:
102-
Mapping = dict
103-
10437
# OrderedDict is only available in Python 2.7+. compat_ordereddict.py has
10538
# comments at the top.
10639
import collections

patsy/constraint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
__all__ = ["LinearConstraint"]
1111

1212
import re
13+
from collections import Mapping
1314
import six
1415
import numpy as np
1516
from patsy import PatsyError
@@ -19,7 +20,6 @@
1920
SortAnythingKey,
2021
no_pickling, assert_no_pickling)
2122
from patsy.infix_parser import Token, Operator, ParseNode, infix_parse
22-
from patsy.compat import Scanner, Mapping
2323

2424
class LinearConstraint(object):
2525
"""A linear constraint in matrix form.
@@ -176,7 +176,7 @@ def _tokenize_constraint(string, variable_names):
176176
(whitespace_re, None),
177177
]
178178

179-
scanner = Scanner(lexicon)
179+
scanner = re.Scanner(lexicon)
180180
tokens, leftover = scanner.scan(string)
181181
if leftover:
182182
offset = len(string) - len(leftover)

patsy/state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
# because right now I'm not sure how to tell whether we are being called for
2525
# fitting versus being called for prediction.
2626

27+
from functools import wraps
2728
import numpy as np
2829
from patsy.util import (atleast_2d_column_default,
2930
asarray_or_pandas, pandas_friendly_reshape,
3031
wide_dtype_for, safe_issubdtype,
3132
no_pickling, assert_no_pickling)
32-
from patsy.compat import wraps
3333

3434
# These are made available in the patsy.* namespace
3535
__all__ = ["stateful_transform",

0 commit comments

Comments
 (0)