Skip to content

Commit

Permalink
FIX-modin-project#1620: Use pandas.reindex() properly
Browse files Browse the repository at this point in the history
Signed-off-by: Vasilij Litvinov <vasilij.n.litvinov@intel.com>
  • Loading branch information
vnlitvinov committed Dec 17, 2020
1 parent 103e4b5 commit 8562d09
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions modin/pandas/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,16 @@ def _broadcast_item(self, row_lookup, col_lookup, item, to_shape):
"an iterable"
)
if hasattr(item, "columns"):
if not all(idx in item.columns for idx in col_lookup):
own_cols = self.qc.columns
# convert indices in column lookup to column names, as Pandas reindex expects them so
lookup = [own_cols[idx] for idx in col_lookup]
if not all(col in item.columns for col in lookup):
# TODO: think if it is needed to handle cases when columns have duplicate names
raise ValueError(
"Must have equal len keys and value when setting "
"with an iterable"
)
item = item.reindex(index=row_lookup, columns=col_lookup)
item = item.reindex(index=row_lookup, columns=lookup)
else:
item = item.reindex(index=row_lookup)
try:
Expand Down

0 comments on commit 8562d09

Please sign in to comment.