lesteve: Forgot to say, but I checked that this fix didn't affect the hash of non datetime-like numpy arrays.
ogrisel: Other than my comment, LGTM.
diff --git a/joblib/hashing.py b/joblib/hashing.py
index 564817c..d3d783a 100644
--- a/joblib/hashing.py
+++ b/joblib/hashing.py
@@ -154,14 +154,21 @@ class NumpyHasher(Hasher):
         if isinstance(obj, self.np.ndarray) and not obj.dtype.hasobject:
             # Compute a hash of the object:
             try:
-                self._hash.update(self._getbuffer(obj))
+                # memoryview is not supported for some dtypes,
+                # e.g. datetime64, see
+                # https://github.com/numpy/numpy/issues/4983.  The
+                # workaround is to view the array as bytes before
+                # taking the memoryview
+                obj_bytes_view = obj.view(self.np.uint8)
+                self._hash.update(self._getbuffer(obj_bytes_view))
             except (TypeError, BufferError, ValueError):
                 # Cater for non-single-segment arrays: this creates a
                 # copy, and thus aleviates this issue.
                 # XXX: There might be a more efficient way of doing this
                 # Python 3.2's memoryview raise a ValueError instead of a
                 # TypeError or a BufferError
-                self._hash.update(self._getbuffer(obj.flatten()))
+                obj_bytes_view = obj.flatten().view(self.np.uint8)
+                self._hash.update(self._getbuffer(obj_bytes_view))
 
             # We store the class, to be able to distinguish between
             # Objects with the same binary content, but different

Cannot hash datetime64
```
In [59]: joblib.hashing.hash(numpy.zeros(dtype="<m8[s]", shape=(10,)))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-59-8b9b8a0f034d> in <module>()
----> 1 joblib.hashing.hash(numpy.zeros(dtype="<m8[s]", shape=(10,)))

/export/data/home/gholl/venv/bleeding/lib/python3.4/site-packages/joblib/hashing.py in hash(obj, hash_name, coerce_mmap)
    199     else:
    200         hasher = Hasher(hash_name=hash_name)
--> 201     return hasher.hash(obj)

/export/data/home/gholl/venv/bleeding/lib/python3.4/site-packages/joblib/hashing.py in hash(self, obj, return_digest)
     51     def hash(self, obj, return_digest=True):
     52         try:
---> 53             self.dump(obj)
     54         except pickle.PicklingError as e:
     55             warnings.warn('PicklingError while hashing %r: %r' % (obj, e))

/usr/lib64/python3.4/pickle.py in dump(self, obj)
    408         if self.proto >= 4:
    409             self.framer.start_framing()
--> 410         self.save(obj)
    411         self.write(STOP)
    412         self.framer.end_framing()

/export/data/home/gholl/venv/bleeding/lib/python3.4/site-packages/joblib/hashing.py in save(self, obj)
    162                 # Python 3.2's memoryview raise a ValueError instead of a
    163                 # TypeError or a BufferError
--> 164                 self._hash.update(self._getbuffer(obj.flatten()))
    165 
    166             # We store the class, to be able to distinguish between

ValueError: cannot include dtype 'm' in a buffer
```
diff --git a/joblib/test/test_hashing.py b/joblib/test/test_hashing.py
index 15a5da9..a1f52b1 100644
--- a/joblib/test/test_hashing.py
+++ b/joblib/test/test_hashing.py
@@ -133,6 +133,18 @@ def test_hash_numpy():
     yield nose.tools.assert_not_equal, hash(arr1), hash(arr1.T)
 
 
+@with_numpy
+def test_numpy_datetime_array():
+    # memoryview is not supported for some dtypes e.g. datetime64
+    # see https://github.com/joblib/joblib/issues/188 for more details
+    dtypes = ['datetime64[s]', 'timedelta64[D]']
+
+    a_hash = hash(np.arange(10))
+    arrays = (np.arange(0, 10, dtype=dtype) for dtype in dtypes)
+    for array in arrays:
+        nose.tools.assert_not_equal(hash(array), a_hash)
+
+
 @with_numpy
 def test_hash_numpy_noncontiguous():
     a = np.asarray(np.arange(6000).reshape((1000, 2, 3)),

pip install -e .
parse_log_pytest
nose coverage numpy>=1.6.1 pytest
apt-get update apt-get install -y gcc
3.5
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==22.2.0
certifi==2021.5.30
coverage==6.2
importlib-metadata==4.8.3
iniconfig==1.1.1
-e git+https://github.com/joblib/joblib.git@21cb6f3fd32b11a9b6bc1528b86bbf83fce7bb1f#egg=joblib
nose==1.3.7
numpy==1.19.5
packaging==21.3
pluggy==1.0.0
py==1.11.0
pyparsing==3.1.4
pytest==7.0.1
tomli==1.2.3
typing_extensions==4.1.1
zipp==3.6.0

name: joblib
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==22.2.0
      - coverage==6.2
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - nose==1.3.7
      - numpy==1.19.5
      - packaging==21.3
      - pluggy==1.0.0
      - py==1.11.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - tomli==1.2.3
      - typing-extensions==4.1.1
      - zipp==3.6.0
prefix: /opt/conda/envs/joblib

joblib/test/test_hashing.py::test_numpy_datetime_array
joblib/test/test_hashing.py::test_memory_setup_func joblib/test/test_hashing.py::test_memory_teardown_func joblib/test/test_hashing.py::test_hash_methods joblib/test/test_hashing.py::test_hash_numpy_noncontiguous joblib/test/test_hashing.py::test_hash_numpy_performance joblib/test/test_hashing.py::test_bound_methods_hash joblib/test/test_hashing.py::test_bound_cached_methods_hash joblib/test/test_hashing.py::test_hash_object_dtype joblib/test/test_hashing.py::test_numpy_scalar joblib/test/test_hashing.py::test_dict_hash joblib/test/test_hashing.py::test_set_hash
joblib/hashing.py
joblib/hashing.py