From 88856eade1618d23de68a737c892b6806f4c616c Mon Sep 17 00:00:00 2001 From: Debian Science Team Date: Wed, 6 Mar 2019 22:19:34 +0000 Subject: [PATCH] 918206 Using this and not upstream's __array_priority__ fix https://github.com/pandas-dev/pandas/commit/ad2a14f4bec8a004b2972c12f12ed3e4ce37ff52 to allow np.array += DataFrame to remain in-place (same object ID / other views also affected) and an array (not a DataFrame). Author: jbrockmendel, Rebecca N. Palmer Origin: upstream Bug-Debian: https://bugs.debian.org/918206 https://bugs.debian.org/923707 Forwarded: not-needed Gbp-Pq: Name 918206.patch --- pandas/core/generic.py | 2 ++ pandas/tests/frame/test_analytics.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 02462218..d1fe127d 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1607,6 +1607,8 @@ class NDFrame(PandasObject, SelectionMixin): def __array_wrap__(self, result, context=None): d = self._construct_axes_dict(self._AXIS_ORDERS, copy=False) + if context is not None and context[0]==np.matmul and not hasattr(context[1][0],'index'): + d.pop('index',None) return self._constructor(result, **d).__finalize__(self) # ideally we would define this to avoid the getattr checks, but diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 0e9d9a15..046285b8 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -2283,8 +2283,11 @@ class TestDataFrameAnalytics(TestData): # np.array @ DataFrame result = operator.matmul(a.values, b) + assert isinstance(result, DataFrame) + assert result.columns.equals(b.columns) + assert result.index.equals(pd.Index(range(3))) expected = np.dot(a.values, b.values) - tm.assert_almost_equal(result, expected) + tm.assert_almost_equal(result.values, expected) # nested list @ DataFrame (__rmatmul__) result = operator.matmul(a.values.tolist(), b) -- 2.30.2