From 4edc28c1f54bad82a8ae6f6ed292ab5710de4967 Mon Sep 17 00:00:00 2001 From: rockg Date: Tue, 15 Oct 2013 16:11:39 -0400 Subject: [PATCH 1/2] Cast input to DataFrame from Series before performing operations --- pandas/stats/ols.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/stats/ols.py b/pandas/stats/ols.py index 9d22068c1612f..83fb387254eda 100644 --- a/pandas/stats/ols.py +++ b/pandas/stats/ols.py @@ -445,12 +445,12 @@ def predict(self, beta=None, x=None, fill_value=None, orig_x = x else: orig_x = x + if isinstance(x, Series): + x = DataFrame({'x': x}) if fill_value is None and fill_method is None: x = x.dropna(how='any') else: x = x.fillna(value=fill_value, method=fill_method, axis=axis) - if isinstance(x, Series): - x = DataFrame({'x': x}) if self._intercept: x['intercept'] = 1. From f8ee140adafddc219ed5e006f0b1264e110de167 Mon Sep 17 00:00:00 2001 From: rockg Date: Tue, 15 Oct 2013 16:11:39 -0400 Subject: [PATCH 2/2] Fix bug OLS.predict() when Series is passed by casting to DataFrame first. --- pandas/stats/tests/test_ols.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/stats/tests/test_ols.py b/pandas/stats/tests/test_ols.py index df2f545c90b92..e487eb3bad5b8 100644 --- a/pandas/stats/tests/test_ols.py +++ b/pandas/stats/tests/test_ols.py @@ -378,6 +378,9 @@ def test_series_rhs(self): model = ols(y=y, x=x) expected = ols(y=y, x={'x': x}) assert_series_equal(model.beta, expected.beta) + + # Test predict using a series + assert_series_equal(model.y_predict, model.predict(x=x)) def test_various_attributes(self): # just make sure everything "works". test correctness elsewhere