|
1 | 1 | from datetime import timedelta
|
2 | 2 | from decimal import Decimal
|
3 |
| -import operator |
4 | 3 |
|
5 | 4 | import numpy as np
|
6 | 5 | import pytest
|
@@ -1115,82 +1114,6 @@ def test_any_all_level_axis_none_raises(self, method):
|
1115 | 1114 | with pytest.raises(ValueError, match=xpr):
|
1116 | 1115 | getattr(df, method)(axis=None, level="out")
|
1117 | 1116 |
|
1118 |
| - # --------------------------------------------------------------------- |
1119 |
| - # Matrix-like |
1120 |
| - |
1121 |
| - def test_matmul(self): |
1122 |
| - # matmul test is for GH 10259 |
1123 |
| - a = DataFrame( |
1124 |
| - np.random.randn(3, 4), index=["a", "b", "c"], columns=["p", "q", "r", "s"] |
1125 |
| - ) |
1126 |
| - b = DataFrame( |
1127 |
| - np.random.randn(4, 2), index=["p", "q", "r", "s"], columns=["one", "two"] |
1128 |
| - ) |
1129 |
| - |
1130 |
| - # DataFrame @ DataFrame |
1131 |
| - result = operator.matmul(a, b) |
1132 |
| - expected = DataFrame( |
1133 |
| - np.dot(a.values, b.values), index=["a", "b", "c"], columns=["one", "two"] |
1134 |
| - ) |
1135 |
| - tm.assert_frame_equal(result, expected) |
1136 |
| - |
1137 |
| - # DataFrame @ Series |
1138 |
| - result = operator.matmul(a, b.one) |
1139 |
| - expected = Series(np.dot(a.values, b.one.values), index=["a", "b", "c"]) |
1140 |
| - tm.assert_series_equal(result, expected) |
1141 |
| - |
1142 |
| - # np.array @ DataFrame |
1143 |
| - result = operator.matmul(a.values, b) |
1144 |
| - assert isinstance(result, DataFrame) |
1145 |
| - assert result.columns.equals(b.columns) |
1146 |
| - assert result.index.equals(pd.Index(range(3))) |
1147 |
| - expected = np.dot(a.values, b.values) |
1148 |
| - tm.assert_almost_equal(result.values, expected) |
1149 |
| - |
1150 |
| - # nested list @ DataFrame (__rmatmul__) |
1151 |
| - result = operator.matmul(a.values.tolist(), b) |
1152 |
| - expected = DataFrame( |
1153 |
| - np.dot(a.values, b.values), index=["a", "b", "c"], columns=["one", "two"] |
1154 |
| - ) |
1155 |
| - tm.assert_almost_equal(result.values, expected.values) |
1156 |
| - |
1157 |
| - # mixed dtype DataFrame @ DataFrame |
1158 |
| - a["q"] = a.q.round().astype(int) |
1159 |
| - result = operator.matmul(a, b) |
1160 |
| - expected = DataFrame( |
1161 |
| - np.dot(a.values, b.values), index=["a", "b", "c"], columns=["one", "two"] |
1162 |
| - ) |
1163 |
| - tm.assert_frame_equal(result, expected) |
1164 |
| - |
1165 |
| - # different dtypes DataFrame @ DataFrame |
1166 |
| - a = a.astype(int) |
1167 |
| - result = operator.matmul(a, b) |
1168 |
| - expected = DataFrame( |
1169 |
| - np.dot(a.values, b.values), index=["a", "b", "c"], columns=["one", "two"] |
1170 |
| - ) |
1171 |
| - tm.assert_frame_equal(result, expected) |
1172 |
| - |
1173 |
| - # unaligned |
1174 |
| - df = DataFrame(np.random.randn(3, 4), index=[1, 2, 3], columns=range(4)) |
1175 |
| - df2 = DataFrame(np.random.randn(5, 3), index=range(5), columns=[1, 2, 3]) |
1176 |
| - |
1177 |
| - with pytest.raises(ValueError, match="aligned"): |
1178 |
| - operator.matmul(df, df2) |
1179 |
| - |
1180 |
| - def test_matmul_message_shapes(self): |
1181 |
| - # GH#21581 exception message should reflect original shapes, |
1182 |
| - # not transposed shapes |
1183 |
| - a = np.random.rand(10, 4) |
1184 |
| - b = np.random.rand(5, 3) |
1185 |
| - |
1186 |
| - df = DataFrame(b) |
1187 |
| - |
1188 |
| - msg = r"shapes \(10, 4\) and \(5, 3\) not aligned" |
1189 |
| - with pytest.raises(ValueError, match=msg): |
1190 |
| - a @ df |
1191 |
| - with pytest.raises(ValueError, match=msg): |
1192 |
| - a.tolist() @ df |
1193 |
| - |
1194 | 1117 | # ---------------------------------------------------------------------
|
1195 | 1118 | # Unsorted
|
1196 | 1119 |
|
|
0 commit comments