Repository: modin-project/modin

Issue:
BUG: Modin crashes on groupby.{pct_change,diff}
### 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 as pd
df = pd.DataFrame({
    "by": ["a", "b", "c", "a", "c"],
    "value": [1, 2, 4, 5, 1],
})
pd.groupby(by="by").pct_change()  # Crashes
pd.groupby(by="by").diff()  # Crashes
```


### Issue Description

An erroneous type check ((here)[https://github.com/modin-project/modin/blame/9ed4e69d1d0ac5e3b527bf5330376d5937a3a80d/modin/pandas/groupby.py#L493]) results in pct_change and diff incorrectly reading the `by` field of the groupby object in certain dataframes, leading to a crash.

### Expected Behavior

Modin does not crash.

### 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/pandas/groupby.py b/modin/pandas/groupby.py
--- a/modin/pandas/groupby.py
+++ b/modin/pandas/groupby.py
@@ -492,8 +492,7 @@ def pct_change(self, periods=1, fill_method="pad", limit=None, freq=None, axis=0
                 # can't calculate change on non-numeric columns, so check for
                 # non-numeric columns that are not included in the `by`
                 if not is_numeric_dtype(dtype) and not (
-                    isinstance(self._by, (Series, DataFrame))
-                    and col in self._by._query_compiler.columns
+                    isinstance(self._by, BaseQueryCompiler) and col in self._by.columns
                 ):
                     raise TypeError(f"unsupported operand type for -: got {dtype}")
 
@@ -1192,8 +1191,7 @@ def diff(self, periods=1, axis=0):
                 # can't calculate diff on non-numeric columns, so check for non-numeric
                 # columns that are not included in the `by`
                 if not is_numeric_dtype(dtype) and not (
-                    isinstance(self._by, (Series, DataFrame))
-                    and col in self._by._query_compiler.columns
+                    isinstance(self._by, BaseQueryCompiler) and col in self._by.columns
                 ):
                     raise TypeError(f"unsupported operand type for -: got {dtype}")
 


Test patch:
diff --git a/modin/pandas/test/test_groupby.py b/modin/pandas/test/test_groupby.py
--- a/modin/pandas/test/test_groupby.py
+++ b/modin/pandas/test/test_groupby.py
@@ -2659,3 +2659,23 @@ def test_groupby_agg_with_empty_column_partition_6175(method):
         # expect any exceptions.
         raising_exceptions=(Exception,),
     )
+
+
+def test_groupby_pct_change_diff_6194():
+    df = pd.DataFrame(
+        {
+            "by": ["a", "b", "c", "a", "c"],
+            "value": [1, 2, 4, 5, 1],
+        }
+    )
+    # These methods should not crash
+    eval_general(
+        df,
+        df._to_pandas(),
+        lambda df: df.groupby(by="by").pct_change(),
+    )
+    eval_general(
+        df,
+        df._to_pandas(),
+        lambda df: df.groupby(by="by").diff(),
+    )