Repository: modin-project/modin

Issue:
astype({"col": "category"}) should convert Series.values type to pandas.core.arrays.categorical.Categorical
### System information
- **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**:

Ubuntu 20.04

- **Modin version** (`modin.__version__`):

0.7.3+57.g23015c5

- **Python version**:

Python 3.8.2

- **Code we can use to reproduce**:

```
if __name__ == "__main__":
    #import pandas as pd
    import modin.pandas as pd

    series_length = 10_000
    df = pd.DataFrame(
        {
            "col1": ["str{0}".format(i) for i in range(0, series_length)],
            "col2": [i for i in range(0, series_length)],
        }
    )

    df1 = df.astype({"col1": "category"})
    print(df1)
    print(df1.dtypes)
    print(type(df1["col1"].values))
    print(df1["col1"].values)
```

<!--
You can obtain the Modin version with

python -c "import modin; print(modin.__version__)"
-->

### Describe the problem
<!-- Describe the problem clearly here. -->

On Pandas column.values type is `pandas.core.arrays.categorical.Categorical` while in Modin it remains to be `numpy.ndarray`. Test for this bug was written in PR #1382 and is marked as xfail at the moment.

### Source code / logs
<!-- Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached. Try to provide a reproducible test case that is the bare minimum necessary to generate the problem. -->



Discussion:
Thanks for the report @gshimansky ! I was able to reproduce this on the latest master: [af86009](https://github.com/modin-project/modin/commit/af860093fc59ed1ae68d9ab8716e5c8534fe9a01). I am not sure if this is a bug. @modin-project/modin-contributors @modin-project/modin-core  Do the underlying values have to match the ones used by pandas? 

Resolving patch:
diff --git a/modin/pandas/series.py b/modin/pandas/series.py
--- a/modin/pandas/series.py
+++ b/modin/pandas/series.py
@@ -484,7 +484,12 @@ def values(self):  # noqa: RT01, D200
         """
         Return Series as ndarray or ndarray-like depending on the dtype.
         """
-        return self.to_numpy()
+        import modin.pandas as pd
+
+        data = self.to_numpy()
+        if isinstance(self.dtype, pd.CategoricalDtype):
+            data = pd.Categorical(data, dtype=self.dtype)
+        return data
 
     def add(self, other, level=None, fill_value=None, axis=0):  # noqa: PR01, RT01, D200
         """


Test patch:
diff --git a/modin/pandas/test/test_series.py b/modin/pandas/test/test_series.py
--- a/modin/pandas/test/test_series.py
+++ b/modin/pandas/test/test_series.py
@@ -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)
diff --git a/modin/pandas/test/utils.py b/modin/pandas/test/utils.py
--- a/modin/pandas/test/utils.py
+++ b/modin/pandas/test/utils.py
@@ -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]