@@ -2014,41 +2014,42 @@ def test_clip_with_na_args(self):
2014
2014
self .frame )
2015
2015
2016
2016
# Matrix-like
2017
-
2017
+ @ pytest . mark . parametrize ( 'dot_fn' , [ DataFrame . dot , DataFrame . __matmul__ ])
2018
2018
def test_dot (self ):
2019
+ # __matmul__ test is for GH #10259
2019
2020
a = DataFrame (np .random .randn (3 , 4 ), index = ['a' , 'b' , 'c' ],
2020
2021
columns = ['p' , 'q' , 'r' , 's' ])
2021
2022
b = DataFrame (np .random .randn (4 , 2 ), index = ['p' , 'q' , 'r' , 's' ],
2022
2023
columns = ['one' , 'two' ])
2023
2024
2024
- result = a . dot ( b )
2025
+ result = dot_fn ( a , b )
2025
2026
expected = DataFrame (np .dot (a .values , b .values ),
2026
2027
index = ['a' , 'b' , 'c' ],
2027
2028
columns = ['one' , 'two' ])
2028
2029
# Check alignment
2029
2030
b1 = b .reindex (index = reversed (b .index ))
2030
- result = a . dot ( b )
2031
+ result = dot_fn ( a , b )
2031
2032
tm .assert_frame_equal (result , expected )
2032
2033
2033
2034
# Check series argument
2034
- result = a . dot ( b ['one' ])
2035
+ result = dot_fn ( a , b ['one' ])
2035
2036
tm .assert_series_equal (result , expected ['one' ], check_names = False )
2036
2037
assert result .name is None
2037
2038
2038
- result = a . dot ( b1 ['one' ])
2039
+ result = dot_fn ( a , b1 ['one' ])
2039
2040
tm .assert_series_equal (result , expected ['one' ], check_names = False )
2040
2041
assert result .name is None
2041
2042
2042
2043
# can pass correct-length arrays
2043
2044
row = a .iloc [0 ].values
2044
2045
2045
- result = a . dot ( row )
2046
- exp = a . dot ( a .iloc [0 ])
2046
+ result = dot_fn ( a , row )
2047
+ exp = dot_fn ( a , a .iloc [0 ])
2047
2048
tm .assert_series_equal (result , exp )
2048
2049
2049
2050
with tm .assert_raises_regex (ValueError ,
2050
2051
'Dot product shape mismatch' ):
2051
- a . dot ( row [:- 1 ])
2052
+ dot_fn ( a , row [:- 1 ])
2052
2053
2053
2054
a = np .random .rand (1 , 5 )
2054
2055
b = np .random .rand (5 , 1 )
@@ -2058,14 +2059,14 @@ def test_dot(self):
2058
2059
B = DataFrame (b ) # noqa
2059
2060
2060
2061
# it works
2061
- result = A . dot ( b )
2062
+ result = dot_fn ( A , b )
2062
2063
2063
2064
# unaligned
2064
2065
df = DataFrame (randn (3 , 4 ), index = [1 , 2 , 3 ], columns = lrange (4 ))
2065
2066
df2 = DataFrame (randn (5 , 3 ), index = lrange (5 ), columns = [1 , 2 , 3 ])
2066
2067
2067
2068
with tm .assert_raises_regex (ValueError , 'aligned' ):
2068
- df . dot ( df2 )
2069
+ dot_fn ( df , df2 )
2069
2070
2070
2071
2071
2072
@pytest .fixture
0 commit comments