<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> from datetime import datetime <EOL> from pandas import compat <EOL> from distutils . version import LooseVersion <EOL> import nose <EOL> import numpy as np <EOL> from numpy . testing . decorators import slow <EOL> from pandas import date_range , bdate_range <EOL> from pandas . core . panel import Panel <EOL> from pandas import DataFrame , Index , Series , notnull , datetools <EOL> from pandas . stats . api import ols <EOL> from pandas . stats . ols import _filter_data <EOL> from pandas . stats . plm import NonPooledPanelOLS , PanelOLS <EOL> from pandas . util . testing import ( assert_almost_equal , assert_series_equal , <EOL> assert_frame_equal , assertRaisesRegexp ) <EOL> import pandas . util . testing as tm <EOL> import pandas . compat as compat <EOL> from . common import BaseTest <EOL> _have_statsmodels = True <EOL> try : <EOL> import statsmodels . api as sm <EOL> except ImportError : <EOL> try : <EOL> import scikits . statsmodels . api as sm <EOL> except ImportError : <EOL> _have_statsmodels = False <EOL> def _check_repr ( obj ) : <EOL> repr ( obj ) <EOL> str ( obj ) <EOL> def _compare_ols_results ( model1 , model2 ) : <EOL> tm . assertIsInstance ( model1 , type ( model2 ) ) <EOL> if hasattr ( model1 , '<STR_LIT>' ) : <EOL> _compare_moving_ols ( model1 , model2 ) <EOL> else : <EOL> _compare_fullsample_ols ( model1 , model2 ) <EOL> def _compare_fullsample_ols ( model1 , model2 ) : <EOL> assert_series_equal ( model1 . beta , model2 . beta ) <EOL> def _compare_moving_ols ( model1 , model2 ) : <EOL> assert_frame_equal ( model1 . beta , model2 . beta ) <EOL> class TestOLS ( BaseTest ) : <EOL> _multiprocess_can_split_ = True <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> super ( TestOLS , cls ) . setUpClass ( ) <EOL> try : <EOL> import matplotlib as mpl <EOL> mpl . use ( '<STR_LIT>' , warn = False ) <EOL> except ImportError : <EOL> pass <EOL> if not _have_statsmodels : <EOL> raise nose . SkipTest ( "<STR_LIT>" ) <EOL> def testOLSWithDatasets_ccard ( self ) : <EOL> self . checkDataSet ( sm . datasets . ccard . load ( ) , skip_moving = True ) <EOL> self . checkDataSet ( sm . datasets . cpunish . load ( ) , skip_moving = True ) <EOL> self . checkDataSet ( sm . datasets . longley . load ( ) , skip_moving = True ) <EOL> self . checkDataSet ( sm . datasets . stackloss . load ( ) , skip_moving = True ) <EOL> @ slow <EOL> def testOLSWithDatasets_copper ( self ) : <EOL> self . checkDataSet ( sm . datasets . copper . load ( ) ) <EOL> @ slow <EOL> def testOLSWithDatasets_scotland ( self ) : <EOL> self . checkDataSet ( sm . datasets . scotland . load ( ) ) <EOL> def testWLS ( self ) : <EOL> sm_version = sm . version . version <EOL> if sm_version < LooseVersion ( '<STR_LIT>' ) : <EOL> raise nose . SkipTest ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( sm_version ) ) <EOL> X = DataFrame ( np . random . randn ( <NUM_LIT:30> , <NUM_LIT:4> ) , columns = [ '<STR_LIT:A>' , '<STR_LIT:B>' , '<STR_LIT:C>' , '<STR_LIT:D>' ] ) <EOL> Y = Series ( np . random . randn ( <NUM_LIT:30> ) ) <EOL> weights = X . std ( <NUM_LIT:1> ) <EOL> self . _check_wls ( X , Y , weights ) <EOL> weights . ix [ [ <NUM_LIT:5> , <NUM_LIT:15> ] ] = np . nan <EOL> Y [ [ <NUM_LIT:2> , <NUM_LIT> ] ] = np . nan <EOL> self . _check_wls ( X , Y , weights ) <EOL> def _check_wls ( self , x , y , weights ) : <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> result = ols ( y = y , x = x , weights = <NUM_LIT:1> / weights ) <EOL> combined = x . copy ( ) <EOL> combined [ '<STR_LIT>' ] = y <EOL> combined [ '<STR_LIT>' ] = weights <EOL> combined = combined . dropna ( ) <EOL> endog = combined . pop ( '<STR_LIT>' ) . values <EOL> aweights = combined . pop ( '<STR_LIT>' ) . values <EOL> exog = sm . add_constant ( combined . values , prepend = False ) <EOL> sm_result = sm . WLS ( endog , exog , weights = <NUM_LIT:1> / aweights ) . fit ( ) <EOL> assert_almost_equal ( sm_result . params , result . _beta_raw ) <EOL> assert_almost_equal ( sm_result . resid , result . _resid_raw ) <EOL> self . checkMovingOLS ( '<STR_LIT>' , x , y , weights = weights ) <EOL> self . checkMovingOLS ( '<STR_LIT>' , x , y , weights = weights ) <EOL> def checkDataSet ( self , dataset , start = None , end = None , skip_moving = False ) : <EOL> exog = dataset . exog [ start : end ] <EOL> endog = dataset . endog [ start : end ] <EOL> x = DataFrame ( exog , index = np . arange ( exog . shape [ <NUM_LIT:0> ] ) , <EOL> columns = np . arange ( exog . shape [ <NUM_LIT:1> ] ) ) <EOL> y = Series ( endog , index = np . arange ( len ( endog ) ) ) <EOL> self . checkOLS ( exog , endog , x , y ) <EOL> if not skip_moving : <EOL> self . checkMovingOLS ( '<STR_LIT>' , x , y ) <EOL> self . checkMovingOLS ( '<STR_LIT>' , x , y , nw_lags = <NUM_LIT:0> ) <EOL> self . checkMovingOLS ( '<STR_LIT>' , x , y , nw_lags = <NUM_LIT:0> ) <EOL> self . checkMovingOLS ( '<STR_LIT>' , x , y , nw_lags = <NUM_LIT:1> ) <EOL> self . checkMovingOLS ( '<STR_LIT>' , x , y , nw_lags = <NUM_LIT:1> ) <EOL> self . checkMovingOLS ( '<STR_LIT>' , x , y , nw_lags = <NUM_LIT:1> , nw_overlap = True ) <EOL> def checkOLS ( self , exog , endog , x , y ) : <EOL> reference = sm . OLS ( endog , sm . add_constant ( exog , prepend = False ) ) . fit ( ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> result = ols ( y = y , x = x ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> sparse_result = ols ( y = y . to_sparse ( ) , x = x . to_sparse ( ) ) <EOL> _compare_ols_results ( result , sparse_result ) <EOL> assert_almost_equal ( reference . params , result . _beta_raw ) <EOL> assert_almost_equal ( reference . df_model , result . _df_model_raw ) <EOL> assert_almost_equal ( reference . df_resid , result . _df_resid_raw ) <EOL> assert_almost_equal ( reference . fvalue , result . _f_stat_raw [ <NUM_LIT:0> ] ) <EOL> assert_almost_equal ( reference . pvalues , result . _p_value_raw ) <EOL> assert_almost_equal ( reference . rsquared , result . _r2_raw ) <EOL> assert_almost_equal ( reference . rsquared_adj , result . _r2_adj_raw ) <EOL> assert_almost_equal ( reference . resid , result . _resid_raw ) <EOL> assert_almost_equal ( reference . bse , result . _std_err_raw ) <EOL> assert_almost_equal ( reference . tvalues , result . _t_stat_raw ) <EOL> assert_almost_equal ( reference . cov_params ( ) , result . _var_beta_raw ) <EOL> assert_almost_equal ( reference . fittedvalues , result . _y_fitted_raw ) <EOL> _check_non_raw_results ( result ) <EOL> def checkMovingOLS ( self , window_type , x , y , weights = None , ** kwds ) : <EOL> window = np . linalg . matrix_rank ( x . values ) * <NUM_LIT:2> <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> moving = ols ( y = y , x = x , weights = weights , window_type = window_type , <EOL> window = window , ** kwds ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> sparse_moving = ols ( y = y . to_sparse ( ) , x = x . to_sparse ( ) , <EOL> weights = weights , <EOL> window_type = window_type , <EOL> window = window , ** kwds ) <EOL> _compare_ols_results ( moving , sparse_moving ) <EOL> index = moving . _index <EOL> for n , i in enumerate ( moving . _valid_indices ) : <EOL> if window_type == '<STR_LIT>' and i >= window : <EOL> prior_date = index [ i - window + <NUM_LIT:1> ] <EOL> else : <EOL> prior_date = index [ <NUM_LIT:0> ] <EOL> date = index [ i ] <EOL> x_iter = { } <EOL> for k , v in compat . iteritems ( x ) : <EOL> x_iter [ k ] = v . truncate ( before = prior_date , after = date ) <EOL> y_iter = y . truncate ( before = prior_date , after = date ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> static = ols ( y = y_iter , x = x_iter , weights = weights , ** kwds ) <EOL> self . compare ( static , moving , event_index = i , <EOL> result_index = n ) <EOL> _check_non_raw_results ( moving ) <EOL> FIELDS = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> def compare ( self , static , moving , event_index = None , <EOL> result_index = None ) : <EOL> index = moving . _index <EOL> if event_index is not None : <EOL> ref = static . _resid_raw [ - <NUM_LIT:1> ] <EOL> label = index [ event_index ] <EOL> res = moving . resid [ label ] <EOL> assert_almost_equal ( ref , res ) <EOL> ref = static . _y_fitted_raw [ - <NUM_LIT:1> ] <EOL> res = moving . y_fitted [ label ] <EOL> assert_almost_equal ( ref , res ) <EOL> for field in self . FIELDS : <EOL> attr = '<STR_LIT>' % field <EOL> ref = getattr ( static , attr ) <EOL> res = getattr ( moving , attr ) <EOL> if result_index is not None : <EOL> res = res [ result_index ] <EOL> assert_almost_equal ( ref , res ) <EOL> def test_ols_object_dtype ( self ) : <EOL> df = DataFrame ( np . random . randn ( <NUM_LIT:20> , <NUM_LIT:2> ) , dtype = object ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> model = ols ( y = df [ <NUM_LIT:0> ] , x = df [ <NUM_LIT:1> ] ) <EOL> summary = repr ( model ) <EOL> class TestOLSMisc ( tm . TestCase ) : <EOL> _multiprocess_can_split_ = True <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> super ( TestOLSMisc , cls ) . setUpClass ( ) <EOL> if not _have_statsmodels : <EOL> raise nose . SkipTest ( "<STR_LIT>" ) <EOL> def test_f_test ( self ) : <EOL> x = tm . makeTimeDataFrame ( ) <EOL> y = x . pop ( '<STR_LIT:A>' ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> model = ols ( y = y , x = x ) <EOL> hyp = '<STR_LIT>' <EOL> result = model . f_test ( hyp ) <EOL> hyp = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> result = model . f_test ( hyp ) <EOL> assert_almost_equal ( result [ '<STR_LIT>' ] , model . f_stat [ '<STR_LIT>' ] ) <EOL> self . assertRaises ( Exception , model . f_test , '<STR_LIT>' ) <EOL> def test_r2_no_intercept ( self ) : <EOL> y = tm . makeTimeSeries ( ) <EOL> x = tm . makeTimeDataFrame ( ) <EOL> x_with = x . copy ( ) <EOL> x_with [ '<STR_LIT>' ] = <NUM_LIT:1.> <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> model1 = ols ( y = y , x = x ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> model2 = ols ( y = y , x = x_with , intercept = False ) <EOL> assert_series_equal ( model1 . beta , model2 . beta ) <EOL> self . assertNotEqual ( model1 . r2 , model2 . r2 ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> model1 = ols ( y = y , x = x , window = <NUM_LIT:20> ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> model2 = ols ( y = y , x = x_with , window = <NUM_LIT:20> , intercept = False ) <EOL> assert_frame_equal ( model1 . beta , model2 . beta ) <EOL> self . assertTrue ( ( model1 . r2 != model2 . r2 ) . all ( ) ) <EOL> def test_summary_many_terms ( self ) : <EOL> x = DataFrame ( np . random . randn ( <NUM_LIT:100> , <NUM_LIT:20> ) ) <EOL> y = np . random . randn ( <NUM_LIT:100> ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> model = ols ( y = y , x = x ) <EOL> model . summary <EOL> def test_y_predict ( self ) : <EOL> y = tm . makeTimeSeries ( ) <EOL> x = tm . makeTimeDataFrame ( ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> model1 = ols ( y = y , x = x ) <EOL> assert_series_equal ( model1 . y_predict , model1 . y_fitted ) <EOL> assert_almost_equal ( model1 . _y_predict_raw , model1 . _y_fitted_raw ) <EOL> def test_predict ( self ) : <EOL> y = tm . makeTimeSeries ( ) <EOL> x = tm . makeTimeDataFrame ( ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> model1 = ols ( y = y , x = x ) <EOL> assert_series_equal ( model1 . predict ( ) , model1 . y_predict ) <EOL> assert_series_equal ( model1 . predict ( x = x ) , model1 . y_predict ) <EOL> assert_series_equal ( model1 . predict ( beta = model1 . beta ) , model1 . y_predict ) <EOL> exog = x . copy ( ) <EOL> exog [ '<STR_LIT>' ] = <NUM_LIT:1.> <EOL> rs = Series ( np . dot ( exog . values , model1 . beta . values ) , x . index ) <EOL> assert_series_equal ( model1 . y_predict , rs ) <EOL> x2 = x . reindex ( columns = x . columns [ : : - <NUM_LIT:1> ] ) <EOL> assert_series_equal ( model1 . predict ( x = x2 ) , model1 . y_predict ) <EOL> x3 = x2 + <NUM_LIT:10> <EOL> pred3 = model1 . predict ( x = x3 ) <EOL> x3 [ '<STR_LIT>' ] = <NUM_LIT:1.> <EOL> x3 = x3 . reindex ( columns = model1 . beta . index ) <EOL> expected = Series ( np . dot ( x3 . values , model1 . beta . values ) , x3 . index ) <EOL> assert_series_equal ( expected , pred3 ) <EOL> beta = Series ( <NUM_LIT:0.> , model1 . beta . index ) <EOL> pred4 = model1 . predict ( beta = beta ) <EOL> assert_series_equal ( Series ( <NUM_LIT:0.> , pred4 . index ) , pred4 ) <EOL> def test_predict_longer_exog ( self ) : <EOL> exogenous = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } <EOL> endogenous = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } <EOL> endog = Series ( endogenous ) <EOL> exog = Series ( exogenous ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> model = ols ( y = endog , x = exog ) <EOL> pred = model . y_predict <EOL> self . assertTrue ( pred . index . equals ( exog . index ) ) <EOL> def test_longpanel_series_combo ( self ) : <EOL> wp = tm . makePanel ( ) <EOL> lp = wp . to_frame ( ) <EOL> y = lp . pop ( '<STR_LIT>' ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> model = ols ( y = y , x = lp , entity_effects = True , window = <NUM_LIT:20> ) <EOL> self . assertTrue ( notnull ( model . beta . values ) . all ( ) ) <EOL> tm . assertIsInstance ( model , PanelOLS ) <EOL> model . summary <EOL> def test_series_rhs ( self ) : <EOL> y = tm . makeTimeSeries ( ) <EOL> x = tm . makeTimeSeries ( ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> model = ols ( y = y , x = x ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> expected = ols ( y = y , x = { '<STR_LIT:x>' : x } ) <EOL> assert_series_equal ( model . beta , expected . beta ) <EOL> assert_series_equal ( model . y_predict , model . predict ( x = x ) ) <EOL> def test_various_attributes ( self ) : <EOL> x = DataFrame ( np . random . randn ( <NUM_LIT:100> , <NUM_LIT:5> ) ) <EOL> y = np . random . randn ( <NUM_LIT:100> ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> model = ols ( y = y , x = x , window = <NUM_LIT:20> ) <EOL> series_attrs = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for attr in series_attrs : <EOL> value = getattr ( model , attr ) <EOL> tm . assertIsInstance ( value , Series ) <EOL> model . _results <EOL> def test_catch_regressor_overlap ( self ) : <EOL> df1 = tm . makeTimeDataFrame ( ) . ix [ : , [ '<STR_LIT:A>' , '<STR_LIT:B>' ] ] <EOL> df2 = tm . makeTimeDataFrame ( ) . ix [ : , [ '<STR_LIT:B>' , '<STR_LIT:C>' , '<STR_LIT:D>' ] ] <EOL> y = tm . makeTimeSeries ( ) <EOL> data = { '<STR_LIT:foo>' : df1 , '<STR_LIT:bar>' : df2 } <EOL> def f ( ) : <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> ols ( y = y , x = data ) <EOL> self . assertRaises ( Exception , f ) <EOL> def test_plm_ctor ( self ) : <EOL> y = tm . makeTimeDataFrame ( ) <EOL> x = { '<STR_LIT:a>' : tm . makeTimeDataFrame ( ) , <EOL> '<STR_LIT:b>' : tm . makeTimeDataFrame ( ) } <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> model = ols ( y = y , x = x , intercept = False ) <EOL> model . summary <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> model = ols ( y = y , x = Panel ( x ) ) <EOL> model . summary <EOL> def test_plm_attrs ( self ) : <EOL> y = tm . makeTimeDataFrame ( ) <EOL> x = { '<STR_LIT:a>' : tm . makeTimeDataFrame ( ) , <EOL> '<STR_LIT:b>' : tm . makeTimeDataFrame ( ) } <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> rmodel = ols ( y = y , x = x , window = <NUM_LIT:10> ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> model = ols ( y = y , x = x ) <EOL> model . resid <EOL> rmodel . resid <EOL> def test_plm_lagged_y_predict ( self ) : <EOL> y = tm . makeTimeDataFrame ( ) <EOL> x = { '<STR_LIT:a>' : tm . makeTimeDataFrame ( ) , <EOL> '<STR_LIT:b>' : tm . makeTimeDataFrame ( ) } <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> model = ols ( y = y , x = x , window = <NUM_LIT:10> ) <EOL> result = model . lagged_y_predict ( <NUM_LIT:2> ) <EOL> def test_plm_f_test ( self ) : <EOL> y = tm . makeTimeDataFrame ( ) <EOL> x = { '<STR_LIT:a>' : tm . makeTimeDataFrame ( ) , <EOL> '<STR_LIT:b>' : tm . makeTimeDataFrame ( ) } <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> model = ols ( y = y , x = x ) <EOL> hyp = '<STR_LIT>' <EOL> result = model . f_test ( hyp ) <EOL> hyp = [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> result = model . f_test ( hyp ) <EOL> assert_almost_equal ( result [ '<STR_LIT>' ] , model . f_stat [ '<STR_LIT>' ] ) <EOL> def test_plm_exclude_dummy_corner ( self ) : <EOL> y = tm . makeTimeDataFrame ( ) <EOL> x = { '<STR_LIT:a>' : tm . makeTimeDataFrame ( ) , <EOL> '<STR_LIT:b>' : tm . makeTimeDataFrame ( ) } <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> model = ols ( <EOL> y = y , x = x , entity_effects = True , dropped_dummies = { '<STR_LIT>' : '<STR_LIT:D>' } ) <EOL> model . summary <EOL> def f ( ) : <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> ols ( y = y , x = x , entity_effects = True , <EOL> dropped_dummies = { '<STR_LIT>' : '<STR_LIT:E>' } ) <EOL> self . assertRaises ( Exception , f ) <EOL> def test_columns_tuples_summary ( self ) : <EOL> X = DataFrame ( np . random . randn ( <NUM_LIT:10> , <NUM_LIT:2> ) , columns = [ ( '<STR_LIT:a>' , '<STR_LIT:b>' ) , ( '<STR_LIT:c>' , '<STR_LIT:d>' ) ] ) <EOL> Y = Series ( np . random . randn ( <NUM_LIT:10> ) ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> model = ols ( y = Y , x = X ) <EOL> model . summary <EOL> class TestPanelOLS ( BaseTest ) : <EOL> _multiprocess_can_split_ = True <EOL> FIELDS = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> _other_fields = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def testFiltering ( self ) : <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> result = ols ( y = self . panel_y2 , x = self . panel_x2 ) <EOL> x = result . _x <EOL> index = x . index . get_level_values ( <NUM_LIT:0> ) <EOL> index = Index ( sorted ( set ( index ) ) ) <EOL> exp_index = Index ( [ datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:3> ) ] ) <EOL> self . assertTrue <EOL> ( exp_index . equals ( index ) ) <EOL> index = x . index . get_level_values ( <NUM_LIT:1> ) <EOL> index = Index ( sorted ( set ( index ) ) ) <EOL> exp_index = Index ( [ '<STR_LIT:A>' , '<STR_LIT:B>' ] ) <EOL> self . assertTrue ( exp_index . equals ( index ) ) <EOL> x = result . _x_filtered <EOL> index = x . index . get_level_values ( <NUM_LIT:0> ) <EOL> index = Index ( sorted ( set ( index ) ) ) <EOL> exp_index = Index ( [ datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:3> ) , <EOL> datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:4> ) ] ) <EOL> self . assertTrue ( exp_index . equals ( index ) ) <EOL> assert_almost_equal ( result . _y . values . flat , [ <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> ] ) <EOL> exp_x = [ [ <NUM_LIT:6> , <NUM_LIT> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:30> , <NUM_LIT> , <NUM_LIT:1> ] ] <EOL> assert_almost_equal ( exp_x , result . _x . values ) <EOL> exp_x_filtered = [ [ <NUM_LIT:6> , <NUM_LIT> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:30> , <NUM_LIT> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:11> , <NUM_LIT:20> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:1> ] ] <EOL> assert_almost_equal ( exp_x_filtered , result . _x_filtered . values ) <EOL> self . assertTrue ( result . _x_filtered . index . levels [ <NUM_LIT:0> ] . equals ( <EOL> result . y_fitted . index ) ) <EOL> def test_wls_panel ( self ) : <EOL> y = tm . makeTimeDataFrame ( ) <EOL> x = Panel ( { '<STR_LIT>' : tm . makeTimeDataFrame ( ) , <EOL> '<STR_LIT>' : tm . makeTimeDataFrame ( ) } ) <EOL> y . ix [ [ <NUM_LIT:1> , <NUM_LIT:7> ] , '<STR_LIT:A>' ] = np . nan <EOL> y . ix [ [ <NUM_LIT:6> , <NUM_LIT:15> ] , '<STR_LIT:B>' ] = np . nan <EOL> y . ix [ [ <NUM_LIT:3> , <NUM_LIT:20> ] , '<STR_LIT:C>' ] = np . nan <EOL> y . ix [ [ <NUM_LIT:5> , <NUM_LIT:11> ] , '<STR_LIT:D>' ] = np . nan <EOL> stack_y = y . stack ( ) <EOL> stack_x = DataFrame ( dict ( ( k , v . stack ( ) ) <EOL> for k , v in x . iteritems ( ) ) ) <EOL> weights = x . std ( '<STR_LIT>' ) <EOL> stack_weights = weights . stack ( ) <EOL> stack_y . index = stack_y . index . _tuple_index <EOL> stack_x . index = stack_x . index . _tuple_index <EOL> stack_weights . index = stack_weights . index . _tuple_index <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> result = ols ( y = y , x = x , weights = <NUM_LIT:1> / weights ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> expected = ols ( y = stack_y , x = stack_x , weights = <NUM_LIT:1> / stack_weights ) <EOL> assert_almost_equal ( result . beta , expected . beta ) <EOL> for attr in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> rvals = getattr ( result , attr ) . stack ( ) . values <EOL> evals = getattr ( expected , attr ) . values <EOL> assert_almost_equal ( rvals , evals ) <EOL> def testWithTimeEffects ( self ) : <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> result = ols ( y = self . panel_y2 , x = self . panel_x2 , time_effects = True ) <EOL> assert_almost_equal ( result . _y_trans . values . flat , [ <NUM_LIT:0> , - <NUM_LIT:0.5> , <NUM_LIT:0.5> ] ) <EOL> exp_x = [ [ <NUM_LIT:0> , <NUM_LIT:0> ] , [ - <NUM_LIT> , - <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> ] ] <EOL> assert_almost_equal ( result . _x_trans . values , exp_x ) <EOL> def testWithEntityEffects ( self ) : <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> result = ols ( y = self . panel_y2 , x = self . panel_x2 , entity_effects = True ) <EOL> assert_almost_equal ( result . _y . values . flat , [ <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> ] ) <EOL> exp_x = DataFrame ( [ [ <NUM_LIT:0.> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.> ] , [ <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:1> ] , [ <NUM_LIT:1> , <NUM_LIT:30> , <NUM_LIT> , <NUM_LIT:1> ] ] , <EOL> index = result . _x . index , columns = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> dtype = float ) <EOL> tm . assert_frame_equal ( result . _x , exp_x . ix [ : , result . _x . columns ] ) <EOL> def testWithEntityEffectsAndDroppedDummies ( self ) : <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> result = ols ( y = self . panel_y2 , x = self . panel_x2 , entity_effects = True , <EOL> dropped_dummies = { '<STR_LIT>' : '<STR_LIT:B>' } ) <EOL> assert_almost_equal ( result . _y . values . flat , [ <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> ] ) <EOL> exp_x = DataFrame ( [ [ <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.> ] , [ <NUM_LIT:1> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:1> ] , [ <NUM_LIT:0> , <NUM_LIT:30> , <NUM_LIT> , <NUM_LIT:1> ] ] , <EOL> index = result . _x . index , columns = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> dtype = float ) <EOL> tm . assert_frame_equal ( result . _x , exp_x . ix [ : , result . _x . columns ] ) <EOL> def testWithXEffects ( self ) : <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> result = ols ( y = self . panel_y2 , x = self . panel_x2 , x_effects = [ '<STR_LIT>' ] ) <EOL> assert_almost_equal ( result . _y . values . flat , [ <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> ] ) <EOL> res = result . _x <EOL> exp_x = DataFrame ( [ [ <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT> , <NUM_LIT:1.> ] , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:1> ] , [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:1> ] ] , <EOL> columns = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> index = res . index , dtype = float ) <EOL> assert_frame_equal ( res , exp_x . reindex ( columns = res . columns ) ) <EOL> def testWithXEffectsAndDroppedDummies ( self ) : <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> result = ols ( y = self . panel_y2 , x = self . panel_x2 , x_effects = [ '<STR_LIT>' ] , <EOL> dropped_dummies = { '<STR_LIT>' : <NUM_LIT:30> } ) <EOL> res = result . _x <EOL> assert_almost_equal ( result . _y . values . flat , [ <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> ] ) <EOL> exp_x = DataFrame ( [ [ <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT> , <NUM_LIT:1.> ] , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:1> ] , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:1> ] ] , <EOL> columns = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> index = res . index , dtype = float ) <EOL> assert_frame_equal ( res , exp_x . reindex ( columns = res . columns ) ) <EOL> def testWithXEffectsAndConversion ( self ) : <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> result = ols ( y = self . panel_y3 , x = self . panel_x3 , <EOL> x_effects = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> assert_almost_equal ( result . _y . values . flat , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> exp_x = [ [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ] , [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ] ] <EOL> assert_almost_equal ( result . _x . values , exp_x ) <EOL> exp_index = Index ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( exp_index . equals ( result . _x . columns ) ) <EOL> def testWithXEffectsAndConversionAndDroppedDummies ( self ) : <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> result = ols ( y = self . panel_y3 , x = self . panel_x3 , x_effects = [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> dropped_dummies = { '<STR_LIT>' : '<STR_LIT:foo>' } ) <EOL> assert_almost_equal ( result . _y . values . flat , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> exp_x = [ [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] ] <EOL> assert_almost_equal ( result . _x . values , exp_x ) <EOL> exp_index = Index ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( exp_index . equals ( result . _x . columns ) ) <EOL> def testForSeries ( self ) : <EOL> self . checkForSeries ( self . series_panel_x , self . series_panel_y , <EOL> self . series_x , self . series_y ) <EOL> self . checkForSeries ( self . series_panel_x , self . series_panel_y , <EOL> self . series_x , self . series_y , nw_lags = <NUM_LIT:0> ) <EOL> self . checkForSeries ( self . series_panel_x , self . series_panel_y , <EOL> self . series_x , self . series_y , nw_lags = <NUM_LIT:1> , <EOL> nw_overlap = True ) <EOL> def testRolling ( self ) : <EOL> self . checkMovingOLS ( self . panel_x , self . panel_y ) <EOL> def testRollingWithFixedEffects ( self ) : <EOL> self . checkMovingOLS ( self . panel_x , self . panel_y , <EOL> entity_effects = True ) <EOL> self . checkMovingOLS ( self . panel_x , self . panel_y , intercept = False , <EOL> entity_effects = True ) <EOL> def testRollingWithTimeEffects ( self ) : <EOL> self . checkMovingOLS ( self . panel_x , self . panel_y , <EOL> time_effects = True ) <EOL> def testRollingWithNeweyWest ( self ) : <EOL> self . checkMovingOLS ( self . panel_x , self . panel_y , <EOL> nw_lags = <NUM_LIT:1> ) <EOL> def testRollingWithEntityCluster ( self ) : <EOL> self . checkMovingOLS ( self . panel_x , self . panel_y , <EOL> cluster = '<STR_LIT>' ) <EOL> def testUnknownClusterRaisesValueError ( self ) : <EOL> assertRaisesRegexp ( ValueError , "<STR_LIT>" , <EOL> self . checkMovingOLS , self . panel_x , self . panel_y , <EOL> cluster = '<STR_LIT>' ) <EOL> def testRollingWithTimeEffectsAndEntityCluster ( self ) : <EOL> self . checkMovingOLS ( self . panel_x , self . panel_y , <EOL> time_effects = True , cluster = '<STR_LIT>' ) <EOL> def testRollingWithTimeCluster ( self ) : <EOL> self . checkMovingOLS ( self . panel_x , self . panel_y , <EOL> cluster = '<STR_LIT:time>' ) <EOL> def testRollingWithNeweyWestAndEntityCluster ( self ) : <EOL> self . assertRaises ( ValueError , self . checkMovingOLS , <EOL> self . panel_x , self . panel_y , <EOL> nw_lags = <NUM_LIT:1> , cluster = '<STR_LIT>' ) <EOL> def testRollingWithNeweyWestAndTimeEffectsAndEntityCluster ( self ) : <EOL> self . assertRaises ( ValueError , <EOL> self . checkMovingOLS , self . panel_x , self . panel_y , <EOL> nw_lags = <NUM_LIT:1> , cluster = '<STR_LIT>' , <EOL> time_effects = True ) <EOL> def testExpanding ( self ) : <EOL> self . checkMovingOLS ( <EOL> self . panel_x , self . panel_y , window_type = '<STR_LIT>' ) <EOL> def testNonPooled ( self ) : <EOL> self . checkNonPooled ( y = self . panel_y , x = self . panel_x ) <EOL> self . checkNonPooled ( y = self . panel_y , x = self . panel_x , <EOL> window_type = '<STR_LIT>' , window = <NUM_LIT> , min_periods = <NUM_LIT:10> ) <EOL> def testUnknownWindowType ( self ) : <EOL> assertRaisesRegexp ( ValueError , "<STR_LIT>" , <EOL> self . checkNonPooled , y = self . panel_y , x = self . panel_x , <EOL> window_type = '<STR_LIT>' , window = <NUM_LIT> , min_periods = <NUM_LIT:10> ) <EOL> def checkNonPooled ( self , x , y , ** kwds ) : <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> result = ols ( y = y , x = x , pool = False , ** kwds ) <EOL> _check_repr ( result ) <EOL> for attr in NonPooledPanelOLS . ATTRIBUTES : <EOL> _check_repr ( getattr ( result , attr ) ) <EOL> def checkMovingOLS ( self , x , y , window_type = '<STR_LIT>' , ** kwds ) : <EOL> window = <NUM_LIT> <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> moving = ols ( y = y , x = x , window_type = window_type , <EOL> window = window , ** kwds ) <EOL> index = moving . _index <EOL> for n , i in enumerate ( moving . _valid_indices ) : <EOL> if window_type == '<STR_LIT>' and i >= window : <EOL> prior_date = index [ i - window + <NUM_LIT:1> ] <EOL> else : <EOL> prior_date = index [ <NUM_LIT:0> ] <EOL> date = index [ i ] <EOL> x_iter = { } <EOL> for k , v in compat . iteritems ( x ) : <EOL> x_iter [ k ] = v . truncate ( before = prior_date , after = date ) <EOL> y_iter = y . truncate ( before = prior_date , after = date ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> static = ols ( y = y_iter , x = x_iter , ** kwds ) <EOL> self . compare ( static , moving , event_index = i , <EOL> result_index = n ) <EOL> _check_non_raw_results ( moving ) <EOL> def checkForSeries ( self , x , y , series_x , series_y , ** kwds ) : <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> result = ols ( y = y , x = x , ** kwds ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> reference = ols ( y = series_y , x = series_x , ** kwds ) <EOL> self . compare ( reference , result ) <EOL> def compare ( self , static , moving , event_index = None , <EOL> result_index = None ) : <EOL> if event_index is not None : <EOL> staticSlice = _period_slice ( static , - <NUM_LIT:1> ) <EOL> movingSlice = _period_slice ( moving , event_index ) <EOL> ref = static . _resid_raw [ staticSlice ] <EOL> res = moving . _resid_raw [ movingSlice ] <EOL> assert_almost_equal ( ref , res ) <EOL> ref = static . _y_fitted_raw [ staticSlice ] <EOL> res = moving . _y_fitted_raw [ movingSlice ] <EOL> assert_almost_equal ( ref , res ) <EOL> for field in self . FIELDS : <EOL> attr = '<STR_LIT>' % field <EOL> ref = getattr ( static , attr ) <EOL> res = getattr ( moving , attr ) <EOL> if result_index is not None : <EOL> res = res [ result_index ] <EOL> assert_almost_equal ( ref , res ) <EOL> def test_auto_rolling_window_type ( self ) : <EOL> data = tm . makeTimeDataFrame ( ) <EOL> y = data . pop ( '<STR_LIT:A>' ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> window_model = ols ( y = y , x = data , window = <NUM_LIT:20> , min_periods = <NUM_LIT:10> ) <EOL> with tm . assert_produces_warning ( FutureWarning , check_stacklevel = False ) : <EOL> rolling_model = ols ( y = y , x = data , window = <NUM_LIT:20> , min_periods = <NUM_LIT:10> , <EOL> window_type = '<STR_LIT>' ) <EOL> assert_frame_equal ( window_model . beta , rolling_model . beta ) <EOL> def test_group_agg ( self ) : <EOL> from pandas . stats . plm import _group_agg <EOL> values = np . ones ( ( <NUM_LIT:10> , <NUM_LIT:2> ) ) * np . arange ( <NUM_LIT:10> ) . reshape ( ( <NUM_LIT:10> , <NUM_LIT:1> ) ) <EOL> bounds = np . arange ( <NUM_LIT:5> ) * <NUM_LIT:2> <EOL> f = lambda x : x . mean ( axis = <NUM_LIT:0> ) <EOL> agged = _group_agg ( values , bounds , f ) <EOL> assert ( agged [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] == <NUM_LIT> ) <EOL> assert ( agged [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] == <NUM_LIT> ) <EOL> f2 = lambda x : np . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> self . assertRaises ( Exception , _group_agg , values , bounds , f2 ) <EOL> def _check_non_raw_results ( model ) : <EOL> _check_repr ( model ) <EOL> _check_repr ( model . resid ) <EOL> _check_repr ( model . summary_as_matrix ) <EOL> _check_repr ( model . y_fitted ) <EOL> _check_repr ( model . y_predict ) <EOL> def _period_slice ( panelModel , i ) : <EOL> index = panelModel . _x_trans . index <EOL> period = index . levels [ <NUM_LIT:0> ] [ i ] <EOL> L , R = index . get_major_bounds ( period , period ) <EOL> return slice ( L , R ) <EOL> class TestOLSFilter ( tm . TestCase ) : <EOL> _multiprocess_can_split_ = True <EOL> def setUp ( self ) : <EOL> date_index = date_range ( datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:11> ) , periods = <NUM_LIT:3> , <EOL> freq = datetools . bday ) <EOL> ts = Series ( [ <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:4> ] , index = date_index ) <EOL> self . TS1 = ts <EOL> date_index = date_range ( datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:11> ) , periods = <NUM_LIT:5> , <EOL> freq = datetools . bday ) <EOL> ts = Series ( [ <NUM_LIT:1> , <NUM_LIT:5> , <NUM_LIT:9> , <NUM_LIT:2> , <NUM_LIT:6> ] , index = date_index ) <EOL> self . TS2 = ts <EOL> date_index = date_range ( datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:11> ) , periods = <NUM_LIT:3> , <EOL> freq = datetools . bday ) <EOL> ts = Series ( [ <NUM_LIT:5> , np . nan , <NUM_LIT:3> ] , index = date_index ) <EOL> self . TS3 = ts <EOL> date_index = date_range ( datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:11> ) , periods = <NUM_LIT:5> , <EOL> freq = datetools . bday ) <EOL> ts = Series ( [ np . nan , <NUM_LIT:5> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:7> ] , index = date_index ) <EOL> self . TS4 = ts <EOL> data = { '<STR_LIT>' : self . TS2 , '<STR_LIT>' : self . TS4 } <EOL> self . DF1 = DataFrame ( data = data ) <EOL> data = { '<STR_LIT>' : self . TS2 , '<STR_LIT>' : self . TS4 } <EOL> self . DICT1 = data <EOL> def testFilterWithSeriesRHS ( self ) : <EOL> ( lhs , rhs , weights , rhs_pre , <EOL> index , valid ) = _filter_data ( self . TS1 , { '<STR_LIT>' : self . TS2 } , None ) <EOL> self . tsAssertEqual ( self . TS1 , lhs ) <EOL> self . tsAssertEqual ( self . TS2 [ : <NUM_LIT:3> ] , rhs [ '<STR_LIT>' ] ) <EOL> self . tsAssertEqual ( self . TS2 , rhs_pre [ '<STR_LIT>' ] ) <EOL> def testFilterWithSeriesRHS2 ( self ) : <EOL> ( lhs , rhs , weights , rhs_pre , <EOL> index , valid ) = _filter_data ( self . TS2 , { '<STR_LIT>' : self . TS1 } , None ) <EOL> self . tsAssertEqual ( self . TS2 [ : <NUM_LIT:3> ] , lhs ) <EOL> self . tsAssertEqual ( self . TS1 , rhs [ '<STR_LIT>' ] ) <EOL> self . tsAssertEqual ( self . TS1 , rhs_pre [ '<STR_LIT>' ] ) <EOL> def testFilterWithSeriesRHS3 ( self ) : <EOL> ( lhs , rhs , weights , rhs_pre , <EOL> index , valid ) = _filter_data ( self . TS3 , { '<STR_LIT>' : self . TS4 } , None ) <EOL> exp_lhs = self . TS3 [ <NUM_LIT:2> : <NUM_LIT:3> ] <EOL> exp_rhs = self . TS4 [ <NUM_LIT:2> : <NUM_LIT:3> ] <EOL> exp_rhs_pre = self . TS4 [ <NUM_LIT:1> : ] <EOL> self . tsAssertEqual ( exp_lhs , lhs ) <EOL> self . tsAssertEqual ( exp_rhs , rhs [ '<STR_LIT>' ] ) <EOL> self . tsAssertEqual ( exp_rhs_pre , rhs_pre [ '<STR_LIT>' ] ) <EOL> def testFilterWithDataFrameRHS ( self ) : <EOL> ( lhs , rhs , weights , rhs_pre , <EOL> index , valid ) = _filter_data ( self . TS1 , self . DF1 , None ) <EOL> exp_lhs = self . TS1 [ <NUM_LIT:1> : ] <EOL> exp_rhs1 = self . TS2 [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> exp_rhs2 = self . TS4 [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> self . tsAssertEqual ( exp_lhs , lhs ) <EOL> self . tsAssertEqual ( exp_rhs1 , rhs [ '<STR_LIT>' ] ) <EOL> self . tsAssertEqual ( exp_rhs2 , rhs [ '<STR_LIT>' ] ) <EOL> def testFilterWithDictRHS ( self ) : <EOL> ( lhs , rhs , weights , rhs_pre , <EOL> index , valid ) = _filter_data ( self . TS1 , self . DICT1 , None ) <EOL> exp_lhs = self . TS1 [ <NUM_LIT:1> : ] <EOL> exp_rhs1 = self . TS2 [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> exp_rhs2 = self . TS4 [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> self . tsAssertEqual ( exp_lhs , lhs ) <EOL> self . tsAssertEqual ( exp_rhs1 , rhs [ '<STR_LIT>' ] ) <EOL> self . tsAssertEqual ( exp_rhs2 , rhs [ '<STR_LIT>' ] ) <EOL> def tsAssertEqual ( self , ts1 , ts2 ) : <EOL> self . assert_numpy_array_equal ( ts1 , ts2 ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import nose <EOL> nose . runmodule ( argv = [ __file__ , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> exit = False ) </s>
