Skip to content

Commit c45dc76

Browse files
committed
Merge pull request #11898 from jreback/stats
DEPR: pandas.stats.var, pandas.stats.plm, pandas.stats.ols, pandas.stats.fama_macbeth
2 parents d636a74 + 47dd9e7 commit c45dc76

File tree

8 files changed

+159
-70
lines changed

8 files changed

+159
-70
lines changed

doc/source/whatsnew/v0.18.0.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ Deprecations
253253
For example, instead of ``s.rolling(window=5,freq='D').max()`` to get the max value on a rolling 5 Day window, one could use ``s.resample('D',how='max').rolling(window=5).max()``, which first resamples the data to daily data, then provides a rolling 5 day window.
254254

255255
- ``pd.tseries.frequencies.get_offset_name`` function is deprecated. Use offset's ``.freqstr`` property as alternative (:issue:`11192`)
256+
- ``pandas.stats.fama_macbeth`` routines are deprecated and will be removed in a future version (:issue:`6077`)
257+
- ``pandas.stats.ols``, ``pandas.stats.plm`` and ``pandas.stats.var`` routines are deprecated and will be removed in a future version (:issue:`6077`)
256258

257259
.. _whatsnew_0180.prior_deprecations:
258260

@@ -346,4 +348,4 @@ Bug Fixes
346348

347349
- Bug in ``read_sql`` with pymysql connections failing to return chunked data (:issue:`11522`)
348350

349-
- Bug in ``DataFrame`` when masking an empty ``DataFrame`` (:issue:`11859`)
351+
- Bug in ``DataFrame`` when masking an empty ``DataFrame`` (:issue:`11859`)

pandas/stats/fama_macbeth.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def fama_macbeth(**kwargs):
1717
1818
nw_lags_beta: int
1919
Newey-West adjusts the betas by the given lags
20-
"""
20+
"""
2121
window_type = kwargs.get('window_type')
2222
if window_type is None:
2323
klass = FamaMacBeth
@@ -32,6 +32,12 @@ def __init__(self, y, x, intercept=True, nw_lags=None,
3232
nw_lags_beta=None,
3333
entity_effects=False, time_effects=False, x_effects=None,
3434
cluster=None, dropped_dummies=None, verbose=False):
35+
import warnings
36+
warnings.warn("The pandas.stats.fama_macbeth module is deprecated and will be "
37+
"removed in a future version. We refer to external packages "
38+
"like statsmodels, see here: http://statsmodels.sourceforge.net/stable/index.html",
39+
FutureWarning, stacklevel=4)
40+
3541
if dropped_dummies is None:
3642
dropped_dummies = {}
3743
self._nw_lags_beta = nw_lags_beta

pandas/stats/ols.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ class OLS(StringMixin):
4747

4848
def __init__(self, y, x, intercept=True, weights=None, nw_lags=None,
4949
nw_overlap=False):
50+
import warnings
51+
warnings.warn("The pandas.stats.ols module is deprecated and will be "
52+
"removed in a future version. We refer to external packages "
53+
"like statsmodels, see some examples here: http://statsmodels.sourceforge.net/stable/regression.html",
54+
FutureWarning, stacklevel=4)
55+
5056
try:
5157
import statsmodels.api as sm
5258
except ImportError:
@@ -1197,8 +1203,11 @@ def _results(self):
11971203

11981204
@cache_readonly
11991205
def _window_time_obs(self):
1200-
window_obs = moments.rolling_sum(self._time_obs_count > 0,
1201-
self._window, min_periods=1)
1206+
window_obs = (Series(self._time_obs_count > 0)
1207+
.rolling(self._window, min_periods=1)
1208+
.sum()
1209+
.values
1210+
)
12021211

12031212
window_obs[np.isnan(window_obs)] = 0
12041213
return window_obs.astype(int)
@@ -1211,8 +1220,7 @@ def _nobs_raw(self):
12111220
# expanding case
12121221
window = len(self._index)
12131222

1214-
result = moments.rolling_sum(self._time_obs_count, window,
1215-
min_periods=1)
1223+
result = Series(self._time_obs_count).rolling(window, min_periods=1).sum().values
12161224

12171225
return result.astype(int)
12181226

pandas/stats/plm.py

+11
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ def __init__(self, y, x, weights=None, intercept=True, nw_lags=None,
3434
entity_effects=False, time_effects=False, x_effects=None,
3535
cluster=None, dropped_dummies=None, verbose=False,
3636
nw_overlap=False):
37+
import warnings
38+
warnings.warn("The pandas.stats.plm module is deprecated and will be "
39+
"removed in a future version. We refer to external packages "
40+
"like statsmodels, see some examples here: http://statsmodels.sourceforge.net/stable/mixed_linear.html",
41+
FutureWarning, stacklevel=4)
3742
self._x_orig = x
3843
self._y_orig = y
3944
self._weights = weights
@@ -732,6 +737,12 @@ def __init__(self, y, x, window_type='full_sample', window=None,
732737
min_periods=None, intercept=True, nw_lags=None,
733738
nw_overlap=False):
734739

740+
import warnings
741+
warnings.warn("The pandas.stats.plm module is deprecated and will be "
742+
"removed in a future version. We refer to external packages "
743+
"like statsmodels, see some examples here: http://statsmodels.sourceforge.net/stable/mixed_linear.html",
744+
FutureWarning, stacklevel=4)
745+
735746
for attr in self.ATTRIBUTES:
736747
setattr(self.__class__, attr, create_ols_attr(attr))
737748

pandas/stats/tests/test_fama_macbeth.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from pandas.compat import range
66
from pandas import compat
7+
import pandas.util.testing as tm
78
import numpy as np
89

910

@@ -23,8 +24,9 @@ def testFamaMacBethRolling(self):
2324
def checkFamaMacBethExtended(self, window_type, x, y, **kwds):
2425
window = 25
2526

26-
result = fama_macbeth(y=y, x=x, window_type=window_type, window=window,
27-
**kwds)
27+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
28+
result = fama_macbeth(y=y, x=x, window_type=window_type, window=window,
29+
**kwds)
2830
self._check_stuff_works(result)
2931

3032
index = result._index
@@ -43,10 +45,12 @@ def checkFamaMacBethExtended(self, window_type, x, y, **kwds):
4345
x2[k] = v.truncate(start, end)
4446
y2 = y.truncate(start, end)
4547

46-
reference = fama_macbeth(y=y2, x=x2, **kwds)
48+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
49+
reference = fama_macbeth(y=y2, x=x2, **kwds)
4750
assert_almost_equal(reference._stats, result._stats[:, i])
4851

49-
static = fama_macbeth(y=y2, x=x2, **kwds)
52+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
53+
static = fama_macbeth(y=y2, x=x2, **kwds)
5054
self._check_stuff_works(static)
5155

5256
def _check_stuff_works(self, result):

pandas/stats/tests/test_math.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def test_solve_rect(self):
5252

5353
b = Series(np.random.randn(N), self.frame.index)
5454
result = pmath.solve(self.frame, b)
55-
expected = ols(y=b, x=self.frame, intercept=False).beta
55+
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
56+
expected = ols(y=b, x=self.frame, intercept=False).beta
5657
self.assertTrue(np.allclose(result, expected))
5758

5859
def test_inv_illformed(self):

0 commit comments

Comments
 (0)