Repository: modin-project/modin

Issue:
BUG: `pd.get_dummies` produces wrong result
### Modin version checks

- [X] I have checked that this issue has not already been reported.

- [X] I have confirmed this bug exists on the latest released version of Modin.

- [X] I have confirmed this bug exists on the main branch of Modin. (In order to do this you can follow [this guide](https://modin.readthedocs.io/en/stable/getting_started/installation.html#installing-from-the-github-master-branch).)


### Reproducible Example

```python
import pandas
import modin.pandas as pd

pandas_df = pandas.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": ["7", "8", "9"]})
modin_df = pd.DataFrame(pandas_df)

pandas_result = pandas.get_dummies(pandas_df, columns=["a", "b"])
modin_result = pd.get_dummies(modin_df, columns=["a", "b"])

print(pandas_result)
   c  a_1  a_2  a_3  b_4  b_5  b_6
0  7    1    0    0    1    0    0
1  8    0    1    0    0    1    0
2  9    0    0    1    0    0    1

print(modin_result)
   c  a  b
0  7  1  4
1  8  2  5
2  9  3  6
```


### Issue Description

Modin get_dummies() produces wrong result as it doesn't respect passed columns to be encoded.

### Expected Behavior

Should match pandas behavior.

### Error Logs

<details>

```python-traceback

Replace this line with the error backtrace (if applicable).

```

</details>


### Installed Versions

<details>

Replace this line with the output of pd.show_versions()

</details>



Discussion:

Resolving patch:
diff --git a/modin/core/storage_formats/pandas/query_compiler.py b/modin/core/storage_formats/pandas/query_compiler.py
--- a/modin/core/storage_formats/pandas/query_compiler.py
+++ b/modin/core/storage_formats/pandas/query_compiler.py
@@ -3173,20 +3173,22 @@ def get_dummies(self, columns, **kwargs):
         elif not is_list_like(columns):
             columns = [columns]
 
+        def map_fn(df):
+            cols_to_encode = df.columns.intersection(columns)
+            return pandas.get_dummies(df, columns=cols_to_encode, **kwargs)
+
         # In some cases, we are mapping across all of the data. It is more
         # efficient if we are mapping over all of the data to do it this way
         # than it would be to reuse the code for specific columns.
         if len(columns) == len(self.columns):
             new_modin_frame = self._modin_frame.apply_full_axis(
-                0, lambda df: pandas.get_dummies(df, **kwargs), new_index=self.index
+                0, map_fn, new_index=self.index
             )
             untouched_frame = None
         else:
             new_modin_frame = self._modin_frame.take_2d_labels_or_positional(
                 col_labels=columns
-            ).apply_full_axis(
-                0, lambda df: pandas.get_dummies(df, **kwargs), new_index=self.index
-            )
+            ).apply_full_axis(0, map_fn, new_index=self.index)
             untouched_frame = self.drop(columns=columns)
         # If we mapped over all the data we are done. If not, we need to
         # prepend the `new_modin_frame` with the raw data from the columns that were


Test patch:
diff --git a/modin/pandas/test/test_reshape.py b/modin/pandas/test/test_reshape.py
--- a/modin/pandas/test/test_reshape.py
+++ b/modin/pandas/test/test_reshape.py
@@ -65,6 +65,13 @@ def test_get_dummies():
     with warns_that_defaulting_to_pandas():
         pd.get_dummies(1)
 
+    # test from #5184
+    pandas_df = pandas.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": ["7", "8", "9"]})
+    modin_df = pd.DataFrame(pandas_df)
+    pandas_result = pandas.get_dummies(pandas_df, columns=["a", "b"])
+    modin_result = pd.get_dummies(modin_df, columns=["a", "b"])
+    df_equals(modin_result, pandas_result)
+
 
 def test_melt():
     data = test_data_values[0]