Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REFACTOR-#6858: Rename _get_dimensions and change arguments #6859

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 11 additions & 10 deletions modin/core/dataframe/pandas/dataframe/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,28 +186,31 @@ 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, Axis.ROW_WISE)
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.

Parameters
----------
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 == Axis.ROW_WISE:
return [part.length() for part in parts]
else:
return [part.width() for part in parts]

def __len__(self) -> int:
"""
Expand Down Expand Up @@ -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, Axis.COL_WISE)
else:
self._column_widths_cache = []
return self._column_widths_cache
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion modin/core/execution/dask/common/engine_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion modin/core/execution/python/common/engine_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion modin/core/execution/ray/common/engine_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

"""Module houses class that implements ``PandasDataframe`` using Ray."""

from modin.core.dataframe.base.dataframe.utils import Axis
from modin.core.dataframe.pandas.dataframe.dataframe import PandasDataframe

from ..partitioning.partition_manager import PandasOnRayDataframePartitionManager
Expand Down Expand Up @@ -42,20 +43,24 @@ 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.

Parameters
----------
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 == Axis.ROW_WISE:
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)
2 changes: 1 addition & 1 deletion modin/core/execution/unidist/common/engine_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down