def _filter_data(lhs, rhs):
 def _has_all_columns(df):
  return (np.isfinite(df.values).sum(1) == len(df.columns))
 rhs_valid = _has_all_columns(rhs)
 if (not rhs_valid.all()):
  pre_filtered_rhs = rhs[rhs_valid]
 else:
  pre_filtered_rhs = rhs
 index = lhs.index.union(rhs.index)
 if ((not index.equals(rhs.index)) or (not index.equals(lhs.index))):
  rhs = rhs.reindex(index)
  lhs = lhs.reindex(index)
  rhs_valid = _has_all_columns(rhs)
 lhs_valid = _has_all_columns(lhs)
 valid = (rhs_valid & lhs_valid)
 if (not valid.all()):
  filt_index = rhs.index[valid]
  filtered_rhs = rhs.reindex(filt_index)
  filtered_lhs = lhs.reindex(filt_index)
 else:
  (filtered_rhs, filtered_lhs) = (rhs, lhs)
 return (filtered_lhs, filtered_rhs, pre_filtered_rhs, index, valid)

def _filter_data ( lhs , rhs ) : def _has_all_columns ( df ) : return ( np . isfinite ( df . values ) . sum ( 1 ) == len ( df . columns ) ) rhs_valid = _has_all_columns ( rhs ) if ( not rhs_valid . all ( ) ) : pre_filtered_rhs = rhs [ rhs_valid ] else : pre_filtered_rhs = rhs index = lhs . index . union ( rhs . index ) if ( ( not index . equals ( rhs . index ) ) or ( not index . equals ( lhs . index ) ) ) : rhs = rhs . reindex ( index ) lhs = lhs . reindex ( index ) rhs_valid = _has_all_columns ( rhs ) lhs_valid = _has_all_columns ( lhs ) valid = ( rhs_valid & lhs_valid ) if ( not valid . all ( ) ) : filt_index = rhs . index [ valid ] filtered_rhs = rhs . reindex ( filt_index ) filtered_lhs = lhs . reindex ( filt_index ) else : ( filtered_rhs , filtered_lhs ) = ( rhs , lhs ) return ( filtered_lhs , filtered_rhs , pre_filtered_rhs , index , valid )
data filtering routine for dynamic var lhs : dataframe original data rhs : dataframe lagged variables returns .