Repository: pandas-dev/pandas

Issue:
BUG: Series[int] + datetime64 should raise
identified [here](https://github.com/pandas-dev/pandas/commit/a6c0d02c99cfaf90119d1316dd897019326472c1#r34783276).  We handle this correctly for timedelta64, but apparently not datetime64

```
iser = pd.Series(range(3))
dt = np.datetime64(3, "D")

>>> iser + dt
0   1970-01-04
1   1970-01-05
2   1970-01-06
```

Should behave like `iser + pd.Timestamp(dt)`:

```
>>> iser + pd.Timestamp(dt)
[...]
ValueError: Cannot add integral value to Timestamp without freq.
```


Discussion:

Resolving patch:
diff --git a/pandas/_libs/tslibs/__init__.py b/pandas/_libs/tslibs/__init__.py
--- a/pandas/_libs/tslibs/__init__.py
+++ b/pandas/_libs/tslibs/__init__.py
@@ -7,3 +7,6 @@
 from .timedeltas import Timedelta, delta_to_nanoseconds, ints_to_pytimedelta
 from .timestamps import Timestamp
 from .tzconversion import tz_convert_single
+
+# import fails if we do this before np_datetime
+from .c_timestamp import NullFrequencyError  # isort:skip
diff --git a/pandas/errors/__init__.py b/pandas/errors/__init__.py
--- a/pandas/errors/__init__.py
+++ b/pandas/errors/__init__.py
@@ -4,7 +4,7 @@
 Expose public exceptions & warnings
 """
 
-from pandas._libs.tslibs import OutOfBoundsDatetime
+from pandas._libs.tslibs import NullFrequencyError, OutOfBoundsDatetime
 
 
 class PerformanceWarning(Warning):
@@ -157,14 +157,6 @@ class MergeError(ValueError):
     """
 
 
-class NullFrequencyError(ValueError):
-    """
-    Error raised when a null `freq` attribute is used in an operation
-    that needs a non-null frequency, particularly `DatetimeIndex.shift`,
-    `TimedeltaIndex.shift`, `PeriodIndex.shift`.
-    """
-
-
 class AccessorRegistrationWarning(Warning):
     """Warning for attribute conflicts in accessor registration."""
 


Test patch:
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
@@ -241,10 +241,7 @@ def test_subtraction_ops(self):
         with pytest.raises(TypeError, match=msg):
             tdi - dti
 
-        msg = (
-            r"descriptor '__sub__' requires a 'datetime\.datetime' object"
-            " but received a 'Timedelta'"
-        )
+        msg = r"unsupported operand type\(s\) for -"
         with pytest.raises(TypeError, match=msg):
             td - dt
 
diff --git a/pandas/tests/scalar/timestamp/test_arithmetic.py b/pandas/tests/scalar/timestamp/test_arithmetic.py
--- a/pandas/tests/scalar/timestamp/test_arithmetic.py
+++ b/pandas/tests/scalar/timestamp/test_arithmetic.py
@@ -3,6 +3,8 @@
 import numpy as np
 import pytest
 
+from pandas.errors import NullFrequencyError
+
 from pandas import Timedelta, Timestamp
 import pandas.util.testing as tm
 
@@ -177,12 +179,12 @@ def test_timestamp_add_timedelta64_unit(self, other, expected_difference):
         ],
     )
     def test_add_int_no_freq_raises(self, ts, other):
-        with pytest.raises(ValueError, match="without freq"):
+        with pytest.raises(NullFrequencyError, match="without freq"):
             ts + other
-        with pytest.raises(ValueError, match="without freq"):
+        with pytest.raises(NullFrequencyError, match="without freq"):
             other + ts
 
-        with pytest.raises(ValueError, match="without freq"):
+        with pytest.raises(NullFrequencyError, match="without freq"):
             ts - other
         with pytest.raises(TypeError):
             other - ts
diff --git a/pandas/tests/tslibs/test_api.py b/pandas/tests/tslibs/test_api.py
--- a/pandas/tests/tslibs/test_api.py
+++ b/pandas/tests/tslibs/test_api.py
@@ -29,6 +29,7 @@ def test_namespace():
         "NaTType",
         "iNaT",
         "is_null_datetimelike",
+        "NullFrequencyError",
         "OutOfBoundsDatetime",
         "Period",
         "IncompatibleFrequency",