@@ -31,7 +31,7 @@ def assert_full_rank(m):
3131 u , s , v = np .linalg .svd (m )
3232 rank = np .sum (s > 1e-10 )
3333 assert rank == m .shape [1 ]
34-
34+
3535def test_assert_full_rank ():
3636 assert_full_rank (np .eye (10 ))
3737 assert_full_rank ([[1 , 0 ], [1 , 0 ], [1 , 0 ], [1 , 1 ]])
@@ -44,7 +44,7 @@ def test_assert_full_rank():
4444 # col1 + col2 = col3
4545 assert_raises (AssertionError ,
4646 assert_full_rank , [[1 , 2 , 3 ], [1 , 5 , 6 ], [1 , 6 , 7 ]])
47-
47+
4848def make_termlist (* entries ):
4949 terms = []
5050 for entry in entries :
@@ -116,11 +116,11 @@ def test_simple():
116116 [1 , 0 , x1 [1 ], 0 ],
117117 [0 , 1 , x1 [2 ], x1 [2 ]],
118118 [0 , 1 , x1 [3 ], x1 [3 ]]])
119-
119+
120120 m = make_matrix (data , 3 , [["x1" ], ["x2" ], ["x2" , "x1" ]],
121121 column_names = ["x1" , "x2" , "x2:x1" ])
122122 assert np .allclose (m , np .column_stack ((x1 , x2 , x1 * x2 )))
123-
123+
124124def test_R_bugs ():
125125 data = balanced (a = 2 , b = 2 , c = 2 )
126126 data ["x" ] = np .linspace (0 , 1 , len (data ["a" ]))
@@ -253,7 +253,7 @@ def test_return_type():
253253 def iter_maker ():
254254 yield data
255255 builder = design_matrix_builders ([make_termlist ("x" )], iter_maker , 0 )[0 ]
256-
256+
257257 # Check explicitly passing return_type="matrix" works
258258 mat = build_design_matrices ([builder ], data , return_type = "matrix" )[0 ]
259259 assert isinstance (mat , DesignMatrix )
@@ -298,7 +298,7 @@ def iter_maker():
298298 assert mat .shape == (2 , 3 )
299299 # According to this (and only this) function, NaN == NaN.
300300 np .testing .assert_array_equal (mat , [[1.0 , 0.0 , 10.0 ], [0.0 , 1.0 , np .nan ]])
301-
301+
302302 # NA_action="raise"
303303 assert_raises (PatsyError ,
304304 build_design_matrices ,
@@ -596,7 +596,7 @@ def iter_maker():
596596def test_contrast ():
597597 from patsy .contrasts import ContrastMatrix , Sum
598598 values = ["a1" , "a3" , "a1" , "a2" ]
599-
599+
600600 # No intercept in model, full-rank coding of 'a'
601601 m = make_matrix ({"a" : C (values )}, 3 , [["a" ]],
602602 column_names = ["a[a1]" , "a[a2]" , "a[a3]" ])
@@ -605,7 +605,7 @@ def test_contrast():
605605 [0 , 0 , 1 ],
606606 [1 , 0 , 0 ],
607607 [0 , 1 , 0 ]])
608-
608+
609609 for s in (Sum , Sum ()):
610610 m = make_matrix ({"a" : C (values , s )}, 3 , [["a" ]],
611611 column_names = ["a[mean]" , "a[S.a1]" , "a[S.a2]" ])
@@ -614,7 +614,7 @@ def test_contrast():
614614 [1 ,- 1 , - 1 ],
615615 [1 , 1 , 0 ],
616616 [1 , 0 , 1 ]])
617-
617+
618618 m = make_matrix ({"a" : C (values , Sum (omit = 0 ))}, 3 , [["a" ]],
619619 column_names = ["a[mean]" , "a[S.a2]" , "a[S.a3]" ])
620620 # Output from R
@@ -631,7 +631,7 @@ def test_contrast():
631631 [1 , 0 , 1 ],
632632 [1 , 0 , 0 ],
633633 [1 , 1 , 0 ]])
634-
634+
635635 for s in (Sum , Sum ()):
636636 m = make_matrix ({"a" : C (values , s )}, 3 , [[], ["a" ]],
637637 column_names = ["Intercept" , "a[S.a1]" , "a[S.a2]" ])
@@ -640,7 +640,7 @@ def test_contrast():
640640 [1 ,- 1 , - 1 ],
641641 [1 , 1 , 0 ],
642642 [1 , 0 , 1 ]])
643-
643+
644644 m = make_matrix ({"a" : C (values , Sum (omit = 0 ))}, 3 , [[], ["a" ]],
645645 column_names = ["Intercept" , "a[S.a2]" , "a[S.a3]" ])
646646 # Output from R
@@ -747,24 +747,24 @@ def test_safe_data_maker():
747747 if not have_pandas :
748748 return
749749 from pandas .util .testing import assert_frame_equal
750- data = pandas .DataFrame ({'a' : [1 , 2 , 3 ],
751- 'b' : [4 , 5 , 6 ],
752- 'c' : [7 , 8 , 9 ]})
750+ data = pandas .DataFrame ({'a' : [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ],
751+ 'b' : [4 , 5 , 6 , 7 , 8 , 9 , 1 , 2 , 3 ],
752+ 'c' : [7 , 8 , 9 , 1 , 2 , 3 , 4 , 5 , 6 ]})
753753
754754 def iter_maker ():
755- for i in range ( 0 , 3 , 2 ):
756- yield data .iloc [i : i + 2 ]
755+ yield data . iloc [: 4 ]
756+ yield data .iloc [4 : ]
757757 d = safe_data_maker (iter_maker , ['a' , 'b' ])
758758 d2 = next (d )
759- assert_frame_equal (d2 , data .iloc [:2 ])
759+ assert_frame_equal (d2 , data .iloc [:4 ])
760760 d2 = next (d )
761- assert_frame_equal (d2 , data .iloc [2 :])
761+ assert_frame_equal (d2 , data .iloc [4 :])
762762
763- def iter_maker (var_names ):
764- for i in range ( 0 , 3 , 2 ):
765- yield data [var_names ].iloc [i : i + 2 ]
763+ def iter_maker (varnames ):
764+ yield data [ varnames ]. iloc [: 4 ]
765+ yield data [varnames ].iloc [4 : ]
766766 d = safe_data_maker (iter_maker , ['a' , 'b' ])
767767 d2 = next (d )
768- assert_frame_equal (d2 , data [['a' , 'b' ]].iloc [:2 ])
768+ assert_frame_equal (d2 , data [['a' , 'b' ]].iloc [:4 ])
769769 d2 = next (d )
770- assert_frame_equal (d2 , data [['a' , 'b' ]].iloc [2 :])
770+ assert_frame_equal (d2 , data [['a' , 'b' ]].iloc [4 :])
0 commit comments