Skip to content

Commit

Permalink
Get rid of duplicate code
Browse files Browse the repository at this point in the history
Signed-off-by: Iaroslav Igoshev <[email protected]>
  • Loading branch information
YarShev committed Mar 28, 2024
1 parent 905c3a3 commit 948ddb0
Showing 1 changed file with 15 additions and 38 deletions.
53 changes: 15 additions & 38 deletions modin/core/dataframe/pandas/dataframe/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3439,50 +3439,40 @@ def broadcast_apply_full_axis(
index=new_columns,
)
)

if not keep_partitioning:
if kw["row_lengths"] is None and ModinIndex.is_materialized_index(
new_index
is_index_materialized = ModinIndex.is_materialized_index(new_index)
is_columns_materialized = ModinIndex.is_materialized_index(new_columns)
if axis == 0:
if (
is_columns_materialized
and len(new_partitions.shape) > 1
and new_partitions.shape[1] == 1
):
kw["column_widths"] = [len(new_columns)]
elif axis == 1:
if is_index_materialized and new_partitions.shape[0] == 1:
kw["row_lengths"] = [len(new_columns)]
if not keep_partitioning:
if kw["row_lengths"] is None and is_index_materialized:
if axis == 0:
kw["row_lengths"] = get_length_list(
axis_len=len(new_index), num_splits=new_partitions.shape[0]
)
if (
kw["column_widths"] is None
and ModinIndex.is_materialized_index(new_columns)
and len(new_partitions.shape) > 1
and new_partitions.shape[1] == 1
):
kw["column_widths"] = [len(new_columns)]
elif axis == 1:
if self._row_lengths_cache is not None and len(new_index) == sum(
self._row_lengths_cache
):
kw["row_lengths"] = self._row_lengths_cache
elif new_partitions.shape[0] == 1:
kw["row_lengths"] = [len(new_index)]
if kw["column_widths"] is None and ModinIndex.is_materialized_index(
new_columns
):
if kw["column_widths"] is None and is_columns_materialized:
if axis == 1:
kw["column_widths"] = get_length_list(
axis_len=len(new_columns),
num_splits=new_partitions.shape[1],
)
if (
kw["row_lengths"] is None
and ModinIndex.is_materialized_index(new_index)
and new_partitions.shape[0] == 1
):
kw["row_lengths"] = [len(new_index)]
elif axis == 0:
if self._column_widths_cache is not None and len(
new_columns
) == sum(self._column_widths_cache):
kw["column_widths"] = self._column_widths_cache
elif new_partitions.shape[1] == 1:
kw["column_widths"] = [len(new_columns)]
else:
if axis == 0:
if (
Expand All @@ -3494,14 +3484,7 @@ def broadcast_apply_full_axis(
and all(r != 0 for r in self._row_lengths_cache)
):
kw["row_lengths"] = self._row_lengths_cache
if (
kw["column_widths"] is None
and ModinIndex.is_materialized_index(new_columns)
and len(new_partitions.shape) > 1
and new_partitions.shape[1] == 1
):
kw["column_widths"] = [len(new_columns)]
if axis == 1:
elif axis == 1:
if (
kw["column_widths"] is None
and self._column_widths_cache is not None
Expand All @@ -3511,12 +3494,6 @@ def broadcast_apply_full_axis(
and all(w != 0 for w in self._column_widths_cache)
):
kw["column_widths"] = self._column_widths_cache
if (
kw["row_lengths"] is None
and ModinIndex.is_materialized_index(new_index)
and new_partitions.shape[0] == 1
):
kw["row_lengths"] = [len(new_index)]

result = self.__constructor__(
new_partitions, index=new_index, columns=new_columns, **kw
Expand Down

0 comments on commit 948ddb0

Please sign in to comment.