Skip to content

Commit

Permalink
FIX-modin-project#1620: Convert lookups to values for both indices an…
Browse files Browse the repository at this point in the history
…d columns

Signed-off-by: Vasilij Litvinov <vasilij.n.litvinov@intel.com>
  • Loading branch information
vnlitvinov committed Dec 16, 2020
1 parent d325271 commit af1f16a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions modin/pandas/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,24 +385,24 @@ def _broadcast_item(self, row_lookup, col_lookup, item, to_shape):
# It is valid to pass a DataFrame or Series to __setitem__ that is larger than
# the target the user is trying to overwrite. This
if isinstance(item, (pandas.Series, pandas.DataFrame, DataFrame)):
if not all(idx in item.index for idx in row_lookup):
# convert indices in lookups to names, as Pandas reindex expects them to be so
index_values = self.qc.index[row_lookup]
if not all(idx in item.index for idx in index_values):
raise ValueError(
"Must have equal len keys and value when setting with "
"an iterable"
)
if hasattr(item, "columns"):
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):
column_values = self.qc.columns[col_lookup]
if not all(col in item.columns for col in column_values):
# 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=lookup)
item = item.reindex(index=index_values, columns=column_values)
else:
item = item.reindex(index=row_lookup)
item = item.reindex(index=index_values)
try:
item = np.array(item)
if np.prod(to_shape) == np.prod(item.shape):
Expand Down

0 comments on commit af1f16a

Please sign in to comment.