Skip to content

Commit b9e65d6

Browse files
authored
remove Python2 support (pydata#209)
1 parent 8546450 commit b9e65d6

25 files changed

+111
-282
lines changed

.github/workflows/tox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
max-parallel: 4
1616
matrix:
17-
python-version: ['2.7', '3.6', '3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
17+
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
1818
pandas-presence: ['with_pandas', 'without_pandas']
1919
env:
2020
PYTHON_VERSION: ${{ matrix.python-version }}

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ building design matrices. Patsy brings the convenience of [R](http://www.r-proje
3232

3333
## Dependencies
3434

35-
* Python (2.6, 2.7, or 3.3+)
36-
* six
35+
* Python (3.3+)
3736
* numpy
3837
* Optional:
3938
* pytest/pytest-cov: needed to run tests

doc/conf.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
# -*- coding: utf-8 -*-
22

33
# General information about the project.
4-
project = u'patsy'
5-
copyright = u'2011-2015, Nathaniel J. Smith'
4+
project = 'patsy'
5+
copyright = '2011-2015, Nathaniel J. Smith'
66

77
import sys
8-
print "python exec:", sys.executable
9-
print "sys.path:", sys.path
8+
print("python exec:", sys.executable)
9+
print("sys.path:", sys.path)
1010
try:
1111
import numpy
12-
print "numpy: %s, %s" % (numpy.__version__, numpy.__file__)
12+
print("numpy: %s, %s" % (numpy.__version__, numpy.__file__))
1313
except ImportError:
14-
print "no numpy"
14+
print("no numpy")
1515
try:
1616
import matplotlib
17-
print "matplotlib: %s, %s" % (matplotlib.__version__, matplotlib.__file__)
17+
print("matplotlib: %s, %s" % (matplotlib.__version__, matplotlib.__file__))
1818
except ImportError:
19-
print "no matplotlib"
19+
print("no matplotlib")
2020
try:
2121
import IPython
22-
print "ipython: %s, %s" % (IPython.__version__, IPython.__file__)
22+
print("ipython: %s, %s" % (IPython.__version__, IPython.__file__))
2323
except ImportError:
24-
print "no ipython"
24+
print("no ipython")
2525

2626
# The version info for the project you're documenting, acts as replacement for
2727
# |version| and |release|, also used in various other places throughout the

doc/overview.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ Requirements
8282

8383
Installing :mod:`patsy` requires:
8484

85-
* `Python <http://python.org/>`_ (version 2.6, 2.7, or 3.3+)
86-
* `Six <https://pypi.python.org/pypi/six>`_
85+
* `Python <http://python.org/>`_ (version 3.3+)
8786
* `NumPy <http://numpy.scipy.org/>`_
8887

8988
Installation

doc/py2-versus-py3.rst

Lines changed: 0 additions & 35 deletions
This file was deleted.

patsy/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
design matrices. It is closely inspired by the 'formula' mini-language used in
77
R and S."""
88

9-
import sys
10-
119
from patsy.version import __version__
1210

1311
# Do this first, to make it easy to check for warnings while testing:

patsy/build.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
__all__ = ["design_matrix_builders", "build_design_matrices"]
99

1010
import itertools
11-
import six
1211

1312
import numpy as np
1413
from patsy import PatsyError
@@ -357,7 +356,7 @@ def _factors_memorize(factors, data_iter_maker, eval_env):
357356
# Now, cycle through the data until all the factors have finished
358357
# memorizing everything:
359358
memorize_needed = set()
360-
for factor, passes in six.iteritems(passes_needed):
359+
for factor, passes in passes_needed.items():
361360
if passes > 0:
362361
memorize_needed.add(factor)
363362
which_pass = 0
@@ -459,7 +458,7 @@ def _examine_factor_types(factors, factor_states, data_iter_maker, NA_action):
459458
break
460459
# Pull out the levels
461460
cat_levels_contrasts = {}
462-
for factor, sniffer in six.iteritems(cat_sniffers):
461+
for factor, sniffer in cat_sniffers.items():
463462
cat_levels_contrasts[factor] = sniffer.levels_contrast()
464463
return (num_column_counts, cat_levels_contrasts)
465464

@@ -726,7 +725,7 @@ def design_matrix_builders(termlists, data_iter_maker, eval_env,
726725
for factor in term.factors:
727726
this_design_factor_infos[factor] = factor_infos[factor]
728727
column_names = []
729-
for subterms in six.itervalues(term_to_subterm_infos):
728+
for subterms in term_to_subterm_infos.values():
730729
for subterm in subterms:
731730
for column_name in _subterm_column_names_iter(
732731
factor_infos, subterm):
@@ -740,7 +739,7 @@ def _build_design_matrix(design_info, factor_info_to_values, dtype):
740739
factor_to_values = {}
741740
need_reshape = False
742741
num_rows = None
743-
for factor_info, value in six.iteritems(factor_info_to_values):
742+
for factor_info, value in factor_info_to_values.items():
744743
# It's possible that the same factor appears in multiple different
745744
# FactorInfo objects (e.g. if someone is simultaneously building two
746745
# DesignInfo objects that started out as part of different
@@ -761,7 +760,7 @@ def _build_design_matrix(design_info, factor_info_to_values, dtype):
761760
shape = (num_rows, len(design_info.column_names))
762761
m = DesignMatrix(np.empty(shape, dtype=dtype), design_info)
763762
start_column = 0
764-
for term, subterms in six.iteritems(design_info.term_codings):
763+
for term, subterms in design_info.term_codings.items():
765764
for subterm in subterms:
766765
end_column = start_column + subterm.num_columns
767766
m_slice = m[:, start_column:end_column]
@@ -883,7 +882,7 @@ def build_design_matrices(design_infos, data,
883882
# We look at evaluators rather than factors here, because it might
884883
# happen that we have the same factor twice, but with different
885884
# memorized state.
886-
for factor_info in six.itervalues(design_info.factor_infos):
885+
for factor_info in design_info.factor_infos.values():
887886
if factor_info not in factor_info_to_values:
888887
value, is_NA = _eval_factor(factor_info, data, NA_action)
889888
factor_info_to_isNAs[factor_info] = is_NA

patsy/categorical.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
# handle the different stages of categorical data munging.
3535

3636
import numpy as np
37-
import six
37+
3838
from patsy import PatsyError
3939
from patsy.util import (SortAnythingKey,
4040
safe_scalar_isnan,
@@ -158,7 +158,7 @@ def _categorical_shape_fix(data):
158158
# coerce scalars into 1d, which is consistent with what we do for numeric
159159
# factors. (See statsmodels/statsmodels#1881)
160160
if (not iterable(data)
161-
or isinstance(data, (six.text_type, six.binary_type))):
161+
or isinstance(data, (str, bytes))):
162162
data = [data]
163163
return data
164164

patsy/compat.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,12 @@
3131
# 'raise from' available in Python 3+
3232
import sys
3333
from patsy import PatsyError
34+
3435
def call_and_wrap_exc(msg, origin, f, *args, **kwargs):
3536
try:
3637
return f(*args, **kwargs)
3738
except Exception as e:
38-
if sys.version_info[0] >= 3:
39-
new_exc = PatsyError("%s: %s: %s"
40-
% (msg, e.__class__.__name__, e),
41-
origin)
42-
# Use 'exec' to hide this syntax from the Python 2 parser:
43-
exec("raise new_exc from e")
44-
else:
45-
# In python 2, we just let the original exception escape -- better
46-
# than destroying the traceback. But if it's a PatsyError, we can
47-
# at least set the origin properly.
48-
if isinstance(e, PatsyError):
49-
e.set_origin(origin)
50-
raise
39+
new_exc = PatsyError("%s: %s: %s"
40+
% (msg, e.__class__.__name__, e),
41+
origin)
42+
raise new_exc from e

patsy/constraint.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
# Interpreting linear constraints like "2*x1 + x2 = 0"
66

7-
from __future__ import print_function
8-
97
# These are made available in the patsy.* namespace
108
__all__ = ["LinearConstraint"]
119

@@ -14,7 +12,6 @@
1412
from collections.abc import Mapping
1513
except ImportError:
1614
from collections import Mapping
17-
import six
1815
import numpy as np
1916
from patsy import PatsyError
2017
from patsy.origin import Origin
@@ -376,10 +373,10 @@ def linear_constraint(constraint_like, variable_names):
376373
dtype=float)
377374
constants = np.zeros(len(constraint_like))
378375
used = set()
379-
for i, (name, value) in enumerate(six.iteritems(constraint_like)):
376+
for i, (name, value) in enumerate(constraint_like.items()):
380377
if name in variable_names:
381378
idx = variable_names.index(name)
382-
elif isinstance(name, six.integer_types):
379+
elif isinstance(name, int):
383380
idx = name
384381
else:
385382
raise ValueError("unrecognized variable name/index %r"

0 commit comments

Comments
 (0)