Repository: modin-project/modin

Issue:
CLN: remove code duplication for `progress_bar_wrapper`



Discussion:

Resolving patch:
diff --git a/modin/core/execution/modin_aqp.py b/modin/core/execution/modin_aqp.py
--- a/modin/core/execution/modin_aqp.py
+++ b/modin/core/execution/modin_aqp.py
@@ -19,10 +19,11 @@
 
 import os
 import time
+import inspect
 import threading
 import warnings
 
-from modin.config import Engine
+from modin.config import Engine, ProgressBar
 
 
 progress_bars = {}
@@ -134,3 +135,56 @@ def _show_time_updates(p_bar):
         time.sleep(1)
         if p_bar.total > p_bar.n:
             p_bar.refresh()
+
+
+def progress_bar_wrapper(f):
+    """
+    Wrap computation function inside a progress bar.
+
+    Spawns another thread which displays a progress bar showing
+    estimated completion time.
+
+    Parameters
+    ----------
+    f : callable
+        The name of the function to be wrapped.
+
+    Returns
+    -------
+    callable
+        Decorated version of `f` which reports progress.
+    """
+    from functools import wraps
+
+    @wraps(f)
+    def magic(*args, **kwargs):
+        result_parts = f(*args, **kwargs)
+        if ProgressBar.get():
+            current_frame = inspect.currentframe()
+            function_name = None
+            while function_name != "<module>":
+                (
+                    filename,
+                    line_number,
+                    function_name,
+                    lines,
+                    index,
+                ) = inspect.getframeinfo(current_frame)
+                current_frame = current_frame.f_back
+            t = threading.Thread(
+                target=call_progress_bar,
+                args=(result_parts, line_number),
+            )
+            t.start()
+            # We need to know whether or not we are in a jupyter notebook
+            from IPython import get_ipython
+
+            try:
+                ipy_str = str(type(get_ipython()))
+                if "zmqshell" not in ipy_str:
+                    t.join()
+            except Exception:
+                pass
+        return result_parts
+
+    return magic
diff --git a/modin/core/execution/ray/implementations/pandas_on_ray/partitioning/partition_manager.py b/modin/core/execution/ray/implementations/pandas_on_ray/partitioning/partition_manager.py
--- a/modin/core/execution/ray/implementations/pandas_on_ray/partitioning/partition_manager.py
+++ b/modin/core/execution/ray/implementations/pandas_on_ray/partitioning/partition_manager.py
@@ -13,10 +13,6 @@
 
 """Module houses class that implements ``GenericRayDataframePartitionManager`` using Ray."""
 
-import inspect
-import threading
-
-from modin.config import ProgressBar
 from modin.core.execution.ray.generic.partitioning import (
     GenericRayDataframePartitionManager,
 )
@@ -27,60 +23,7 @@
     PandasOnRayDataframeRowPartition,
 )
 from .partition import PandasOnRayDataframePartition
-from modin.core.execution.modin_aqp import call_progress_bar
-
-
-def progress_bar_wrapper(f):
-    """
-    Wrap computation function inside a progress bar.
-
-    Spawns another thread which displays a progress bar showing
-    estimated completion time.
-
-    Parameters
-    ----------
-    f : callable
-        The name of the function to be wrapped.
-
-    Returns
-    -------
-    callable
-        Decorated version of `f` which reports progress.
-    """
-    from functools import wraps
-
-    @wraps(f)
-    def magic(*args, **kwargs):
-        result_parts = f(*args, **kwargs)
-        if ProgressBar.get():
-            current_frame = inspect.currentframe()
-            function_name = None
-            while function_name != "<module>":
-                (
-                    filename,
-                    line_number,
-                    function_name,
-                    lines,
-                    index,
-                ) = inspect.getframeinfo(current_frame)
-                current_frame = current_frame.f_back
-            t = threading.Thread(
-                target=call_progress_bar,
-                args=(result_parts, line_number),
-            )
-            t.start()
-            # We need to know whether or not we are in a jupyter notebook
-            from IPython import get_ipython
-
-            try:
-                ipy_str = str(type(get_ipython()))
-                if "zmqshell" not in ipy_str:
-                    t.join()
-            except Exception:
-                pass
-        return result_parts
-
-    return magic
+from modin.core.execution.modin_aqp import progress_bar_wrapper
 
 
 class PandasOnRayDataframePartitionManager(GenericRayDataframePartitionManager):
diff --git a/modin/core/execution/unidist/implementations/pandas_on_unidist/partitioning/partition_manager.py b/modin/core/execution/unidist/implementations/pandas_on_unidist/partitioning/partition_manager.py
--- a/modin/core/execution/unidist/implementations/pandas_on_unidist/partitioning/partition_manager.py
+++ b/modin/core/execution/unidist/implementations/pandas_on_unidist/partitioning/partition_manager.py
@@ -13,10 +13,6 @@
 
 """Module houses class that implements ``GenericUnidistDataframePartitionManager`` using Unidist."""
 
-import inspect
-import threading
-
-from modin.config import ProgressBar
 from modin.core.execution.unidist.generic.partitioning import (
     GenericUnidistDataframePartitionManager,
 )
@@ -27,60 +23,7 @@
     PandasOnUnidistDataframeRowPartition,
 )
 from .partition import PandasOnUnidistDataframePartition
-from modin.core.execution.modin_aqp import call_progress_bar
-
-
-def progress_bar_wrapper(f):
-    """
-    Wrap computation function inside a progress bar.
-
-    Spawns another thread which displays a progress bar showing
-    estimated completion time.
-
-    Parameters
-    ----------
-    f : callable
-        The name of the function to be wrapped.
-
-    Returns
-    -------
-    callable
-        Decorated version of `f` which reports progress.
-    """
-    from functools import wraps
-
-    @wraps(f)
-    def magic(*args, **kwargs):
-        result_parts = f(*args, **kwargs)
-        if ProgressBar.get():
-            current_frame = inspect.currentframe()
-            function_name = None
-            while function_name != "<module>":
-                (
-                    filename,
-                    line_number,
-                    function_name,
-                    lines,
-                    index,
-                ) = inspect.getframeinfo(current_frame)
-                current_frame = current_frame.f_back
-            t = threading.Thread(
-                target=call_progress_bar,
-                args=(result_parts, line_number),
-            )
-            t.start()
-            # We need to know whether or not we are in a jupyter notebook
-            from IPython import get_ipython
-
-            try:
-                ipy_str = str(type(get_ipython()))
-                if "zmqshell" not in ipy_str:
-                    t.join()
-            except Exception:
-                pass
-        return result_parts
-
-    return magic
+from modin.core.execution.modin_aqp import progress_bar_wrapper
 
 
 class PandasOnUnidistDataframePartitionManager(GenericUnidistDataframePartitionManager):


Test patch: