@@ -31,7 +31,7 @@ def assert_full_rank(m):
31
31
u , s , v = np .linalg .svd (m )
32
32
rank = np .sum (s > 1e-10 )
33
33
assert rank == m .shape [1 ]
34
-
34
+
35
35
def test_assert_full_rank ():
36
36
assert_full_rank (np .eye (10 ))
37
37
assert_full_rank ([[1 , 0 ], [1 , 0 ], [1 , 0 ], [1 , 1 ]])
@@ -44,7 +44,7 @@ def test_assert_full_rank():
44
44
# col1 + col2 = col3
45
45
assert_raises (AssertionError ,
46
46
assert_full_rank , [[1 , 2 , 3 ], [1 , 5 , 6 ], [1 , 6 , 7 ]])
47
-
47
+
48
48
def make_termlist (* entries ):
49
49
terms = []
50
50
for entry in entries :
@@ -116,11 +116,11 @@ def test_simple():
116
116
[1 , 0 , x1 [1 ], 0 ],
117
117
[0 , 1 , x1 [2 ], x1 [2 ]],
118
118
[0 , 1 , x1 [3 ], x1 [3 ]]])
119
-
119
+
120
120
m = make_matrix (data , 3 , [["x1" ], ["x2" ], ["x2" , "x1" ]],
121
121
column_names = ["x1" , "x2" , "x2:x1" ])
122
122
assert np .allclose (m , np .column_stack ((x1 , x2 , x1 * x2 )))
123
-
123
+
124
124
def test_R_bugs ():
125
125
data = balanced (a = 2 , b = 2 , c = 2 )
126
126
data ["x" ] = np .linspace (0 , 1 , len (data ["a" ]))
@@ -253,7 +253,7 @@ def test_return_type():
253
253
def iter_maker ():
254
254
yield data
255
255
builder = design_matrix_builders ([make_termlist ("x" )], iter_maker , 0 )[0 ]
256
-
256
+
257
257
# Check explicitly passing return_type="matrix" works
258
258
mat = build_design_matrices ([builder ], data , return_type = "matrix" )[0 ]
259
259
assert isinstance (mat , DesignMatrix )
@@ -298,7 +298,7 @@ def iter_maker():
298
298
assert mat .shape == (2 , 3 )
299
299
# According to this (and only this) function, NaN == NaN.
300
300
np .testing .assert_array_equal (mat , [[1.0 , 0.0 , 10.0 ], [0.0 , 1.0 , np .nan ]])
301
-
301
+
302
302
# NA_action="raise"
303
303
assert_raises (PatsyError ,
304
304
build_design_matrices ,
@@ -596,7 +596,7 @@ def iter_maker():
596
596
def test_contrast ():
597
597
from patsy .contrasts import ContrastMatrix , Sum
598
598
values = ["a1" , "a3" , "a1" , "a2" ]
599
-
599
+
600
600
# No intercept in model, full-rank coding of 'a'
601
601
m = make_matrix ({"a" : C (values )}, 3 , [["a" ]],
602
602
column_names = ["a[a1]" , "a[a2]" , "a[a3]" ])
@@ -605,7 +605,7 @@ def test_contrast():
605
605
[0 , 0 , 1 ],
606
606
[1 , 0 , 0 ],
607
607
[0 , 1 , 0 ]])
608
-
608
+
609
609
for s in (Sum , Sum ()):
610
610
m = make_matrix ({"a" : C (values , s )}, 3 , [["a" ]],
611
611
column_names = ["a[mean]" , "a[S.a1]" , "a[S.a2]" ])
@@ -614,7 +614,7 @@ def test_contrast():
614
614
[1 ,- 1 , - 1 ],
615
615
[1 , 1 , 0 ],
616
616
[1 , 0 , 1 ]])
617
-
617
+
618
618
m = make_matrix ({"a" : C (values , Sum (omit = 0 ))}, 3 , [["a" ]],
619
619
column_names = ["a[mean]" , "a[S.a2]" , "a[S.a3]" ])
620
620
# Output from R
@@ -631,7 +631,7 @@ def test_contrast():
631
631
[1 , 0 , 1 ],
632
632
[1 , 0 , 0 ],
633
633
[1 , 1 , 0 ]])
634
-
634
+
635
635
for s in (Sum , Sum ()):
636
636
m = make_matrix ({"a" : C (values , s )}, 3 , [[], ["a" ]],
637
637
column_names = ["Intercept" , "a[S.a1]" , "a[S.a2]" ])
@@ -640,7 +640,7 @@ def test_contrast():
640
640
[1 ,- 1 , - 1 ],
641
641
[1 , 1 , 0 ],
642
642
[1 , 0 , 1 ]])
643
-
643
+
644
644
m = make_matrix ({"a" : C (values , Sum (omit = 0 ))}, 3 , [[], ["a" ]],
645
645
column_names = ["Intercept" , "a[S.a2]" , "a[S.a3]" ])
646
646
# Output from R
@@ -747,9 +747,9 @@ def test_safe_data_maker():
747
747
if not have_pandas :
748
748
return
749
749
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 ]})
753
753
754
754
def iter_maker ():
755
755
for i in range (0 , 3 , 2 ):
@@ -758,7 +758,7 @@ def iter_maker():
758
758
d2 = next (d )
759
759
assert_frame_equal (d2 , data .iloc [:2 ])
760
760
d2 = next (d )
761
- assert_frame_equal (d2 , data .iloc [2 :])
761
+ assert_frame_equal (d2 , data .iloc [2 : 4 ])
762
762
763
763
def iter_maker (var_names ):
764
764
for i in range (0 , 3 , 2 ):
@@ -767,4 +767,4 @@ def iter_maker(var_names):
767
767
d2 = next (d )
768
768
assert_frame_equal (d2 , data [['a' , 'b' ]].iloc [:2 ])
769
769
d2 = next (d )
770
- assert_frame_equal (d2 , data [['a' , 'b' ]].iloc [2 :])
770
+ assert_frame_equal (d2 , data [['a' , 'b' ]].iloc [2 : 4 ])
0 commit comments