Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ matrix:
- PYTHON=3.7
- PANDAS=0.25
- NUMPY=1.17
- SCIPY=1.3
- SCIPY=1.4
- COVERAGE=true
- PYTEST_OPTIONS=
# Python 3.6 + legacy blas + older pandas
Expand All @@ -66,7 +66,7 @@ matrix:
- PYTHON=3.6
- NUMPY=1.16
- PANDAS=0.24
- SCIPY=1.2
- SCIPY=1.3
- BLAS="nomkl blas=*=openblas"
- COVERAGE=true
- PYTEST_OPTIONS=
Expand All @@ -75,7 +75,7 @@ matrix:
env:
- PYTHON=3.6
- NUMPY=1.15
- SCIPY=1.1
- SCIPY=1.2
- PANDAS=0.23
- MATPLOTLIB=2
- LINT=true
Expand Down
2 changes: 1 addition & 1 deletion docs/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ The current minimum dependencies are:

* `Python <https://www.python.org>`__ >= 3.6
* `NumPy <https://www.scipy.org/>`__ >= 1.15
* `SciPy <https://www.scipy.org/>`__ >= 1.1
* `SciPy <https://www.scipy.org/>`__ >= 1.2
* `Pandas <https://pandas.pydata.org/>`__ >= 0.23
* `Patsy <https://patsy.readthedocs.io/en/latest/>`__ >= 0.5.1

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ requires = [
"numpy==1.15.4; python_version=='3.6'",
"numpy==1.15.4; python_version=='3.7'",
"numpy==1.17.5; python_version>='3.8'",
"scipy>=1.1",
"scipy>=1.2",
]
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
numpy>=1.15
scipy>=1.1
scipy>=1.2
pandas>=0.23
patsy>=0.5.1
10 changes: 5 additions & 5 deletions statsmodels/base/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,8 @@ def __init__(self, model, params, **kwd):
self.__dict__.update(kwd)
self.initialize(model, params, **kwd)
self._data_attr = []
# Variables to clear from cache
self._data_in_cache = ['fittedvalues', 'resid', 'wresid']

def initialize(self, model, params, **kwargs):
"""
Expand Down Expand Up @@ -2191,8 +2193,8 @@ def remove_data(self):
model._data_attr : arrays attached to both the model instance
and the results instance with the same attribute name.

result.data_in_cache : arrays that may exist as values in
result._cache (TODO : should privatize name)
result._data_in_cache : arrays that may exist as values in
result._cache

result._data_attr_model : arrays attached to the model
instance but not to the results instance
Expand Down Expand Up @@ -2239,9 +2241,7 @@ def wipe(obj, att):
continue
wipe(self, att)

data_in_cache = getattr(self, 'data_in_cache', [])
data_in_cache += ['fittedvalues', 'resid', 'wresid']
for key in data_in_cache:
for key in self._data_in_cache:
try:
self._cache[key] = None
except (AttributeError, KeyError):
Expand Down
3 changes: 1 addition & 2 deletions statsmodels/genmod/generalized_linear_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1463,8 +1463,7 @@ def __init__(self, model, params, normalized_cov_params, scale,
# for remove data and pickle without large arrays
self._data_attr.extend(['results_constrained', '_freq_weights',
'_var_weights', '_iweights'])
self.data_in_cache = getattr(self, 'data_in_cache', [])
self.data_in_cache.extend(['null', 'mu'])
self._data_in_cache.extend(['null', 'mu'])
self._data_attr_model = getattr(self, '_data_attr_model', [])
self._data_attr_model.append('mu')

Expand Down
9 changes: 6 additions & 3 deletions statsmodels/regression/_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,12 @@ def get_prediction(self, exog=None, transform=True, weights=None,
row_labels = None

exog = np.asarray(exog)
if exog.ndim == 1 and (self.model.exog.ndim == 1 or
self.model.exog.shape[1] == 1):
exog = exog[:, None]
if exog.ndim == 1:
# Params informs whether a row or column vector
if self.params.shape[0] > 1:
exog = exog[None, :]
else:
exog = exog[:, None]
exog = np.atleast_2d(exog) # needed in count model shape[1]
else:
exog = self.model.exog
Expand Down
4 changes: 3 additions & 1 deletion statsmodels/regression/linear_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class RegressionModel(base.LikelihoodModel):
"""
def __init__(self, endog, exog, **kwargs):
super(RegressionModel, self).__init__(endog, exog, **kwargs)
self._data_attr.extend(['pinv_wexog', 'wendog', 'wexog', 'weights'])
self._data_attr.extend(['pinv_wexog', 'weights'])

def initialize(self):
"""Initialize model components."""
Expand Down Expand Up @@ -1554,6 +1554,8 @@ def __init__(self, model, params, normalized_cov_params=None, scale=1.,
super(RegressionResults, self).__init__(
model, params, normalized_cov_params, scale)

# Keep wresid since needed by predict
self._data_in_cache.remove("wresid")
self._cache = {}
if hasattr(model, 'wexog_singular_values'):
self._wexog_singular_values = model.wexog_singular_values
Expand Down
1 change: 1 addition & 0 deletions statsmodels/regression/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ class RollingRegressionResults(object):
cov_type : str
Name of covariance estimator
"""
_data_in_cache = tuple()

def __init__(
self, model, store: RollingStore, k_constant, use_t, cov_type
Expand Down
18 changes: 16 additions & 2 deletions statsmodels/regression/tests/test_predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import numpy as np
from numpy.testing import assert_allclose, assert_equal
import pandas as pd

from statsmodels.regression.linear_model import OLS, WLS
from statsmodels.sandbox.regression.predstd import wls_prediction_std
Expand Down Expand Up @@ -132,7 +133,6 @@ def setup_class(cls):
mod_wls = WLS(y, X, weights=1./w)
cls.res_wls = mod_wls.fit()


def test_ci(self):
res_wls = self.res_wls
prstd, iv_l, iv_u = wls_prediction_std(res_wls)
Expand All @@ -159,7 +159,7 @@ def test_ci(self):

# check that list works, issue 4437
x = res_wls.model.exog.mean(0)
pred_res3 = res_wls.get_prediction(x)
pred_res3 = res_wls.get_prediction([x])
ci3 = pred_res3.conf_int(obs=True)
pred_res3b = res_wls.get_prediction(x.tolist())
ci3b = pred_res3b.conf_int(obs=True)
Expand Down Expand Up @@ -258,3 +258,17 @@ def test_glm(self):
assert_allclose(ci3b, ci3, rtol=1e-13)
res_df = pred_res3b.summary_frame()
assert_equal(res_df.index.values, [0, 1])


def test_predict_remove_data():
# GH6887
endog = [i + np.random.normal(scale=0.1) for i in range(100)]
exog = [i for i in range(100)]
model = OLS(endog, exog, weights=[1 for _ in range(100)]).fit()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OLS shouldn't have weights

model.remove_data()
scalar = model.get_prediction(1).predicted_mean
one_d = model.get_prediction([1]).predicted_mean
assert_allclose(scalar, one_d)

series = model.get_prediction(pd.Series([1])).predicted_mean
assert_allclose(scalar, series)
2 changes: 1 addition & 1 deletion statsmodels/robust/robust_linear_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def __init__(self, model, params, normalized_cov_params, scale):
self.nobs = model.nobs
self._cache = {}
# for remove_data
self.data_in_cache = ['sresid']
self._data_in_cache.extend(['sresid'])

self.cov_params_default = self.bcov_scaled
# TODO: "pvals" should come from chisq on bse?
Expand Down
2 changes: 1 addition & 1 deletion statsmodels/stats/contingency_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@ def mcnemar(table, exact=True, correction=True):
if exact:
statistic = np.minimum(n1, n2)
# binom is symmetric with p=0.5
# SciPy 1.7+ required int arguments
# SciPy 1.7+ requires int arguments
int_sum = int(n1 + n2)
if int_sum != (n1 + n2):
warnings.warn("exact can only be used with tables containing "
Expand Down
5 changes: 0 additions & 5 deletions statsmodels/tests/test_package.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import subprocess
import sys

import pytest

from statsmodels.compat.scipy import SCIPY_11


def test_lazy_imports():
# Check that when statsmodels.api is imported, matplotlib is _not_ imported
Expand All @@ -19,7 +15,6 @@ def test_lazy_imports():
assert rc == 0


@pytest.mark.skipif(SCIPY_11, reason='SciPy raises on -OO')
def test_docstring_optimization_compat():
# GH#5235 check that importing with stripped docstrings does not raise
cmd = sys.executable + ' -OO -c "import statsmodels.api as sm"'
Expand Down
2 changes: 1 addition & 1 deletion statsmodels/tsa/exponential_smoothing/initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _initialization_heuristic(endog, trend=False, seasonal=False,

# Seasonal component
initial_seasonal = None
if seasonal is not None:
if seasonal:
# Calculate the number of full cycles to use
if nobs < 2 * seasonal_periods:
raise ValueError('Cannot compute initial seasonals using'
Expand Down
2 changes: 0 additions & 2 deletions statsmodels/tsa/statespace/mlemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2417,8 +2417,6 @@ def __init__(self, model, params, results, cov_type=None, cov_kwds=None,
self._data_attr_model.extend(['ssm'])
self._data_attr.extend(extra_arrays)
self._data_attr.extend(['filter_results', 'smoother_results'])
self.data_in_cache = getattr(self, 'data_in_cache', [])
self.data_in_cache.extend([])

def _get_robustcov_results(self, cov_type='opg', **kwargs):
"""
Expand Down
31 changes: 20 additions & 11 deletions statsmodels/tsa/statespace/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,14 +561,14 @@ def _constrain_sv_less_than_one_python(unconstrained, order=None,
Partial autocorrelation matrices. Should be a list of length
`order`, where each element is an array sized `k_endog` x `k_endog`.

See Also
--------
constrain_stationary_multivariate

Notes
-----
Corresponds to Lemma 2.2 in Ansley and Kohn (1986). See
`constrain_stationary_multivariate` for more details.

There is a Cython implementation of this function that can be much faster,
but which requires SciPy 0.14.0 or greater. See
`constrain_stationary_multivariate` for details.
"""

from scipy import linalg
Expand Down Expand Up @@ -620,14 +620,14 @@ def _compute_coefficients_from_multivariate_pacf_python(
Transformed coefficient matrices leading to a stationary VAR
representation.

See Also
--------
constrain_stationary_multivariate

Notes
-----
Corresponds to Lemma 2.1 in Ansley and Kohn (1986). See
`constrain_stationary_multivariate` for more details.

There is a Cython implementation of this function that can be much faster,
but which requires SciPy 0.14.0 or greater. See
`constrain_stationary_multivariate` for details.
"""
from scipy import linalg

Expand Down Expand Up @@ -931,6 +931,10 @@ def _unconstrain_sv_less_than_one(constrained, order=None, k_endog=None):
Unconstrained matrices. A list of length `order`, where each element is
an array sized `k_endog` x `k_endog`.

See Also
--------
unconstrain_stationary_multivariate

Notes
-----
Corresponds to the inverse of Lemma 2.2 in Ansley and Kohn (1986). See
Expand Down Expand Up @@ -1162,15 +1166,17 @@ def _compute_multivariate_pacf_from_autocovariances(autocovariances,
pacf : list
List of first `order` multivariate partial autocorrelations.

See Also
--------
unconstrain_stationary_multivariate

Notes
-----
Note that this computes multivariate partial autocorrelations.

Corresponds to the inverse of Lemma 2.1 in Ansley and Kohn (1986). See
`unconstrain_stationary_multivariate` for more details.

Notes
-----
Computes sample partial autocorrelations if sample autocovariances are
given.
"""
Expand Down Expand Up @@ -1326,6 +1332,10 @@ def _compute_multivariate_pacf_from_coefficients(constrained, error_variance,
pacf : list
List of first `order` multivariate partial autocorrelations.

See Also
--------
unconstrain_stationary_multivariate

Notes
-----
Note that this computes multivariate partial autocorrelations.
Expand All @@ -1335,7 +1345,6 @@ def _compute_multivariate_pacf_from_coefficients(constrained, error_variance,

Notes
-----

Coefficients are assumed to be provided from the VAR model:

.. math::
Expand Down