Repository: modin-project/modin

Issue:
`to_parquet` and `to_csv` on Ray engine does not handle exceptions correctly
### System information
- **Modin version** (`modin.__version__`): 6d8b22198170939dbf2a2f21c7ecb80b371d11c0
- **Python version**: `Python 3.8.10`
- **Code we can use to reproduce**:

```python
import modin.pandas as pd

# example of misuse that throws an exception
df = pd.DataFrame([1,2,3,4,5])

df.to_parquet("test.parquet")
print("\nThis message should not be displayed because the previous operation ended with an error.\n")

```

<!--
You can obtain the Modin version with

python -c "import modin; print(modin.__version__)"
-->

### Describe the problem
<!-- Describe the problem clearly here. -->
Although an exception was thrown inside `to_parquet` function, the code continues to execute.

For Ray to handle exceptions correctly, we need to use `get` function instead of `wait`.

### 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. -->
```bash
...\projects\modin>python test.py

UserWarning: Ray execution environment not yet initialized. Initializing...
To remove this warning, run the following python code before doing dataframe operations:

    import ray
    ray.init()

UserWarning: Distributing <class 'list'> object. This may take some time.

This message should not be displayed because the previous operation ended with an error.
2021-11-17 14:47:12,535 ERROR worker.py:79 -- Unhandled error (suppress with RAY_IGNORE_UNHANDLED_ERRORS=1): 
ray::deploy_ray_func() (pid=21876, ip=10.249.228.17)
  File "python\ray\_raylet.pyx", line 536, in ray._raylet.execute_task
  File "...\projects\modin\modin\core\execution\ray\implementations\pandas_on_ray\partitioning\axis_partition.py", line 211, in deploy_ray_func
    result = func(*args)
  File "...\projects\modin\modin\core\dataframe\pandas\partitioning\axis_partition.py", line 160, in deploy_axis_func
    result = func(dataframe, **kwargs)
  File "...\projects\modin\modin\core\execution\ray\generic\io\io.py", line 262, in func
    df.to_parquet(**kwargs)
  File "...Miniconda3\envs\modin\lib\site-packages\pandas\util\_decorators.py", line 207, in wrapper  
    return func(*args, **kwargs)
  File "...Miniconda3\envs\modin\lib\site-packages\pandas\core\frame.py", line 2677, in to_parquet    
    return to_parquet(
  File "...Miniconda3\envs\modin\lib\site-packages\pandas\io\parquet.py", line 416, in to_parquet     
    impl.write(
  File "...Miniconda3\envs\modin\lib\site-packages\pandas\io\parquet.py", line 167, in write
    self.validate_dataframe(df)
  File "...Miniconda3\envs\modin\lib\site-packages\pandas\io\parquet.py", line 129, in validate_dataframe
    raise ValueError("parquet must have string column names")
ValueError: parquet must have string column names
2021-11-17 14:47:12,541 ERROR worker.py:79 -- Unhandled error (suppress with RAY_IGNORE_UNHANDLED_ERRORS=1): ray::deploy_ray_func() (pid=21876, ip=10.249.228.17)
  File "python\ray\_raylet.pyx", line 536, in ray._raylet.execute_task
  File "...\projects\modin\modin\core\execution\ray\implementations\pandas_on_ray\partitioning\axis_partition.py", line 211, in deploy_ray_func
    result = func(*args)
  File "...\projects\modin\modin\core\dataframe\pandas\partitioning\axis_partition.py", line 160, in deploy_axis_func
    result = func(dataframe, **kwargs)
  File "...\projects\modin\modin\core\execution\ray\generic\io\io.py", line 262, in func
    df.to_parquet(**kwargs)
  File "...Miniconda3\envs\modin\lib\site-packages\pandas\util\_decorators.py", line 207, in wrapper  
    return func(*args, **kwargs)
  File "...Miniconda3\envs\modin\lib\site-packages\pandas\core\frame.py", line 2677, in to_parquet    
    return to_parquet(
  File "...Miniconda3\envs\modin\lib\site-packages\pandas\io\parquet.py", line 416, in to_parquet     
    impl.write(
  File "...Miniconda3\envs\modin\lib\site-packages\pandas\io\parquet.py", line 167, in write
    self.validate_dataframe(df)
  File "...Miniconda3\envs\modin\lib\site-packages\pandas\io\parquet.py", line 129, in validate_dataframe
    raise ValueError("parquet must have string column names")
ValueError: parquet must have string column names
2021-11-17 14:47:12,547 ERROR worker.py:79 -- Unhandled error (suppress with RAY_IGNORE_UNHANDLED_ERRORS=1): ray::deploy_ray_func() (pid=21876, ip=10.249.228.17)
  File "python\ray\_raylet.pyx", line 536, in ray._raylet.execute_task
  File "...\projects\modin\modin\core\execution\ray\implementations\pandas_on_ray\partitioning\axis_partition.py", line 211, in deploy_ray_func
    result = func(*args)
  File "...\projects\modin\modin\core\dataframe\pandas\partitioning\axis_partition.py", line 160, in deploy_axis_func
    result = func(dataframe, **kwargs)
  File "...\projects\modin\modin\core\execution\ray\generic\io\io.py", line 262, in func
    df.to_parquet(**kwargs)
  File "...Miniconda3\envs\modin\lib\site-packages\pandas\util\_decorators.py", line 207, in wrapper  
    return func(*args, **kwargs)
  File "...Miniconda3\envs\modin\lib\site-packages\pandas\core\frame.py", line 2677, in to_parquet    
    return to_parquet(
  File "...Miniconda3\envs\modin\lib\site-packages\pandas\io\parquet.py", line 416, in to_parquet     
    impl.write(
  File "...Miniconda3\envs\modin\lib\site-packages\pandas\io\parquet.py", line 167, in write
    self.validate_dataframe(df)
  File "...Miniconda3\envs\modin\lib\site-packages\pandas\io\parquet.py", line 129, in validate_dataframe
    raise ValueError("parquet must have string column names")
ValueError: parquet must have string column names
```


Discussion:

Resolving patch:
diff --git a/modin/core/execution/ray/generic/io/io.py b/modin/core/execution/ray/generic/io/io.py
--- a/modin/core/execution/ray/generic/io/io.py
+++ b/modin/core/execution/ray/generic/io/io.py
@@ -19,7 +19,7 @@
 
 from modin.core.io import BaseIO
 from ray.util.queue import Queue
-from ray import wait
+from ray import get
 
 
 class RayIO(BaseIO):
@@ -195,9 +195,7 @@ def func(df, **kw):
         )
 
         # pending completion
-        for rows in result:
-            for partition in rows:
-                wait([partition.oid])
+        get([partition.oid for partition in result.flatten()])
 
     @staticmethod
     def _to_parquet_check_support(kwargs):
@@ -270,4 +268,4 @@ def func(df, **kw):
             lengths=None,
             enumerate_partitions=True,
         )
-        wait([part.oid for row in result for part in row])
+        get([partition.oid for partition in result.flatten()])


Test patch: