@@ -2075,41 +2075,42 @@ def test_clip_with_na_args(self):
2075
2075
self .frame )
2076
2076
2077
2077
# Matrix-like
2078
-
2078
+ @ pytest . mark . parametrize ( 'dot_fn' , [ DataFrame . dot , DataFrame . __matmul__ ])
2079
2079
def test_dot (self ):
2080
+ # __matmul__ test is for GH #10259
2080
2081
a = DataFrame (np .random .randn (3 , 4 ), index = ['a' , 'b' , 'c' ],
2081
2082
columns = ['p' , 'q' , 'r' , 's' ])
2082
2083
b = DataFrame (np .random .randn (4 , 2 ), index = ['p' , 'q' , 'r' , 's' ],
2083
2084
columns = ['one' , 'two' ])
2084
2085
2085
- result = a . dot ( b )
2086
+ result = dot_fn ( a , b )
2086
2087
expected = DataFrame (np .dot (a .values , b .values ),
2087
2088
index = ['a' , 'b' , 'c' ],
2088
2089
columns = ['one' , 'two' ])
2089
2090
# Check alignment
2090
2091
b1 = b .reindex (index = reversed (b .index ))
2091
- result = a . dot ( b )
2092
+ result = dot_fn ( a , b )
2092
2093
tm .assert_frame_equal (result , expected )
2093
2094
2094
2095
# Check series argument
2095
- result = a . dot ( b ['one' ])
2096
+ result = dot_fn ( a , b ['one' ])
2096
2097
tm .assert_series_equal (result , expected ['one' ], check_names = False )
2097
2098
assert result .name is None
2098
2099
2099
- result = a . dot ( b1 ['one' ])
2100
+ result = dot_fn ( a , b1 ['one' ])
2100
2101
tm .assert_series_equal (result , expected ['one' ], check_names = False )
2101
2102
assert result .name is None
2102
2103
2103
2104
# can pass correct-length arrays
2104
2105
row = a .iloc [0 ].values
2105
2106
2106
- result = a . dot ( row )
2107
- exp = a . dot ( a .iloc [0 ])
2107
+ result = dot_fn ( a , row )
2108
+ exp = dot_fn ( a , a .iloc [0 ])
2108
2109
tm .assert_series_equal (result , exp )
2109
2110
2110
2111
with tm .assert_raises_regex (ValueError ,
2111
2112
'Dot product shape mismatch' ):
2112
- a . dot ( row [:- 1 ])
2113
+ dot_fn ( a , row [:- 1 ])
2113
2114
2114
2115
a = np .random .rand (1 , 5 )
2115
2116
b = np .random .rand (5 , 1 )
@@ -2119,14 +2120,14 @@ def test_dot(self):
2119
2120
B = DataFrame (b ) # noqa
2120
2121
2121
2122
# it works
2122
- result = A . dot ( b )
2123
+ result = dot_fn ( A , b )
2123
2124
2124
2125
# unaligned
2125
2126
df = DataFrame (randn (3 , 4 ), index = [1 , 2 , 3 ], columns = lrange (4 ))
2126
2127
df2 = DataFrame (randn (5 , 3 ), index = lrange (5 ), columns = [1 , 2 , 3 ])
2127
2128
2128
2129
with tm .assert_raises_regex (ValueError , 'aligned' ):
2129
- df . dot ( df2 )
2130
+ dot_fn ( df , df2 )
2130
2131
2131
2132
2132
2133
@pytest .fixture
0 commit comments