Skip to content

BUG: when np.datetime64[ns] is a type in a MultiIndex, "NotImplementedError" when trying to return the df from a joblib.delayed #63078

@RongkunWang

Description

@RongkunWang

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import numpy as np
import pandas as pd
import joblib

def job():
	df = pd.DataFrame({
		'date' : [np.datetime64("20110101", 'ns')], 
		'id' : [1], 
		'val' : [1]
		}).set_index(["date", "id"])
	return df

joblib.Parallel(n_jobs = 32)(
	[joblib.delayed(job)()]
	)

Issue Description

joblib.externals.loky.process_executor._RemoteTraceback:
"""
Traceback (most recent call last):
File "/lxhome/wangrong/equity_ls_mf_events/first_project/venvpy312/lib/python3.12/site-packages/joblib/externals/loky/process_executor.py", line 688, in wait_result_broken_or_wakeup
result_item = result_reader.recv()
^^^^^^^^^^^^^^^^^^^^
File "/opt/third/python/3.12/root/lib/python3.12/multiprocessing/connection.py", line 251, in recv
return _ForkingPickler.loads(buf.getbuffer())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "pandas/_libs/arrays.pyx", line 85, in pandas._libs.arrays.NDArrayBacked.setstate
File "pandas/_libs/arrays.pyx", line 103, in pandas._libs.arrays.NDArrayBacked.setstate
NotImplementedError: (dtype('<M8[ns]'), array(['2026-04-05T16:07:45.133961216'], dtype='datetime64[ns]'))
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/lxhome/wangrong/equity_ls_mf_events/first_project/bugs/pickle_datetime.py", line 18, in
)
^^
File "/lxhome/wangrong/equity_ls_mf_events/first_project/venvpy312/lib/python3.12/site-packages/joblib/parallel.py", line 2072, in call
return output if self.return_generator else list(output)
^^^^^^^^^^^^
File "/lxhome/wangrong/equity_ls_mf_events/first_project/venvpy312/lib/python3.12/site-packages/joblib/parallel.py", line 1682, in _get_outputs
yield from self._retrieve()
File "/lxhome/wangrong/equity_ls_mf_events/first_project/venvpy312/lib/python3.12/site-packages/joblib/parallel.py", line 1784, in _retrieve
self._raise_error_fast()
File "/lxhome/wangrong/equity_ls_mf_events/first_project/venvpy312/lib/python3.12/site-packages/joblib/parallel.py", line 1859, in _raise_error_fast
error_job.get_result(self.timeout)
File "/lxhome/wangrong/equity_ls_mf_events/first_project/venvpy312/lib/python3.12/site-packages/joblib/parallel.py", line 758, in get_result
return self._return_or_raise()
^^^^^^^^^^^^^^^^^^^^^^^
File "/lxhome/wangrong/equity_ls_mf_events/first_project/venvpy312/lib/python3.12/site-packages/joblib/parallel.py", line 773, in _return_or_raise
raise self._result
joblib.externals.loky.process_executor.BrokenProcessPool: A result has failed to un-serialize. Please ensure that the objects returned by the function are always picklable.

Expected Behavior

No error. I observed no error in pandas 2.2.3. It seems there's no error when it's not MultiIndex.

Installed Versions

INSTALLED VERSIONS

commit : 9c8bc3e
python : 3.12.6
python-bits : 64
OS : Linux
OS-release : 3.10.0-1160.119.1.el7.x86_64
Version : #1 SMP Tue Jun 4 14:43:51 UTC 2024
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.3.3
numpy : 2.3.4
pytz : 2025.2
dateutil : 2.9.0.post0
pip : 25.3
Cython : None
sphinx : None
IPython : 9.7.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.14.2
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.6
lxml.etree : 6.0.2
matplotlib : 3.10.0
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : 20.0.0
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.15.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.2
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions