def test_patsy_lazy_dict(): class LazyDict(dict): def __init__(self, data): self.data = data def __missing__(self, key): return np.array(self.data[key]) data = cpunish.load_pandas().data data = LazyDict(data) res = ols('EXECUTIONS ~ SOUTH + INCOME', data=data).fit() res2 = res.predict(data) npt.assert_allclose(res.fittedvalues, res2) data = cpunish.load_pandas().data data['INCOME'].loc[0] = None data = LazyDict(data) data.index = cpunish.load_pandas().data.index res = ols('EXECUTIONS ~ SOUTH + INCOME', data=data).fit() res2 = res.predict(data) assert_equal(res.fittedvalues, res2) # Should lose a record assert_equal(len(res2) + 1, len(cpunish.load_pandas().data))
def test_patsy_lazy_dict(): class LazyDict(dict): def __init__(self, data): self.data = data def __missing__(self, key): return np.array(self.data[key]) data = cpunish.load_pandas().data data = LazyDict(data) res = ols('EXECUTIONS ~ SOUTH + INCOME', data=data).fit() res2 = res.predict(data) npt.assert_allclose(res.fittedvalues, res2) data = cpunish.load_pandas().data data['INCOME'].loc[0] = None data = LazyDict(data) data.index = cpunish.load_pandas().data.index res = ols('EXECUTIONS ~ SOUTH + INCOME', data=data).fit() res2 = res.predict(data) assert_equal(res.fittedvalues, res2) # Should lose a record assert_equal(len(res2) + 1, len(cpunish.load_pandas().data))
def test_patsy_missing_data(): # Test pandas-style first data = cpunish.load_pandas().data data['INCOME'].loc[0] = None res = ols('EXECUTIONS ~ SOUTH + INCOME', data=data).fit() res2 = res.predict(data) # First record will be dropped during fit, but not during predict assert_equal(res.fittedvalues, res2[1:]) # Non-pandas version data = cpunish.load_pandas().data data['INCOME'].loc[0] = None data = data.to_records(index=False) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") res2 = res.predict(data) assert 'ValueWarning' in repr(w[-1].message) assert 'nan values have been dropped' in repr(w[-1].message) # Frist record will be dropped in both cases assert_equal(res.fittedvalues, res2)
def test_patsy_missing_data(): # Test pandas-style first data = cpunish.load_pandas().data data['INCOME'].loc[0] = None res = ols('EXECUTIONS ~ SOUTH + INCOME', data=data).fit() res2 = res.predict(data) # First record will be dropped during fit, but not during predict assert_equal(res.fittedvalues, res2[1:]) # Non-pandas version data = cpunish.load_pandas().data data['INCOME'].loc[0] = None data = data.to_records(index=False) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") res2 = res.predict(data) assert 'ValueWarning' in repr(w[-1].message) assert 'nan values have been dropped' in repr(w[-1].message) # Frist record will be dropped in both cases assert_equal(res.fittedvalues, res2)