Skip to content

Commit

Permalink
FIX-#3890: Fix the default to pandas in pd.DataFrame.sparse.from_spma…
Browse files Browse the repository at this point in the history
…trix. (#3891)

Signed-off-by: mvashishtha <mahesh@ponder.io>
  • Loading branch information
mvashishtha committed Jan 10, 2022
1 parent 0d9d14e commit ab2855b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
7 changes: 5 additions & 2 deletions modin/pandas/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import pandas
from pandas.core.arrays.sparse.dtype import SparseDtype

import modin.pandas as pd
from modin.error_message import ErrorMessage
from modin.utils import _inherit_docstrings


Expand Down Expand Up @@ -108,8 +110,9 @@ def density(self):

@classmethod
def from_spmatrix(cls, data, index=None, columns=None):
return cls._default_to_pandas(
pandas.DataFrame.sparse.from_spmatrix, data, index=index, columns=columns
ErrorMessage.default_to_pandas("`from_spmatrix`")
return pd.DataFrame(
pandas.DataFrame.sparse.from_spmatrix(data, index=index, columns=columns)
)

def to_dense(self):
Expand Down
13 changes: 13 additions & 0 deletions modin/pandas/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from modin.pandas.utils import from_arrow
import pyarrow as pa
import os
from scipy import sparse
import sys
import shutil
import sqlalchemy as sa
Expand Down Expand Up @@ -2175,6 +2176,18 @@ def test_from_arrow():
df_equals(modin_df, pandas_df)


@pytest.mark.xfail(
condition="config.getoption('--simulate-cloud').lower() != 'off'",
reason="The reason of tests fail in `cloud` mode is unknown for now - issue #3264",
)
def test_from_spmatrix():
data = sparse.eye(3)
with pytest.warns(UserWarning, match="defaulting to pandas.*"):
modin_df = pd.DataFrame.sparse.from_spmatrix(data)
pandas_df = pandas.DataFrame.sparse.from_spmatrix(data)
df_equals(modin_df, pandas_df)


@pytest.mark.xfail(
condition="config.getoption('--simulate-cloud').lower() != 'off'",
reason="The reason of tests fail in `cloud` mode is unknown for now - issue #3264",
Expand Down
1 change: 1 addition & 0 deletions requirements/env_omnisci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ dependencies:
- openpyxl
- xlrd
- sqlalchemy
- scipy

0 comments on commit ab2855b

Please sign in to comment.