Skip to content

Commit 2d68025

Browse files
add deprecation warnings for old backends (#3902)
* add deprecation warnings for old backends * mention backend deprecation #3902 * fix typo Co-authored-by: Colin <[email protected]> Co-authored-by: Michael Osthege <[email protected]> Co-authored-by: Colin <[email protected]>
1 parent d59a6e8 commit 2d68025

File tree

5 files changed

+59
-1
lines changed

5 files changed

+59
-1
lines changed

RELEASE-NOTES.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
### Maintenance
1919
- Remove `sample_ppc` and `sample_ppc_w` that were deprecated in 3.6.
2020
- Tuning results no longer leak into sequentially sampled `Metropolis` chains (see #3733 and #3796).
21-
- Deprecated `sd` in version 3.7 has been replaced by `sigma` now raises `DepreciationWarning` on using `sd` in continuous, mixed and timeseries distributions. (see #3837 and #3688).
21+
- Deprecated `sd` in version 3.7 has been replaced by `sigma` now raises `DeprecationWarning` on using `sd` in continuous, mixed and timeseries distributions. (see #3837 and #3688).
22+
- We'll deprecate the `Text` and `SQLite` backends and the `save_trace`/`load_trace` functions, since this is now done with ArviZ. (see [#3902](https://github.com/pymc-devs/pymc3/pull/3902))
2223
- In named models, `pm.Data` objects now get model-relative names (see [#3843](https://github.com/pymc-devs/pymc3/pull/3843)).
2324
- `pm.sample` now takes 1000 draws and 1000 tuning samples by default, instead of 500 previously (see [#3855](https://github.com/pymc-devs/pymc3/pull/3855)).
2425
- Dropped some deprecated kwargs and functions (see [#3906](https://github.com/pymc-devs/pymc3/pull/3906))

pymc3/backends/ndarray.py

+18
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import os
2222
import shutil
2323
from typing import Optional, Dict, Any, List
24+
import warnings
2425

2526
import numpy as np
2627
from pymc3.backends import base
@@ -52,6 +53,12 @@ def save_trace(trace: MultiTrace, directory: Optional[str]=None, overwrite=False
5253
-------
5354
str, path to the directory where the trace was saved
5455
"""
56+
warnings.warn(
57+
'The `save_trace` function will soon be removed.'
58+
'Instead, use ArviZ to save/load traces.',
59+
DeprecationWarning,
60+
)
61+
5562
if directory is None:
5663
directory = '.pymc_{}.trace'
5764
idx = 1
@@ -89,6 +96,11 @@ def load_trace(directory: str, model=None) -> MultiTrace:
8996
-------
9097
pm.Multitrace that was saved in the directory
9198
"""
99+
warnings.warn(
100+
'The `load_trace` function will soon be removed.'
101+
'Instead, use ArviZ to save/load traces.',
102+
DeprecationWarning,
103+
)
92104
straces = []
93105
for subdir in glob.glob(os.path.join(directory, '*')):
94106
if os.path.isdir(subdir):
@@ -106,6 +118,11 @@ class SerializeNDArray:
106118

107119
def __init__(self, directory: str):
108120
"""Helper to save and load NDArray objects"""
121+
warnings.warn(
122+
'The `SerializeNDArray` class will soon be removed. '
123+
'Instead, use ArviZ to save/load traces.',
124+
DeprecationWarning,
125+
)
109126
self.directory = directory
110127
self.metadata_path = os.path.join(self.directory, self.metadata_file)
111128
self.samples_path = os.path.join(self.directory, self.samples_file)
@@ -367,6 +384,7 @@ def _slice_as_ndarray(strace, idx):
367384

368385
return sliced
369386

387+
370388
def point_list_to_multitrace(point_list: List[Dict[str, np.ndarray]], model: Optional[Model]=None) -> MultiTrace:
371389
'''transform point list into MultiTrace'''
372390
_model = modelcontext(model)

pymc3/backends/sqlite.py

+13
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"""
3333
import numpy as np
3434
import sqlite3
35+
import warnings
3536

3637
from ..backends import base, ndarray
3738
from . import tracetab as ttab
@@ -89,6 +90,12 @@ class SQLite(base.BaseTrace):
8990
"""
9091

9192
def __init__(self, name, model=None, vars=None, test_point=None):
93+
warnings.warn(
94+
'The `SQLite` backend will soon be removed. '
95+
'Please switch to a different backend. '
96+
'If you have good reasons for using the SQLite backend, file an issue and tell us about them.',
97+
DeprecationWarning,
98+
)
9299
super().__init__(name, model, vars, test_point)
93100
self._var_cols = {}
94101
self.var_inserts = {} # varname -> insert statement
@@ -322,6 +329,12 @@ def load(name, model=None):
322329
-------
323330
A MultiTrace instance
324331
"""
332+
warnings.warn(
333+
'The `sqlite.load` function will soon be removed. '
334+
'Please use ArviZ to save traces. '
335+
'If you have good reasons for using the `load` function, file an issue and tell us about them. ',
336+
DeprecationWarning,
337+
)
325338
db = _SQLiteDB(name)
326339
db.connect()
327340
varnames = _get_table_list(db.cursor)

pymc3/backends/text.py

+19
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import os
3434
import re
3535
import pandas as pd
36+
import warnings
3637

3738
from ..backends import base, ndarray
3839
from . import tracetab as ttab
@@ -57,6 +58,12 @@ class Text(base.BaseTrace):
5758
"""
5859

5960
def __init__(self, name, model=None, vars=None, test_point=None):
61+
warnings.warn(
62+
'The `Text` backend will soon be removed. '
63+
'Please switch to a different backend. '
64+
'If you have good reasons for using the Text backend, file an issue and tell us about them. ',
65+
DeprecationWarning,
66+
)
6067
if not os.path.exists(name):
6168
os.mkdir(name)
6269
super().__init__(name, model, vars, test_point)
@@ -185,6 +192,12 @@ def load(name, model=None):
185192
-------
186193
A MultiTrace instance
187194
"""
195+
warnings.warn(
196+
'The `load` function will soon be removed. '
197+
'Please use ArviZ to save traces. '
198+
'If you have good reasons for using the `load` function, file an issue and tell us about them. ',
199+
DeprecationWarning,
200+
)
188201
files = glob(os.path.join(name, 'chain-*.csv'))
189202

190203
if len(files) == 0:
@@ -224,6 +237,12 @@ def dump(name, trace, chains=None):
224237
chains: list
225238
Chains to dump. If None, all chains are dumped.
226239
"""
240+
warnings.warn(
241+
'The `dump` function will soon be removed. '
242+
'Please use ArviZ to save traces. '
243+
'If you have good reasons for using the `dump` function, file an issue and tell us about them. ',
244+
DeprecationWarning,
245+
)
227246
if not os.path.exists(name):
228247
os.mkdir(name)
229248
if chains is None:

pymc3/backends/tracetab.py

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import numpy as np
1919
import pandas as pd
20+
import warnings
2021

2122
from ..util import get_default_varnames
2223

@@ -39,6 +40,12 @@ def trace_to_dataframe(trace, chains=None, varnames=None, include_transformed=Fa
3940
If true transformed variables will be included in the resulting
4041
DataFrame.
4142
"""
43+
warnings.warn(
44+
'The `trace_to_dataframe` function will soon be removed. '
45+
'Please use ArviZ to save traces. '
46+
'If you have good reasons for using the `trace_to_dataframe` function, file an issue and tell us about them. ',
47+
DeprecationWarning,
48+
)
4249
var_shapes = trace._straces[0].var_shapes
4350

4451
if varnames is None:

0 commit comments

Comments
 (0)