Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX-#1503: Proper implementation of Series.values #5469

Merged
merged 5 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion modin/pandas/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,10 @@ def values(self): # noqa: RT01, D200
"""
Return Series as ndarray or ndarray-like depending on the dtype.
"""
return self.to_numpy()
data = self.to_numpy()
if isinstance(self.dtype, pandas.CategoricalDtype):
data = pandas.Categorical(data, dtype=self.dtype)
anmyachev marked this conversation as resolved.
Show resolved Hide resolved
return data
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is still going to mess up a bunch of EA cases. The correct way to handle this is #4187 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I will continue to work on this separately. At the moment, Modin doesn't have a internal interface to implement your suggestion, I've tried that before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbrockmendel Is there some simple condition by which we can determine what this is EA case?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isinstance(self.dtype, ExtensionDtype)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @jbrockmendel! Should be fixed in #5493.


def add(self, other, level=None, fill_value=None, axis=0): # noqa: PR01, RT01, D200
"""
Expand Down
10 changes: 10 additions & 0 deletions modin/pandas/test/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3613,6 +3613,16 @@ def test_values(data):
np.testing.assert_equal(modin_series.values, pandas_series.values)


def test_values_non_numeric():
data = ["str{0}".format(i) for i in range(0, 10**3)]
modin_series, pandas_series = create_test_series(data)

modin_series = modin_series.astype("category")
pandas_series = pandas_series.astype("category")

df_equals(modin_series.values, pandas_series.values)


@pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
@pytest.mark.parametrize(
"skipna", bool_arg_values, ids=arg_keys("skipna", bool_arg_keys)
Expand Down
2 changes: 2 additions & 0 deletions modin/pandas/test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,8 @@ def df_equals(df1, df2):
assert_index_equal(df1, df2)
elif isinstance(df1, pandas.Series) and isinstance(df2, pandas.Series):
assert_series_equal(df1, df2, check_dtype=False, check_series_type=False)
elif isinstance(df1, pandas.Categorical) and isinstance(df2, pandas.Categorical):
assert_extension_array_equal(df1, df2)
elif isinstance(df1, groupby_types) and isinstance(df2, groupby_types):
for g1, g2 in zip(df1, df2):
assert g1[0] == g2[0]
Expand Down