无法散列的类型:将 modin 与 pandas 一起使用时的系列?
Unhashable type: Series when using modin with pandas?
我在 Anaconda Windows 10;我通过以下方式安装:
conda install -c anaconda dask
conda install -c conda-forge modin
conda update conda
conda update anaconda
conda update dask
conda install -c conda-forge pandas=1.0.5 # this will also download modin 0.7.4-py_0 --> 0.8.0-py_0
因此,请考虑以下示例:
#!/usr/bin/env python3
import io
USEDASK=False
if not USEDASK:
import pandas as pd
else:
from dask.distributed import Client # SO:48067066
client = Client(processes=False) # create scheduler and worker automatically
#os.environ["MODIN_ENGINE"] = "dask" # Modin will use Dask
import modin.pandas as pd
my_csv_str = """Time[s], Channel 0
0.000000000000000, -0.736680805683136
0.000008000000000, -0.726485192775726
0.000016000000000, -0.721387386322021
0.000024000000000, -0.711191773414612
0.000032000000000, -0.700996160507202
0.000040000000000, -0.690800547599792
0.000048000000000, -0.670409321784973
0.000056000000000, -0.655115902423859
"""
my_csv_io = io.StringIO()
my_csv_io.write(my_csv_str)
my_csv_io.seek(0)
my_df = pd.read_csv(my_csv_io)
my_df.index = pd.to_timedelta(my_df.iloc[:,0], unit='s')
print(my_df)
当我有 USEDASK=False
时,一切正常。
当我有 USEDASK=True
时,我有以下故障:
python test\test.py
UserWarning: The Dask Engine for Modin is experimental.
UserWarning: Parameters provided defaulting to pandas implementation.
To request implementation, send an email to feature_requests@modin.org.
Traceback (most recent call last):
File "test\test.py", line 30, in <module>
my_df.index = pd.to_timedelta(my_df.iloc[:,0], unit='s')
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\tools\timedeltas.py", line 102, in to_timedelta
return _convert_listlike(arg, unit=unit, errors=errors)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\tools\timedeltas.py", line 140, in _convert_listlike
value = sequence_to_td64ns(arg, unit=unit, errors=errors, copy=False)[0]
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\arrays\timedeltas.py", line 961, in sequence_to_td64ns
data[mask] = iNaT
File "C:\ProgramData\Anaconda3\lib\site-packages\modin\pandas\series.py", line 337, in __setitem__
if key not in self.keys():
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\range.py", line 338, in __contains__
hash(key)
TypeError: unhashable type: 'Series'
有什么方法可以使用 modin+dask 使这段代码正常工作吗?
这不是一个好的解决方案,但应该使用解决方法:
my_df.index = pd.to_timedelta(my_df.iloc[:,0].values, unit='s')
这适用于USEDASK
是真还是假
我在 Anaconda Windows 10;我通过以下方式安装:
conda install -c anaconda dask
conda install -c conda-forge modin
conda update conda
conda update anaconda
conda update dask
conda install -c conda-forge pandas=1.0.5 # this will also download modin 0.7.4-py_0 --> 0.8.0-py_0
因此,请考虑以下示例:
#!/usr/bin/env python3
import io
USEDASK=False
if not USEDASK:
import pandas as pd
else:
from dask.distributed import Client # SO:48067066
client = Client(processes=False) # create scheduler and worker automatically
#os.environ["MODIN_ENGINE"] = "dask" # Modin will use Dask
import modin.pandas as pd
my_csv_str = """Time[s], Channel 0
0.000000000000000, -0.736680805683136
0.000008000000000, -0.726485192775726
0.000016000000000, -0.721387386322021
0.000024000000000, -0.711191773414612
0.000032000000000, -0.700996160507202
0.000040000000000, -0.690800547599792
0.000048000000000, -0.670409321784973
0.000056000000000, -0.655115902423859
"""
my_csv_io = io.StringIO()
my_csv_io.write(my_csv_str)
my_csv_io.seek(0)
my_df = pd.read_csv(my_csv_io)
my_df.index = pd.to_timedelta(my_df.iloc[:,0], unit='s')
print(my_df)
当我有 USEDASK=False
时,一切正常。
当我有 USEDASK=True
时,我有以下故障:
python test\test.py
UserWarning: The Dask Engine for Modin is experimental.
UserWarning: Parameters provided defaulting to pandas implementation.
To request implementation, send an email to feature_requests@modin.org.
Traceback (most recent call last):
File "test\test.py", line 30, in <module>
my_df.index = pd.to_timedelta(my_df.iloc[:,0], unit='s')
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\tools\timedeltas.py", line 102, in to_timedelta
return _convert_listlike(arg, unit=unit, errors=errors)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\tools\timedeltas.py", line 140, in _convert_listlike
value = sequence_to_td64ns(arg, unit=unit, errors=errors, copy=False)[0]
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\arrays\timedeltas.py", line 961, in sequence_to_td64ns
data[mask] = iNaT
File "C:\ProgramData\Anaconda3\lib\site-packages\modin\pandas\series.py", line 337, in __setitem__
if key not in self.keys():
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\range.py", line 338, in __contains__
hash(key)
TypeError: unhashable type: 'Series'
有什么方法可以使用 modin+dask 使这段代码正常工作吗?
这不是一个好的解决方案,但应该使用解决方法:
my_df.index = pd.to_timedelta(my_df.iloc[:,0].values, unit='s')
这适用于USEDASK
是真还是假