Bug#918206: Pandas new version (not?)
This builds (including build-time tests; haven't tried the autopkgtest). Description: Fix np.array @ DataFrame matrix multiplication Author: jbrockmendel Origin: upstream https://github.com/pandas-dev/pandas/commit/ad2a14f4bec8a004b2972c12f12ed3e4ce37ff52 Bug-Debian: https://bugs.debian.org/918206 Forwarded: not-needed --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1602,6 +1602,7 @@ class NDFrame(PandasObject, SelectionMix # -- # Array Interface +__array_priority__ = 1000 def __array__(self, dtype=None): return com._values_from_object(self) --- 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)
Bug#918206: Pandas new version (not?)
Given the soft freeze, the new upstream version is probably no longer an option for buster. Just setting __array_priority__ fails, but with a message that suggests also including the test_analytics part of that upstream commit would work; I haven't yet had time to try this. left = one two 0 -1.365296 1.088132 1 -1.668353 3.025582 2 0.343140 -0.260306 right = array([[-1.36529629, 1.08813166], [-1.66835336, 3.02558216], [ 0.34314 , -0.26030576]]) cls = def _check_isinstance(left, right, cls): """ Helper method for our assert_* methods that ensures that the two objects being compared have the right type before proceeding with the comparison. Parameters -- left : The first object being compared. right : The second object being compared. cls : The class type to check against. Raises -- AssertionError : Either `left` or `right` is not an instance of `cls`. """ err_msg = "{name} Expected type {exp_type}, found {act_type} instead" cls_name = cls.__name__ if not isinstance(left, cls): raise AssertionError(err_msg.format(name=cls_name, exp_type=cls, act_type=type(left))) if not isinstance(right, cls): raise AssertionError(err_msg.format(name=cls_name, exp_type=cls, > act_type=type(right))) E AssertionError: DataFrame Expected type 'pandas.core.frame.DataFrame'>, found instead ../debian/tmp/usr/lib/python3/dist-packages/pandas/util/testing.py:296: AssertionError
Bug#918206: Pandas new version
Control: tags -1 fixed-upstream patch The test failure is that np.array @ pd.DataFrame (matrix product) tries to keep both the DataFrame's indices, which fails because the new matrix is a different shape. This appears to be fixed in 0.24.1 from PyPI, but as previously noted, this is a new major version and hence risks breaking rdeps. The relevant change appears to be setting __array_priority__: https://github.com/brute4s99/pandas/commit/a01fa791eafe704ea85e2acc956ad9077e8e7542#diff-03b380f521c43cf003207b0711bac67f but I haven't actually tried applying only that to 0.23.