diff --git a/modin/core/dataframe/pandas/dataframe/dataframe.py b/modin/core/dataframe/pandas/dataframe/dataframe.py index e3b92afdf2c..dc86b9abd32 100644 --- a/modin/core/dataframe/pandas/dataframe/dataframe.py +++ b/modin/core/dataframe/pandas/dataframe/dataframe.py @@ -186,13 +186,13 @@ def row_lengths(self): if self._row_lengths_cache is None: if len(self._partitions.T) > 0: row_parts = self._partitions.T[0] - self._row_lengths_cache = self._get_dimensions(row_parts, "length") + self._row_lengths_cache = self._get_lengths(row_parts, 0) else: self._row_lengths_cache = [] return self._row_lengths_cache @classmethod - def _get_dimensions(cls, parts, dim_name): + def _get_lengths(cls, parts, axis): """ Get list of dimensions for all the provided parts. @@ -200,14 +200,17 @@ def _get_dimensions(cls, parts, dim_name): ---------- parts : list List of parttions. - dim_name : string - Dimension name could be "length" or "width". + axis : {0, 1} + The axis along which to get the lengths (0 - length across rows or, 1 - width across columns). Returns ------- list """ - return [getattr(part, dim_name)() for part in parts] + if axis == 0: + return [part.length() for part in parts] + else: + return [part.width() for part in parts] def __len__(self) -> int: """ @@ -236,7 +239,7 @@ def column_widths(self): if self._column_widths_cache is None: if len(self._partitions) > 0: col_parts = self._partitions[0] - self._column_widths_cache = self._get_dimensions(col_parts, "width") + self._column_widths_cache = self._get_lengths(col_parts, 1) else: self._column_widths_cache = [] return self._column_widths_cache @@ -3673,9 +3676,7 @@ def _compute_new_widths(): if all( part._length_cache is not None for part in new_partitions.T[0] ): - new_lengths = self._get_dimensions( - new_partitions.T[0], "length" - ) + new_lengths = self._get_lengths(new_partitions.T[0], axis) else: new_lengths = None else: @@ -3697,7 +3698,7 @@ def _compute_new_widths(): new_widths = [] if new_partitions.size > 0: if all(part._width_cache is not None for part in new_partitions[0]): - new_widths = self._get_dimensions(new_partitions[0], "width") + new_widths = self._get_lengths(new_partitions[0], axis) else: new_widths = None diff --git a/modin/core/dataframe/pandas/partitioning/partition_manager.py b/modin/core/dataframe/pandas/partitioning/partition_manager.py index 12a34187faf..3a1dd63e555 100644 --- a/modin/core/dataframe/pandas/partitioning/partition_manager.py +++ b/modin/core/dataframe/pandas/partitioning/partition_manager.py @@ -122,7 +122,7 @@ def materialize_futures(cls, input_list): filtered_list = [] filtered_idx = [] for idx, item in enumerate(input_list): - if cls._execution_wrapper.check_is_future(item): + if cls._execution_wrapper.is_future(item): filtered_idx.append(idx) filtered_list.append(item) filtered_list = cls._execution_wrapper.materialize(filtered_list) diff --git a/modin/core/execution/dask/common/engine_wrapper.py b/modin/core/execution/dask/common/engine_wrapper.py index fe21e1ea457..f35f7ae2714 100644 --- a/modin/core/execution/dask/common/engine_wrapper.py +++ b/modin/core/execution/dask/common/engine_wrapper.py @@ -92,7 +92,7 @@ def deploy( return remote_task_future @classmethod - def check_is_future(cls, item): + def is_future(cls, item): """ Check if the item is a Future. diff --git a/modin/core/execution/python/common/engine_wrapper.py b/modin/core/execution/python/common/engine_wrapper.py index 396793aa5db..fe7c49cd5fe 100644 --- a/modin/core/execution/python/common/engine_wrapper.py +++ b/modin/core/execution/python/common/engine_wrapper.py @@ -42,7 +42,7 @@ def deploy(cls, func, f_args=None, f_kwargs=None, num_returns=1): return func(*args, **kwargs) @classmethod - def check_is_future(cls, item): + def is_future(cls, item): """ Check if the item is a Future. diff --git a/modin/core/execution/ray/common/engine_wrapper.py b/modin/core/execution/ray/common/engine_wrapper.py index 3fc1f75a906..8e20033d20d 100644 --- a/modin/core/execution/ray/common/engine_wrapper.py +++ b/modin/core/execution/ray/common/engine_wrapper.py @@ -76,7 +76,7 @@ def deploy(cls, func, f_args=None, f_kwargs=None, num_returns=1): ) @classmethod - def check_is_future(cls, item): + def is_future(cls, item): """ Check if the item is a Future. diff --git a/modin/core/execution/ray/implementations/pandas_on_ray/dataframe/dataframe.py b/modin/core/execution/ray/implementations/pandas_on_ray/dataframe/dataframe.py index 73b216c62c4..8351b71425d 100644 --- a/modin/core/execution/ray/implementations/pandas_on_ray/dataframe/dataframe.py +++ b/modin/core/execution/ray/implementations/pandas_on_ray/dataframe/dataframe.py @@ -42,7 +42,7 @@ class PandasOnRayDataframe(PandasDataframe): _partition_mgr_cls = PandasOnRayDataframePartitionManager - def _get_dimensions(self, parts, dim_name): + def _get_lengths(self, parts, axis): """ Get list of dimensions for all the provided parts. @@ -50,12 +50,16 @@ def _get_dimensions(self, parts, dim_name): ---------- parts : list List of parttions. - dim_name : string - Dimension name could be "length" or "width". + axis : {0, 1} + The axis along which to get the lengths (0 - length across rows or, 1 - width across columns). Returns ------- list """ - dims = [getattr(part, dim_name)(False) for part in parts] + if axis == 0: + dims = [part.length(False) for part in parts] + else: + dims = [part.width(False) for part in parts] + return self._partition_mgr_cls.materialize_futures(dims) diff --git a/modin/core/execution/unidist/common/engine_wrapper.py b/modin/core/execution/unidist/common/engine_wrapper.py index f28115f133f..08937cf30a6 100644 --- a/modin/core/execution/unidist/common/engine_wrapper.py +++ b/modin/core/execution/unidist/common/engine_wrapper.py @@ -75,7 +75,7 @@ def deploy(cls, func, f_args=None, f_kwargs=None, num_returns=1): ) @classmethod - def check_is_future(cls, item): + def is_future(cls, item): """ Check if the item is a Future.