Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit ea643ca

Browse files
authored
Merge pull request #381 from ariddell/feature/issue-327
Add DeprecationWarning for pystan.stan
2 parents 3be386e + 96f69dc commit ea643ca

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

doc/avoiding_recompilation.rst

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ whenever possible. If the same model is going to be used repeatedly, we would
1111
like to compile it just once. The following demonstrates how to reuse a model in
1212
different scripts and between interactive Python sessions.
1313

14-
**Within sessions** you can avoid recompiling a model in two ways. The first
15-
method is to reuse a fit object in the call to ``stan``. For example,
14+
**Within sessions** you can avoid recompiling a model by reusing the `StanModel` instance:
1615

1716
.. code-block:: python
1817
@@ -34,32 +33,17 @@ method is to reuse a fit object in the call to ``stan``. For example,
3433
}
3534
"""
3635
37-
data = dict(N=10, y=[0, 1, 0, 1, 0, 1, 0, 1, 1, 1])
38-
39-
.. code-block:: python
40-
41-
fit = stan(model_code=model_code, data=data)
42-
print(fit)
43-
44-
new_data = dict(N=6, y=[0, 0, 0, 0, 0, 1])
45-
fit2 = stan(fit=fit, data=new_data)
46-
print(fit2)
47-
48-
However, calling ``pystan.stan`` is deprecated and will soon be removed from
49-
PyStan. The recommended method is to compile the model once using the
50-
``StanModel`` class and then sample from the model using the ``sampling``
51-
method.
5236
5337
.. code-block:: python
5438
5539
from pystan import StanModel
5640
57-
# using the same model as before
5841
data = dict(N=10, y=[0, 1, 0, 1, 0, 1, 0, 1, 1, 1])
5942
sm = StanModel(model_code=model_code)
6043
fit = sm.sampling(data=data)
6144
print(fit)
6245
46+
# reuse model with new data
6347
new_data = dict(N=6, y=[0, 0, 0, 0, 0, 1])
6448
fit2 = sm.sampling(data=new_data)
6549
print(fit2)
@@ -107,7 +91,7 @@ Automatically reusing models
10791

10892
For those who miss using variables across sessions in R, it is not difficult to
10993
write a function that automatically saves a copy of every model that gets
110-
compiled using ``stan`` and opportunistically loads a copy of a model if one is
94+
compiled and opportunistically loads a copy of a model if one is
11195
available.
11296

11397
.. code-block:: python

doc/whats_new.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
v2.17.0.0 (TBD)
1010
===============
1111
- ...
12+
- Marked ``pystan.stan`` as deprecated. It will be removed in version 3.0. Please compile and use a
13+
Stan program as two separate steps.
1214

1315
v2.16.0.0 (22. June 2017)
1416
========================

pystan/api.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
# License. See LICENSE for a text of the license.
66
#-----------------------------------------------------------------------------
77

8+
import hashlib
89
import io
910
import logging
10-
import hashlib
11+
import warnings
1112

1213
import pystan._api # stanc wrapper
1314
from pystan._compat import string_types, PY2
@@ -146,6 +147,10 @@ def stan(file=None, model_name="anon_model", model_code=None, fit=None,
146147
eigen_lib=None, n_jobs=-1, **kwargs):
147148
"""Fit a model using Stan.
148149
150+
The `pystan.stan` function was deprecated in version 2.17 and will be
151+
removed in version 3.0. Compiling and using a Stan Program (e.g., for
152+
drawing samples) should be done in separate steps.
153+
149154
Parameters
150155
----------
151156
@@ -368,6 +373,8 @@ def stan(file=None, model_name="anon_model", model_code=None, fit=None,
368373
... return dict(mu=1, sigma=4, z=np.random.normal(size=(3, 2)), alpha=1 + chain_id)
369374
>>> exfit1 = stan(model_code=excode, init=initfun2)
370375
"""
376+
warnings.warn('pystan.stan was deprecated in version 2.17 and will be removed in version 3.0. '
377+
'Compile and use a Stan program in separate steps.', DeprecationWarning)
371378
# NOTE: this is a thin wrapper for other functions. Error handling occurs
372379
# elsewhere.
373380
if data is None:

0 commit comments

Comments
 (0)