Repository: pandas-dev/pandas

Issue:
BUG: incorrect casting in ndarray + DataFrame
```
tdi = pd.timedelta_range('1s', periods=10)
df = pd.DataFrame({'a': tdi, 'b': tdi})
arr = np.arange(2)

>>> df + arr
[...]
AssertionError
# should be TypeError, but close enough for government work

>>> arr + df
                a                      b
0 0 days 00:00:01 0 days 00:00:01.000000
1 1 days 00:00:01 1 days 00:00:01.000000
2 2 days 00:00:01 2 days 00:00:01.000000
3 3 days 00:00:01 3 days 00:00:01.000000
4 4 days 00:00:01 4 days 00:00:01.000000
5 5 days 00:00:01 5 days 00:00:01.000000
6 6 days 00:00:01 6 days 00:00:01.000000
7 7 days 00:00:01 7 days 00:00:01.000000
8 8 days 00:00:01 8 days 00:00:01.000000
9 9 days 00:00:01 9 days 00:00:01.000000
```


Discussion:

Resolving patch:
diff --git a/pandas/core/generic.py b/pandas/core/generic.py
--- a/pandas/core/generic.py
+++ b/pandas/core/generic.py
@@ -1795,6 +1795,10 @@ def __round__(self, decimals=0):
     # ----------------------------------------------------------------------
     # Array Interface
 
+    # This is also set in IndexOpsMixin
+    # GH#23114 Ensure ndarray.__op__(DataFrame) returns NotImplemented
+    __array_priority__ = 1000
+
     def __array__(self, dtype=None):
         return com.values_from_object(self)
 


Test patch:
diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py
--- a/pandas/tests/arithmetic/test_numeric.py
+++ b/pandas/tests/arithmetic/test_numeric.py
@@ -156,7 +156,7 @@ def test_numeric_arr_rdiv_tdscalar(self, three_days, numeric_idx, box):
         if box is not pd.Index and broken:
             # np.timedelta64(3, 'D') / 2 == np.timedelta64(1, 'D')
             raise pytest.xfail("timedelta64 not converted to nanos; "
-                               "Tick division not imlpemented")
+                               "Tick division not implemented")
 
         expected = TimedeltaIndex(['3 Days', '36 Hours'])
 
diff --git a/pandas/tests/arithmetic/test_object.py b/pandas/tests/arithmetic/test_object.py
--- a/pandas/tests/arithmetic/test_object.py
+++ b/pandas/tests/arithmetic/test_object.py
@@ -140,9 +140,6 @@ def test_objarr_radd_str_invalid(self, dtype, data, box):
                                     operator.sub, ops.rsub])
     def test_objarr_add_invalid(self, op, box):
         # invalid ops
-        if box is pd.DataFrame and op is ops.radd:
-            pytest.xfail(reason="DataFrame op incorrectly casts the np.array"
-                                "case to M8[ns]")
 
         obj_ser = tm.makeObjectSeries()
         obj_ser.name = 'objects'
diff --git a/pandas/tests/arithmetic/test_timedelta64.py b/pandas/tests/arithmetic/test_timedelta64.py
--- a/pandas/tests/arithmetic/test_timedelta64.py
+++ b/pandas/tests/arithmetic/test_timedelta64.py
@@ -364,13 +364,13 @@ def test_td64arr_add_str_invalid(self, box):
                                     operator.sub, ops.rsub],
                              ids=lambda x: x.__name__)
     def test_td64arr_add_sub_float(self, box, op, other):
+        if box is pd.DataFrame and isinstance(other, np.ndarray):
+            pytest.xfail("Tries to broadcast, raising "
+                         "ValueError instead of TypeError")
+
         tdi = TimedeltaIndex(['-1 days', '-1 days'])
         tdi = tm.box_expected(tdi, box)
 
-        if box is pd.DataFrame and op in [operator.add, operator.sub]:
-            pytest.xfail(reason="Tries to align incorrectly, "
-                                "raises ValueError")
-
         with pytest.raises(TypeError):
             op(tdi, other)
 
@@ -1126,9 +1126,6 @@ def test_td64arr_floordiv_tdscalar(self, box, scalar_td):
 
     def test_td64arr_rfloordiv_tdscalar(self, box, scalar_td):
         # GH#18831
-        if box is pd.DataFrame and isinstance(scalar_td, np.timedelta64):
-            pytest.xfail(reason="raises TypeError, not sure why")
-
         td1 = Series([timedelta(minutes=5, seconds=3)] * 3)
         td1.iloc[2] = np.nan
 
diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py
--- a/pandas/tests/frame/test_analytics.py
+++ b/pandas/tests/frame/test_analytics.py
@@ -2046,8 +2046,11 @@ def test_matmul(self):
 
         # 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)