Skip to content

Commit d5e0a68

Browse files
authored
Merge pull request #3317 from ColCarroll/remove_py_2
Remove Python 2.7 support
2 parents fcfc1b5 + 376b87a commit d5e0a68

File tree

96 files changed

+453
-609
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+453
-609
lines changed

.travis.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ sudo: required
44
cache:
55
directories:
66
- $HOME/.theano
7-
- $HOME/miniconda2
87
- $HOME/miniconda3
98

109
addons:
@@ -22,17 +21,14 @@ install:
2221
- pip install coveralls travis-sphinx==2.0.0
2322

2423
env:
25-
- PYTHON_VERSION=2.7 FLOATX='float32' TESTCMD="--durations=10 --ignore=pymc3/tests/test_examples.py --cov-append --ignore=pymc3/tests/test_distributions_random.py --ignore=pymc3/tests/test_variational_inference.py --ignore=pymc3/tests/test_shared.py --ignore=pymc3/tests/test_smc.py --ignore=pymc3/tests/test_updates.py --ignore=pymc3/tests/test_posteriors.py --ignore=pymc3/tests/test_sampling.py"
26-
- PYTHON_VERSION=2.7 FLOATX='float32' RUN_PYLINT="true" TESTCMD="--durations=10 --cov-append pymc3/tests/test_distributions_random.py pymc3/tests/test_shared.py pymc3/tests/test_smc.py pymc3/tests/test_sampling.py"
27-
- PYTHON_VERSION=2.7 FLOATX='float32' TESTCMD="--durations=10 --cov-append pymc3/tests/test_examples.py pymc3/tests/test_posteriors.py"
28-
- PYTHON_VERSION=2.7 FLOATX='float32' TESTCMD="--durations=10 --cov-append pymc3/tests/test_variational_inference.py pymc3/tests/test_updates.py"
29-
- PYTHON_VERSION=2.7 FLOATX='float64' TESTCMD="--durations=10 --ignore=pymc3/tests/test_examples.py --cov-append --ignore=pymc3/tests/test_distributions_random.py --ignore=pymc3/tests/test_variational_inference.py --ignore=pymc3/tests/test_shared.py --ignore=pymc3/tests/test_smc.py --ignore=pymc3/tests/test_updates.py --ignore=pymc3/tests/test_posteriors.py --ignore=pymc3/tests/test_sampling.py"
30-
- PYTHON_VERSION=2.7 FLOATX='float64' RUN_PYLINT="true" TESTCMD="--durations=10 --cov-append pymc3/tests/test_distributions_random.py pymc3/tests/test_shared.py pymc3/tests/test_smc.py pymc3/tests/test_sampling.py"
31-
- PYTHON_VERSION=2.7 FLOATX='float64' TESTCMD="--durations=10 --cov-append pymc3/tests/test_examples.py pymc3/tests/test_posteriors.py"
32-
- PYTHON_VERSION=3.6 FLOATX='float64' TESTCMD="--durations=10 --cov-append --ignore=pymc3/tests/test_examples.py --ignore=pymc3/tests/test_distributions_random.py --ignore=pymc3/tests/test_variational_inference.py --ignore=pymc3/tests/test_shared.py --ignore=pymc3/tests/test_smc.py --ignore=pymc3/tests/test_updates.py --ignore=pymc3/tests/test_posteriors.py --ignore=pymc3/tests/test_sampling.py"
33-
- PYTHON_VERSION=3.6 FLOATX='float64' TESTCMD="--durations=10 --cov-append pymc3/tests/test_distributions_random.py pymc3/tests/test_shared.py pymc3/tests/test_smc.py pymc3/tests/test_sampling.py"
34-
- PYTHON_VERSION=3.6 FLOATX='float64' BUILD_DOCS="true" TESTCMD="--durations=10 --cov-append pymc3/tests/test_examples.py pymc3/tests/test_posteriors.py"
35-
- PYTHON_VERSION=3.6 FLOATX='float64' TESTCMD="--durations=10 --cov-append pymc3/tests/test_variational_inference.py pymc3/tests/test_updates.py"
24+
- FLOATX='float32' TESTCMD="--durations=10 --ignore=pymc3/tests/test_examples.py --cov-append --ignore=pymc3/tests/test_distributions_random.py --ignore=pymc3/tests/test_variational_inference.py --ignore=pymc3/tests/test_shared.py --ignore=pymc3/tests/test_smc.py --ignore=pymc3/tests/test_updates.py --ignore=pymc3/tests/test_posteriors.py --ignore=pymc3/tests/test_sampling.py"
25+
- FLOATX='float32' RUN_PYLINT="true" TESTCMD="--durations=10 --cov-append pymc3/tests/test_distributions_random.py pymc3/tests/test_shared.py pymc3/tests/test_smc.py pymc3/tests/test_sampling.py"
26+
- FLOATX='float32' TESTCMD="--durations=10 --cov-append pymc3/tests/test_examples.py pymc3/tests/test_posteriors.py"
27+
- FLOATX='float32' TESTCMD="--durations=10 --cov-append pymc3/tests/test_variational_inference.py pymc3/tests/test_updates.py"
28+
- FLOATX='float64' TESTCMD="--durations=10 --cov-append --ignore=pymc3/tests/test_examples.py --ignore=pymc3/tests/test_distributions_random.py --ignore=pymc3/tests/test_variational_inference.py --ignore=pymc3/tests/test_shared.py --ignore=pymc3/tests/test_smc.py --ignore=pymc3/tests/test_updates.py --ignore=pymc3/tests/test_posteriors.py --ignore=pymc3/tests/test_sampling.py"
29+
- FLOATX='float64' TESTCMD="--durations=10 --cov-append pymc3/tests/test_distributions_random.py pymc3/tests/test_shared.py pymc3/tests/test_smc.py pymc3/tests/test_sampling.py"
30+
- FLOATX='float64' BUILD_DOCS="true" TESTCMD="--durations=10 --cov-append pymc3/tests/test_examples.py pymc3/tests/test_posteriors.py"
31+
- FLOATX='float64' TESTCMD="--durations=10 --cov-append pymc3/tests/test_variational_inference.py pymc3/tests/test_updates.py"
3632

3733
script:
3834
- . ./scripts/test.sh $TESTCMD

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ Another option is to clone the repository and install PyMC3 using
104104
Dependencies
105105
============
106106

107-
PyMC3 is tested on Python 2.7 and 3.6 and depends on Theano, NumPy,
108-
SciPy, Pandas, and Matplotlib (see ``requirements.txt`` for version
107+
PyMC3 is tested on Python 3.6 and depends on Theano, NumPy,
108+
SciPy, and Pandas (see ``requirements.txt`` for version
109109
information).
110110

111111
Optional

benchmarks/benchmarks/benchmarks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def mixture_model(random_seed=1234):
5858
return model, start
5959

6060

61-
class OverheadSuite(object):
61+
class OverheadSuite:
6262
"""
6363
Just tests how long sampling from a normal distribution takes for various
6464
samplers
@@ -77,7 +77,7 @@ def time_overhead_sample(self, step):
7777
progressbar=False, compute_convergence_checks=False)
7878

7979

80-
class ExampleSuite(object):
80+
class ExampleSuite:
8181
"""Implements examples to keep up with benchmarking them."""
8282
timeout = 360.0 # give it a few minutes
8383
timer = timeit.default_timer
@@ -128,7 +128,7 @@ def time_glm_hierarchical(self):
128128
progressbar=False, compute_convergence_checks=False)
129129

130130

131-
class NUTSInitSuite(object):
131+
class NUTSInitSuite:
132132
"""Tests initializations for NUTS sampler on models
133133
"""
134134
timeout = 360.0
@@ -173,7 +173,7 @@ def track_marginal_mixture_model_ess(self, init):
173173
NUTSInitSuite.track_marginal_mixture_model_ess.unit = 'Effective samples per second'
174174

175175

176-
class CompareMetropolisNUTSSuite(object):
176+
class CompareMetropolisNUTSSuite:
177177
timeout = 360.0
178178
# None will be the "sensible default", and include initialization, but should be fastest
179179
params = (None, pm.NUTS, pm.Metropolis)

docs/source/developer_guide.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ A few important points to highlight in the Distribution Class:
2525

2626
.. code:: python
2727
28-
class Distribution(object):
28+
class Distribution:
2929
"""Statistical distribution"""
3030
def __new__(cls, name, *args, **kwargs):
3131
...
@@ -610,7 +610,7 @@ does not edit or rewrite the graph directly.
610610
611611
.. code:: python
612612
613-
class ValueGradFunction(object):
613+
class ValueGradFunction:
614614
"""Create a theano function that computes a value and its gradient.
615615
...
616616
"""
@@ -1104,4 +1104,4 @@ While having the samplers be written in Python allows for a lot of
11041104
flexibility and intuitive for experiment (writing e.g. NUTS in Theano is
11051105
also very difficult), it comes at a performance penalty and makes
11061106
sampling on the GPU very inefficient because memory needs to be copied
1107-
for every logp evaluation.
1107+
for every logp evaluation.

docs/source/sphinxext/gallery_generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def create_thumbnail(infile, width=275, height=275, cx=0.5, cy=0.5, border=4):
6363
return fig
6464

6565

66-
class NotebookGenerator(object):
66+
class NotebookGenerator:
6767
"""Tools for generating an example page from a file"""
6868

6969
def __init__(self, filename, target_dir):
@@ -121,7 +121,7 @@ def gen_previews(self):
121121
create_thumbnail(self.png_path)
122122

123123

124-
class TableOfContentsJS(object):
124+
class TableOfContentsJS:
125125
"""Container to load table of contents JS file"""
126126

127127
def load(self, path):

pymc3/backends/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class BackendError(Exception):
2020
pass
2121

2222

23-
class BaseTrace(object):
23+
class BaseTrace:
2424
"""Base trace object
2525
2626
Parameters
@@ -218,7 +218,7 @@ def stat_names(self):
218218
return set()
219219

220220

221-
class MultiTrace(object):
221+
class MultiTrace:
222222
"""Main interface for accessing values from MCMC results
223223
224224
The core method to select values is `get_values`. The method

pymc3/backends/hdf5.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(self, name=None, model=None, vars=None, test_point=None):
3737
self.hdf5_file = None
3838
self.draw_idx = 0
3939
self.draws = None
40-
super(HDF5, self).__init__(name, model, vars, test_point)
40+
super().__init__(name, model, vars, test_point)
4141

4242
def _get_sampler_stats(self, varname, sampler_idx, burn, thin):
4343
with self.activate_file:

pymc3/backends/ndarray.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def load_trace(directory, model=None):
7878
return base.MultiTrace(straces)
7979

8080

81-
class SerializeNDArray(object):
81+
class SerializeNDArray:
8282
metadata_file = 'metadata.json'
8383
samples_file = 'samples.npz'
8484

@@ -157,7 +157,7 @@ class NDArray(base.BaseTrace):
157157
supports_sampler_stats = True
158158

159159
def __init__(self, name=None, model=None, vars=None, test_point=None):
160-
super(NDArray, self).__init__(name, model, vars, test_point)
160+
super().__init__(name, model, vars, test_point)
161161
self.draw_idx = 0
162162
self.draws = None
163163
self.samples = {}
@@ -178,7 +178,7 @@ def setup(self, draws, chain, sampler_vars=None):
178178
Names and dtypes of the variables that are
179179
exported by the samplers.
180180
"""
181-
super(NDArray, self).setup(draws, chain, sampler_vars)
181+
super().setup(draws, chain, sampler_vars)
182182

183183
self.chain = chain
184184
if self.samples: # Concatenate new array if chain is already present.

pymc3/backends/report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class WarningType(enum.Enum):
3636
}
3737

3838

39-
class SamplerReport(object):
39+
class SamplerReport:
4040
def __init__(self):
4141
self._chain_warnings = {}
4242
self._global_warnings = []

pymc3/backends/sqlite.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class SQLite(base.BaseTrace):
7575
"""
7676

7777
def __init__(self, name, model=None, vars=None, test_point=None):
78-
super(SQLite, self).__init__(name, model, vars, test_point)
78+
super().__init__(name, model, vars, test_point)
7979
self._var_cols = {}
8080
self.var_inserts = {} # varname -> insert statement
8181
self.draw_idx = 0
@@ -270,7 +270,7 @@ def point(self, idx):
270270
return var_values
271271

272272

273-
class _SQLiteDB(object):
273+
class _SQLiteDB:
274274

275275
def __init__(self, name):
276276
self.name = name
@@ -347,8 +347,7 @@ def _get_var_strs(cursor, varname):
347347
def _get_chain_list(cursor, varname):
348348
"""Return a list of sorted chains for `varname`."""
349349
cursor.execute('SELECT DISTINCT chain FROM [{}]'.format(varname))
350-
chains = [chain[0] for chain in cursor.fetchall()]
351-
chains.sort()
350+
chains = sorted([chain[0] for chain in cursor.fetchall()])
352351
return chains
353352

354353

pymc3/backends/text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Text(base.BaseTrace):
4343
def __init__(self, name, model=None, vars=None, test_point=None):
4444
if not os.path.exists(name):
4545
os.mkdir(name)
46-
super(Text, self).__init__(name, model, vars, test_point)
46+
super().__init__(name, model, vars, test_point)
4747

4848
self.flat_names = {v: ttab.create_flat_names(v, shape)
4949
for v, shape in self.var_shapes.items()}

pymc3/blocking.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# TODO Classes and methods need to be fully documented.
1717

1818

19-
class ArrayOrdering(object):
19+
class ArrayOrdering:
2020
"""
2121
An ordering for an array space
2222
"""
@@ -45,7 +45,7 @@ def __getitem__(self, key):
4545
return self.by_name[key]
4646

4747

48-
class DictToArrayBijection(object):
48+
class DictToArrayBijection:
4949
"""
5050
A mapping between a dict space and an array space
5151
"""
@@ -106,7 +106,7 @@ def mapf(self, f):
106106
return Compose(f, self.rmap)
107107

108108

109-
class ListArrayOrdering(object):
109+
class ListArrayOrdering:
110110
"""
111111
An ordering for a list to an array space. Takes also non theano.tensors.
112112
Modified from pymc3 blocking.
@@ -138,7 +138,7 @@ def __init__(self, list_arrays, intype='numpy'):
138138
self.size += array.size
139139

140140

141-
class ListToArrayBijection(object):
141+
class ListToArrayBijection:
142142
"""
143143
A mapping between a List of arrays and an array space
144144
@@ -217,7 +217,7 @@ def rmap(self, array):
217217
return a_list
218218

219219

220-
class DictToVarBijection(object):
220+
class DictToVarBijection:
221221
"""
222222
A mapping between a dict space and the array space for one element within the dict space
223223
"""
@@ -244,7 +244,7 @@ def mapf(self, f):
244244
return Compose(f, self.rmap)
245245

246246

247-
class Compose(object):
247+
class Compose:
248248
"""
249249
Compose two functions in a pickleable way
250250
"""

pymc3/data.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def get_data(filename):
3333

3434
class GenTensorVariable(tt.TensorVariable):
3535
def __init__(self, op, type, name=None):
36-
super(GenTensorVariable, self).__init__(type=type, name=name)
36+
super().__init__(type=type, name=name)
3737
self.op = op
3838

3939
def set_gen(self, gen):
@@ -48,7 +48,7 @@ def clone(self):
4848
return cp
4949

5050

51-
class GeneratorAdapter(object):
51+
class GeneratorAdapter:
5252
"""
5353
Helper class that helps to infer data type of generator with looking
5454
at the first item, preserving the order of the resulting generator
@@ -99,7 +99,7 @@ class Minibatch(tt.TensorVariable):
9999
data : :class:`ndarray`
100100
initial data
101101
batch_size : `int` or `List[int|tuple(size, random_seed)]`
102-
batch size for inference, random seed is needed
102+
batch size for inference, random seed is needed
103103
for child random generators
104104
dtype : `str`
105105
cast data to specific type
@@ -110,10 +110,10 @@ class Minibatch(tt.TensorVariable):
110110
random_seed : `int`
111111
random seed that is used by default
112112
update_shared_f : `callable`
113-
returns :class:`ndarray` that will be carefully
113+
returns :class:`ndarray` that will be carefully
114114
stored to underlying shared variable
115-
you can use it to change source of
116-
minibatches programmatically
115+
you can use it to change source of
116+
minibatches programmatically
117117
in_memory_size : `int` or `List[int|slice|Ellipsis]`
118118
data size for storing in theano.shared
119119
@@ -141,7 +141,7 @@ class Minibatch(tt.TensorVariable):
141141
>>> x = Minibatch(data, batch_size=10)
142142
143143
Note, that your data is cast to `floatX` if it is not integer type
144-
But you still can add `dtype` kwarg for :class:`Minibatch`
144+
But you still can add `dtype` kwarg for :class:`Minibatch`
145145
146146
in case we want 10 sampled rows and columns
147147
`[(size, seed), (size, seed)]` it is
@@ -182,7 +182,7 @@ class Minibatch(tt.TensorVariable):
182182
>>> x.update_shared()
183183
184184
To be more concrete about how we get minibatch, here is a demo
185-
1) create shared variable
185+
1) create shared variable
186186
>>> shared = theano.shared(data)
187187
188188
2) create random slice of size 10
@@ -191,7 +191,7 @@ class Minibatch(tt.TensorVariable):
191191
3) take that slice
192192
>>> minibatch = shared[ridx]
193193
194-
That's done. Next you can use this minibatch somewhere else.
194+
That's done. Next you can use this minibatch somewhere else.
195195
You can see that implementation does not require fixed shape
196196
for shared variable. Feel free to use that if needed.
197197
@@ -222,7 +222,7 @@ class Minibatch(tt.TensorVariable):
222222
We take slice only for the first and last dimension
223223
>>> assert x.eval().shape == (2, 20, 30, 40, 10)
224224
225-
2) Skipping particular dimension, `total_size = (10, None, 30)`
225+
2) Skipping particular dimension, `total_size = (10, None, 30)`
226226
>>> x = Minibatch(moredata, [2, None, 20])
227227
>>> assert x.eval().shape == (2, 20, 20, 40, 50)
228228
@@ -249,8 +249,7 @@ def __init__(self, data, batch_size=128, dtype=None, broadcastable=None, name='M
249249
broadcastable = (False, ) * minibatch.ndim
250250
minibatch = tt.patternbroadcast(minibatch, broadcastable)
251251
self.minibatch = minibatch
252-
super(Minibatch, self).__init__(
253-
self.minibatch.type, None, None, name=name)
252+
super().__init__(self.minibatch.type, None, None, name=name)
254253
theano.Apply(
255254
theano.compile.view_op,
256255
inputs=[self.minibatch], outputs=[self])

pymc3/diagnostics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def generate_neff(trace_values):
292292
'of the same length.')
293293

294294
if varnames is None:
295-
varnames = get_default_varnames(mtrace.varnames,include_transformed=include_transformed)
295+
varnames = get_default_varnames(mtrace.varnames, include_transformed=include_transformed)
296296

297297
n_eff = {}
298298

0 commit comments

Comments
 (0)