QuantConnect / QuantConnect/Lean
Dask serialization issues due to wrapper object for DataFrame
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 21.7k
- Forks
- 5.3k
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 34
Description
Expected Behavior
The DataFrame returned by h = qb.History(qb.Securities.Keys, 10) should be a regular data frame or a conversion method should be available.
Actual Behavior
The DataFrame returned by the history call is some special wrapper object (https://github.com/QuantConnect/Lean/blob/4c085ff853b8a7e63aa4fc9dff7f03c354a75e7f/Common/Python/PandasData.cs#L571), causing various parallel processing libraries to fail during pickling. In the following stacktrace, it can bee seen that the module 'remapper' cannot be found, which is defined here: https://github.com/QuantConnect/Lean/blob/master/Common/Python/PandasData.cs
UserWarning: Distributing <class 'pandas.core.frame.DataFrame'> object. This may take some time.
distributed.core - ERROR - Exception while handling op scatter
Traceback (most recent call last):
File "/opt/miniconda3/lib/python3.6/site-packages/distributed/core.py", line 500, in handle_comm
result = await result
File "/opt/miniconda3/lib/python3.6/site-packages/distributed/scheduler.py", line 4773, in scatter
nthreads, data, rpc=self.rpc, report=False
File "/opt/miniconda3/lib/python3.6/site-packages/distributed/utils_comm.py", line 149, in scatter_to_workers
for address, v in d.items()
File "/opt/miniconda3/lib/python3.6/site-packages/distributed/utils.py", line 229, in All
result = await tasks.next()
File "/opt/miniconda3/lib/python3.6/site-packages/distributed/core.py", line 861, in send_recv_from_rpc
result = await send_recv(comm=comm, op=key, **kwargs)
File "/opt/miniconda3/lib/python3.6/site-packages/distributed/core.py", line 662, in send_recv
raise Exception(response["text"])
Exception: No module named 'remapper'
Potential Solution
- Allow conversion into a regular panda data frame. I have tried using the regular pandas DataFrame constructor, but the wrapper remains. I think this would be clearly the preferable way, as any downstream issues wrt pandas parallel processing will be avoided.
- Document how the PYTHONPATH has to be modified (in the notebook itself, prior to importing modin) when using the Research Docker image so that the Dask workers can locate the
remappermodule.
Reproducing the Problem
from clr import AddReference
from QuantConnect.Python import *
from QuantConnect.Brokerages import BrokerageName
import modin.pandas as pd
import pandas as pdo
qb = QuantBook()
qb.SetBrokerageModel(BrokerageName.Bitfinex, AccountType.Margin)
qb.SetStartDate(2021,1,18)
qb.AddCrypto("BTCUSD", Resolution.Minute)
h = qb.History(qb.Securities.Keys, 2 * 10)
# This shows that the remapper wrapper object is kinda 'persistent'
h_pandas = pdo.DataFrame(h)
h_modin = pd.DataFrame(h_pandas)
System Information
quantconnect/research:latest docker image, extended by installation of modin[dask]==0.6.3.
Checklist
- I have completely filled out this template
- I have confirmed that this issue exists on the current
masterbranch - I have confirmed that this is not a duplicate issue by searching issues
- I have provided detailed steps to reproduce the issue
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Common/Python/PandasData.cs, the QuantBook History entry point, and the supplied reproduction using pandas, Modin, and Dask. Run the example to confirm the wrapper survives pandas conversion, then define done as either a regular DataFrame conversion path or documentation that makes the remapper module available to Dask workers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, pandas, python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100