Repository: modin-project/modin

Issue:
Unable to use modin.pandas after installation
modin version '0.5.4'


Discussion:
I am getting the below error when I execute the example given in Git. I am using a mac. The below error is when I call df.head().
---------------------------------------------------------------------------
RayWorkerError                            Traceback (most recent call last)
/anaconda3/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
    700                 type_pprinters=self.type_printers,
    701                 deferred_pprinters=self.deferred_printers)
--> 702             printer.pretty(obj)
    703             printer.flush()
    704             return stream.getvalue()

/anaconda3/lib/python3.7/site-packages/IPython/lib/pretty.py in pretty(self, obj)
    400                         if cls is not object \
    401                                 and callable(cls.__dict__.get('__repr__')):
--> 402                             return _repr_pprint(obj, self, cycle)
    403 
    404             return _default_pprint(obj, self, cycle)

/anaconda3/lib/python3.7/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
    695     """A pprint that just redirects to the normal repr function."""
    696     # Find newlines and replace them with p.break_()
--> 697     output = repr(obj)
    698     for idx,output_line in enumerate(output.splitlines()):
    699         if idx:

/anaconda3/lib/python3.7/site-packages/modin/pandas/dataframe.py in __repr__(self)
     91         num_cols = pandas.get_option("max_columns") or 20
     92 
---> 93         result = repr(self._build_repr_df(num_rows, num_cols))
     94         if len(self.index) > num_rows or len(self.columns) > num_cols:
     95             # The split here is so that we don't repr pandas row lengths.

/anaconda3/lib/python3.7/site-packages/modin/pandas/base.py in _build_repr_df(self, num_rows, num_cols)
     69                 tail_front = pandas.DataFrame()
     70         else:
---> 71             head_front = head.front(num_cols_for_front).to_pandas()
     72             head_back = head.back(num_cols_for_front).to_pandas()
     73 

/anaconda3/lib/python3.7/site-packages/modin/backends/pandas/query_compiler.py in front(self, n)
   2225         else:
   2226             result = self.__constructor__(
-> 2227                 self.data.take(1, n), self.index, self.columns[:n], new_dtypes
   2228             )
   2229         return result

/anaconda3/lib/python3.7/site-packages/modin/engines/base/frame/partition_manager.py in take(self, axis, n)
    372             bin_lengths = self.block_lengths
    373         else:
--> 374             partitions = self.partitions.T
    375             bin_lengths = self.block_widths
    376         if n < 0:

/anaconda3/lib/python3.7/site-packages/modin/engines/base/frame/partition_manager.py in _get_partitions(self)
     72                             if self.block_lengths[i] != 0 and self.block_widths[j] != 0
     73                         ]
---> 74                         for i in range(len(self._partitions_cache))
     75                     ]
     76                     if len(row)

/anaconda3/lib/python3.7/site-packages/modin/engines/base/frame/partition_manager.py in <listcomp>(.0)
     72                             if self.block_lengths[i] != 0 and self.block_widths[j] != 0
     73                         ]
---> 74                         for i in range(len(self._partitions_cache))
     75                     ]
     76                     if len(row)

/anaconda3/lib/python3.7/site-packages/modin/engines/base/frame/partition_manager.py in <listcomp>(.0)
     70                             self._partitions_cache[i][j]
     71                             for j in range(len(self._partitions_cache[i]))
---> 72                             if self.block_lengths[i] != 0 and self.block_widths[j] != 0
     73                         ]
     74                         for i in range(len(self._partitions_cache))

/anaconda3/lib/python3.7/site-packages/modin/engines/ray/generic/frame/partition_manager.py in block_lengths(self)
     38                             [obj.length().oid for obj in self._partitions_cache.T[0]]
     39                         )
---> 40                         if len(self._partitions_cache.T) > 0
     41                         else []
     42                     )

/anaconda3/lib/python3.7/site-packages/ray/worker.py in get(object_ids)
   2187             if isinstance(value, RayError):
   2188                 last_task_error_raise_time = time.time()
-> 2189                 raise value
   2190 
   2191         # Run post processors.

RayWorkerError: The worker died unexpectedly while executing this task.

---------------------------------------------------------------------------
RayWorkerError                            Traceback (most recent call last)
/anaconda3/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
    343             method = get_real_method(obj, self.print_method)
    344             if method is not None:
--> 345                 return method()
    346             return None
    347         else:

/anaconda3/lib/python3.7/site-packages/modin/pandas/dataframe.py in _repr_html_(self)
    112         # We use pandas _repr_html_ to get a string of the HTML representation
    113         # of the dataframe.
--> 114         result = self._build_repr_df(num_rows, num_cols)._repr_html_()
    115         if len(self.index) > num_rows or len(self.columns) > num_cols:
    116             # We split so that we insert our correct dataframe dimensions.

/anaconda3/lib/python3.7/site-packages/modin/pandas/base.py in _build_repr_df(self, num_rows, num_cols)
     69                 tail_front = pandas.DataFrame()
     70         else:
---> 71             head_front = head.front(num_cols_for_front).to_pandas()
     72             head_back = head.back(num_cols_for_front).to_pandas()
     73 

/anaconda3/lib/python3.7/site-packages/modin/backends/pandas/query_compiler.py in front(self, n)
   2225         else:
   2226             result = self.__constructor__(
-> 2227                 self.data.take(1, n), self.index, self.columns[:n], new_dtypes
   2228             )
   2229         return result

/anaconda3/lib/python3.7/site-packages/modin/engines/base/frame/partition_manager.py in take(self, axis, n)
    372             bin_lengths = self.block_lengths
    373         else:
--> 374             partitions = self.partitions.T
    375             bin_lengths = self.block_widths
    376         if n < 0:

/anaconda3/lib/python3.7/site-packages/modin/engines/base/frame/partition_manager.py in _get_partitions(self)
     72                             if self.block_lengths[i] != 0 and self.block_widths[j] != 0
     73                         ]
---> 74                         for i in range(len(self._partitions_cache))
     75                     ]
     76                     if len(row)

/anaconda3/lib/python3.7/site-packages/modin/engines/base/frame/partition_manager.py in <listcomp>(.0)
     72                             if self.block_lengths[i] != 0 and self.block_widths[j] != 0
     73                         ]
---> 74                         for i in range(len(self._partitions_cache))
     75                     ]
     76                     if len(row)

/anaconda3/lib/python3.7/site-packages/modin/engines/base/frame/partition_manager.py in <listcomp>(.0)
     70                             self._partitions_cache[i][j]
     71                             for j in range(len(self._partitions_cache[i]))
---> 72                             if self.block_lengths[i] != 0 and self.block_widths[j] != 0
     73                         ]
     74                         for i in range(len(self._partitions_cache))

/anaconda3/lib/python3.7/site-packages/modin/engines/ray/generic/frame/partition_manager.py in block_lengths(self)
     38                             [obj.length().oid for obj in self._partitions_cache.T[0]]
     39                         )
---> 40                         if len(self._partitions_cache.T) > 0
     41                         else []
     42                     )

/anaconda3/lib/python3.7/site-packages/ray/worker.py in get(object_ids)
   2187             if isinstance(value, RayError):
   2188                 last_task_error_raise_time = time.time()
-> 2189                 raise value
   2190 
   2191         # Run post processors.

RayWorkerError: The worker died unexpectedly while executing this task.

Hi @masoodimran, thanks for posting!

Was this in a script, and if so does it happen in an interpreter/notebook? If it was not, we should open an issue in Ray: https://github.com/ray-project/ray.
Hello @devin-petersohn,

This happens when I run the example in Jupyter Notebook. I have tried opening an excel as well in Jupyter notebook using modin and still get the same error.
Thanks @masoodimran, that is helpful. I have asked around and it seems one person has encountered this as well, but restarting the environment solved the problem. Does it happen for you every time you execute `df.head()`?

If so, we will open an issue in Ray, the core developers there will have a good idea of how to debug and solve this.
Hello @devin-petersohn, Yes it happens every time. Restarting the environment did not help here.
Thanks @masoodimran, I have created an issue on the Ray repo so let's continue conversation there.
@devin-petersohn 
Thanks for your attention! 
I just installed the Modin and this issue happened every time. I cannot use Modin at all.
@Jacobzhangjw does this happen after you run `pip install -U ray`?
@devin-petersohn 
Yes, the Ray Worker Issue also happened after running pip install -U ray.

By the way, it raised compatibility warning when installing the latest ray:

ERROR: modin 0.5.4 has requirement ray==0.7.1, but you'll have ray 0.7.3 which is incompatible.
Installing collected packages: ray
  Found existing installation: ray 0.7.1
    Uninstalling ray-0.7.1:
      Successfully uninstalled ray-0.7.1
Successfully installed ray-0.7.3

Additional info for your reference, I'm running all of these on windows10 WSL Ubuntu18:
Linux DESKTOP 4.4.0-17763-Microsoft #379-Microsoft Wed Mar 06 19:16:00 PST 2019 x86_64 x86_64 x86_64 GNU/Linux
The incompatibility warning is expected because of our pinned requirements, but it is surprising that it still happens.

cc @robertnishihara 

Resolving patch:
diff --git a/modin/pandas/__init__.py b/modin/pandas/__init__.py
--- a/modin/pandas/__init__.py
+++ b/modin/pandas/__init__.py
@@ -81,6 +81,7 @@
 import os
 import ray
 import types
+import sys
 
 from .. import __version__
 from .concat import concat
@@ -180,6 +181,35 @@ def initialize_ray():
         # We serialize `MethodType` objects when we use AxisPartition operations.
         ray.register_custom_serializer(types.MethodType, use_pickle=True)
 
+        # Register a fix import function to run on all_workers including the driver.
+        # This is a hack solution to fix #647, #746
+        def move_stdlib_ahead_of_site_packages(*args):
+            site_packages_path = None
+            site_packages_path_index = -1
+            for i, path in enumerate(sys.path):
+                if sys.exec_prefix in path and path.endswith("site-packages"):
+                    site_packages_path = path
+                    site_packages_path_index = i
+                    # break on first found
+                    break
+
+            if site_packages_path is not None:
+                # stdlib packages layout as follows:
+                # - python3.x
+                #   - typing.py
+                #   - site-packages/
+                #     - pandas
+                # So extracting the dirname of the site_packages can point us
+                # to the directory containing standard libraries.
+                sys.path.insert(
+                    site_packages_path_index, os.path.dirname(site_packages_path)
+                )
+
+        move_stdlib_ahead_of_site_packages()
+        ray.worker.global_worker.run_function_on_all_workers(
+            move_stdlib_ahead_of_site_packages
+        )
+
 
 if execution_engine == "Ray":
     initialize_ray()


Test patch: