Repository: modin-project/modin

Issue:
BUG: HDK: 'AVG|SUM' is only valid on integer and floating point
### 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 modin.pandas as pd

df = pd.DataFrame({"A": [True, False]})
print(df.mean())
print(df.sum())
```


### Issue Description

The code above fails on HDK engine.

### Expected Behavior

```
A    0.5
dtype: float64
A    1
dtype: int64
```

### Error Logs

<details>

```python-traceback

modin/experimental/core/execution/native/implementations/hdk_on_native/hdk_worker.py", line 76, in _executeRelAlgJson
    res = rel_alg_executor.execute()
  File "_sql.pyx", line 103, in pyhdk._sql.RelAlgExecutor.execute
RuntimeError: AVG is only valid on integer and floating point

```

</details>


### Installed Versions

<details>

INSTALLED VERSIONS
------------------
commit           : d3948666bf211c296f3a5640f23a9471cd4f54f0
python           : 3.10.8.final.0
python-bits      : 64
OS               : Linux
OS-release       : 5.15.79.1-microsoft-standard-WSL2
Version          : #1 SMP Wed Nov 23 01:01:46 UTC 2022
machine          : x86_64
processor        : x86_64
byteorder        : little
LC_ALL           : None
LANG             : en_GB.UTF-8
LOCALE           : en_GB.UTF-8

Modin dependencies
------------------
modin            : 0.18.0+52.gd3948666.dirty
hdk              : present

pandas dependencies
-------------------
pandas           : 1.5.2
numpy            : 1.24.1
pytz             : 2022.7.1
dateutil         : 2.8.2
setuptools       : 66.0.0
pip              : 22.3.1
Cython           : None
pytest           : 7.2.1
hypothesis       : None
sphinx           : 6.1.3
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : 3.1.2
IPython          : None
pandas_datareader: None
bs4              : None
bottleneck       : None
brotli           : 
fastparquet      : None
fsspec           : 2022.11.0
gcsfs            : None
matplotlib       : 3.6.3
numba            : None
numexpr          : None
odfpy            : None
openpyxl         : 3.0.10
pandas_gbq       : None
pyarrow          : 8.0.1
pyreadstat       : None
pyxlsb           : None
s3fs             : 2022.11.0
scipy            : 1.10.0
snappy           : None
sqlalchemy       : 1.4.46
tables           : None
tabulate         : None
xarray           : None
xlrd             : 2.0.1
xlwt             : None
zstandard        : None
tzdata           : None

</details>



Discussion:

Resolving patch:
diff --git a/modin/experimental/core/storage_formats/hdk/query_compiler.py b/modin/experimental/core/storage_formats/hdk/query_compiler.py
--- a/modin/experimental/core/storage_formats/hdk/query_compiler.py
+++ b/modin/experimental/core/storage_formats/hdk/query_compiler.py
@@ -32,6 +32,8 @@
 from pandas.core.dtypes.common import is_list_like
 from functools import wraps
 
+import numpy as np
+
 
 def is_inoperable(value):
     """
@@ -399,9 +401,11 @@ def sum(self, **kwargs):
             raise NotImplementedError(
                 f"HDK's sum does not support such set of parameters: min_count={min_count}."
             )
+        _check_int_or_float("sum", self.dtypes)
         return self._agg("sum", **kwargs)
 
     def mean(self, **kwargs):
+        _check_int_or_float("mean", self.dtypes)
         return self._agg("mean", **kwargs)
 
     def nunique(self, axis=0, dropna=True):
@@ -793,3 +797,14 @@ def free(self):
     @property
     def dtypes(self):
         return self._modin_frame.dtypes
+
+
+_SUPPORTED_NUM_TYPE_CODES = set(np.typecodes["AllInteger"] + np.typecodes["Float"]) - {
+    np.dtype(np.float16).char
+}
+
+
+def _check_int_or_float(op, dtypes):  # noqa: GL08
+    for t in dtypes:
+        if t.char not in _SUPPORTED_NUM_TYPE_CODES:
+            raise NotImplementedError(f"Operation '{op}' on type '{t.name}'")


Test patch:
diff --git a/modin/experimental/core/execution/native/implementations/hdk_on_native/test/test_dataframe.py b/modin/experimental/core/execution/native/implementations/hdk_on_native/test/test_dataframe.py
--- a/modin/experimental/core/execution/native/implementations/hdk_on_native/test/test_dataframe.py
+++ b/modin/experimental/core/execution/native/implementations/hdk_on_native/test/test_dataframe.py
@@ -2061,6 +2061,19 @@ def test_uint_serialization(self):
         df = pd.DataFrame({"A": [np.iinfo(np.int64).max - 1, 1]})
         assert df.astype(np.uint64).sum()[0] == np.iinfo(np.int64).max
 
+    def test_mean_sum(self):
+        all_codes = np.typecodes["All"]
+        exclude_codes = np.typecodes["Datetime"] + np.typecodes["Complex"] + "gSUVO"
+        supported_codes = set(all_codes) - set(exclude_codes)
+
+        def test(df, dtype_code, operation, **kwargs):
+            df = type(df)({"A": [0, 1], "B": [1, 0]}, dtype=np.dtype(dtype_code))
+            return getattr(df, operation)()
+
+        for c in supported_codes:
+            for op in ("sum", "mean"):
+                run_and_compare(test, data={}, dtype_code=c, operation=op)
+
 
 class TestDropna:
     data = {