Open labanyamukhopadhyay opened 2 years ago
@labanyamukhopadhyay thank you for reporting this! It's hard to tell just from the stack trace what is going wrong in Modin. Would you be able to create a minimal reproducible example of the Modin error, including any data required to reproduce the error? It's ideal to have a snippet that works in Modin, but not in pandas.
@mvashishtha hopefully this is enough to reproduce the error! The following works in pandas but not modin
import modin.pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import warnings
warnings.filterwarnings('ignore')
%matplotlib inline
df_train = pd.read_csv('../examples/data/train.csv')
corrmat = df_train.corr()
k = 10 #number of variables for heatmap
cols = corrmat.nlargest(k, 'SalePrice')['SalePrice'].index
@labanyamukhopadhyay thank you! By the way, if you use ```python
instead of just ```
to demarcate your Python code in Github markdown, your code will show up as Python!
I can reproduce the bug with nlargest
on Modin version 0.13.0+14.g99e8507c
. Here's a short, self-contained example:
import modin.pandas as pd
from modin.config import MinPartitionSize
# Compute nlargest with a single column partition.
pd.DataFrame([[1] * (MinPartitionSize.get())]).nlargest(1, columns=0)
# Try to compute nlargest with two column partitions. KeyError: 0
pd.DataFrame([[1] * (MinPartitionSize.get() + 1)]).nlargest(1, columns=0)
The problem is that Modin tries to parallelize the row sort by splitting it up among column partitions, but not every partition will have access to the columns needed to do the sort. In the above example, in the first case, all the columns are in a single partition, but in the second, one of the two partitions is missing the first column, 0. We could fix this by adding the sort columns into each partition, doing the sort, and then removing the sort columns. If that's too complicated, we can default to pandas instead. If we had a good way to parallelize sort along the sorting axis as in #3535, we could use that to speed up nlargest
. @modin-project/modin-contributors , any thoughts?
So it looks like the assumption in our implementation is that nlargest
is run independently on each column. Marked for the next release.
I also ran into the same RayTaskError(KeyError)
error today with the latest 0.15 code.
In addition, if we do nlargest
on pd.Series, it defaults to pandas implementation, even though the docs states that nlargest is supported for pd.Series.
import modin.pandas as pd
filename = "data/synthetic_100_1000.parquet"
df = pd.read_parquet(filename)
df.nlargest(5,"col_0") # RayTaskError
df["col_0"].nlargest(5) # default to pandas
Note that #3435 has a similar root cause: when doing a distributed groupby, not all partitions have the keys they need to group by.
I got key error too, nlargest
is common in use.
Describe the problem
There is an issue with nlargest function that results in ray.exceptions.RayTaskError: ray::deploy_ray_func() due to
columns
parameter in nlargest.Source code
Error message