pythonpandasdataframeraymodin

How to replace type: pandas.core.frame.DataFrame with type: modin.pandas.dataframe.DataFrame


I try to replace pandas with modin pandas in the code:

if not isinstance(X, pd.DataFrame):
    raise TypeError(
        "X is not a pandas dataframe. The dataset should be a pandas dataframe.")

but the error is:

DataFrame Expected type <class 'pandas.core.frame.DataFrame'>, found <class 'modin.pandas.dataframe.DataFrame'> instead

How should I change code to solve the problem?


Solution

  • As mentioned by devin-petersohn on Github related to this issue you can simply import modin.pandas as such:

    import modin.pandas as m_pd
    
    if not isinstance(X, m_pd.DataFrame):
        raise TypeError(
            "X is not a pandas dataframe. The dataset should be a pandas dataframe.")
    
    

    an alternative could be to call _to_pandas() function, but then you could run into error handling loop.

    Source:

    https://github.com/modin-project/modin/issues/896