Skip to content

Commit

Permalink
FIX-modin-project#3764: Fix KeyError from for out of range index
Browse files Browse the repository at this point in the history
  • Loading branch information
billiam-wang committed Sep 21, 2022
1 parent 0687bcd commit 1c68ba9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/release_notes/release_notes-0.16.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Key Features and Updates
* FIX-#3983: FIX-#4107: Materialize 'rowid' columns when selecting rows by position (#4834)
* FIX-#4845: Fix KeyError from `__getitem_bool` for single row dataframes (#4845)
* FIX-#4734: Handle Series.apply when return type is a DataFrame (#4830)
* FIX-#3764: Fix KeyError from `__setitem__` for out of range index (#3764)
* Performance enhancements
* PERF-#4182: Add cell-wise execution for binary ops, fix bin ops for empty dataframes (#4391)
* PERF-#4288: Improve perf of `groupby.mean` for narrow data (#4591)
Expand Down
3 changes: 1 addition & 2 deletions modin/pandas/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,9 +766,8 @@ def _loc(df):
return
row_loc, col_loc, _ = self._parse_row_and_column_locators(key)
if isinstance(row_loc, int) and row_loc not in self.qc.index:
# if row_loc not in self.qc.index:
index = self.qc.index.insert(len(self.qc.index), row_loc)
self.qc = self.qc.reindex(labels=index, axis=0)
self.qc = self.qc.reindex(labels=index, axis=0, fill_value=0)
self.df._update_inplace(new_query_compiler=self.qc)
if isinstance(col_loc, int) and col_loc not in self.qc.columns:
new_col = pandas.Series(index=self.df.index)
Expand Down
11 changes: 11 additions & 0 deletions modin/pandas/test/dataframe/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2117,3 +2117,14 @@ def test__getitem_bool_single_row_dataframe():
# This test case comes from
# https://github.com/modin-project/modin/issues/4845
eval_general(pd, pandas, lambda lib: lib.DataFrame([1])[lib.Series([True])])


def test_setitem_index_out_of_range():
# This test case comes from
# https://github.com/modin-project/modin/issues/3764
def set_new_row(lib):
df = lib.DataFrame([[1, 2], [3, 4]])
df.loc[2] = df.loc[1]
return df

eval_general(pd, pandas, set_new_row)

0 comments on commit 1c68ba9

Please sign in to comment.