Skip to content

Commit

Permalink
BUG: Correct dimension when data removed
Browse files Browse the repository at this point in the history
Correct exog dimension when data has been removed

closes statsmodels#6887
  • Loading branch information
bashtage committed Jul 17, 2020
1 parent 3614385 commit bc22619
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 22 deletions.
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
3 changes: 2 additions & 1 deletion statsmodels/regression/_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ 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
if exog.ndim == 1 and (self.model.exog is None or
self.model.exog.ndim == 1 or
self.model.exog.shape[1] == 1):
exog = exog[:, None]
exog = np.atleast_2d(exog) # needed in count model shape[1]
Expand Down
11 changes: 11 additions & 0 deletions statsmodels/regression/tests/test_predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,14 @@ 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()
model.remove_data()
# works fine
assert_allclose(model.get_prediction(1).predicted_mean,
model.get_prediction([1]).predicted_mean)
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
17 changes: 9 additions & 8 deletions statsmodels/tsa/statespace/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,14 +561,15 @@ 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 +621,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

0 comments on commit bc22619

Please sign in to comment.