Repository: modin-project/modin

Issue:
Move PandasDataframePartitionManager.concatenate to a utils
After the refactor and the clean abstractions, there are some leaks that weren't taken care of then. This one needs to be moved to a utils, it has nothing to do with partition management.

https://github.com/modin-project/modin/blob/67013f935861187c784415d4265a5b437dba5690/modin/core/dataframe/pandas/partitioning/partition_manager.py#L603-L627


Discussion:

Resolving patch:
diff --git a/modin/core/dataframe/pandas/partitioning/partition_manager.py b/modin/core/dataframe/pandas/partitioning/partition_manager.py
--- a/modin/core/dataframe/pandas/partitioning/partition_manager.py
+++ b/modin/core/dataframe/pandas/partitioning/partition_manager.py
@@ -25,9 +25,9 @@
 
 from modin.error_message import ErrorMessage
 from modin.core.storage_formats.pandas.utils import compute_chunksize
+from modin.core.dataframe.pandas.utils import concatenate
 from modin.config import NPartitions, ProgressBar, BenchmarkMode
 
-from pandas.api.types import union_categoricals
 import os
 
 
@@ -600,32 +600,6 @@ def concat(cls, axis, left_parts, right_parts):
         else:
             return np.append(left_parts, right_parts, axis=axis)
 
-    @classmethod
-    def concatenate(cls, dfs):
-        """
-        Concatenate pandas DataFrames with saving 'category' dtype.
-
-        Parameters
-        ----------
-        dfs : list
-            List of pandas DataFrames to concatenate.
-
-        Returns
-        -------
-        pandas.DataFrame
-            A pandas DataFrame
-        """
-        categoricals_columns = set.intersection(
-            *[set(df.select_dtypes("category").columns.tolist()) for df in dfs]
-        )
-
-        for col in categoricals_columns:
-            uc = union_categoricals([df[col] for df in dfs])
-            for df in dfs:
-                df[col] = pandas.Categorical(df[col], categories=uc.categories)
-
-        return pandas.concat(dfs)
-
     @classmethod
     def to_pandas(cls, partitions):
         """
@@ -662,7 +636,7 @@ def to_pandas(cls, partitions):
         if len(df_rows) == 0:
             return pandas.DataFrame()
         else:
-            return cls.concatenate(df_rows)
+            return concatenate(df_rows)
 
     @classmethod
     def to_numpy(cls, partitions, **kwargs):
diff --git a/modin/core/dataframe/pandas/utils.py b/modin/core/dataframe/pandas/utils.py
new file mode 100644
--- /dev/null
+++ b/modin/core/dataframe/pandas/utils.py
@@ -0,0 +1,44 @@
+# Licensed to Modin Development Team under one or more contributor license agreements.
+# See the NOTICE file distributed with this work for additional information regarding
+# copyright ownership.  The Modin Development Team licenses this file to you under the
+# Apache License, Version 2.0 (the "License"); you may not use this file except in
+# compliance with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software distributed under
+# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
+# ANY KIND, either express or implied. See the License for the specific language
+# governing permissions and limitations under the License.
+
+
+"""Collection of utility functions for the PandasDataFrame."""
+
+import pandas
+from pandas.api.types import union_categoricals
+
+
+def concatenate(dfs):
+    """
+    Concatenate pandas DataFrames with saving 'category' dtype.
+
+    Parameters
+    ----------
+    dfs : list
+        List of pandas DataFrames to concatenate.
+
+    Returns
+    -------
+    pandas.DataFrame
+        A pandas DataFrame.
+    """
+    categoricals_columns = set.intersection(
+        *[set(df.select_dtypes("category").columns.tolist()) for df in dfs]
+    )
+
+    for col in categoricals_columns:
+        uc = union_categoricals([df[col] for df in dfs])
+        for df in dfs:
+            df[col] = pandas.Categorical(df[col], categories=uc.categories)
+
+    return pandas.concat(dfs)


Test patch: